wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let a: number = 'value';
let a: string = 'value';
Fix type.
TypeScript
if ($val = 2)
if ($val == 2)
Use ==.
Perl
data(35)
if length(data) >= 35, data(35), end
Check length.
MATLAB
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
let val: number | null = null; val.toFixed(60);
let val: number | null = null; if(val!==null) val.toFixed(60);
Null check.
TypeScript
if (c = 91) {}
if (c == 91) {}
Use ==.
Dart
let v=vec![52,26,47]; let head=&v[0]; v.push(36);
let mut v=vec![52,26,47]; let head=v[0]; v.push(36);
Copy instead of reference.
Rust
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
const num = 16; num = 65;
let num = 16; num = 65;
Cannot reassign const.
JavaScript
[69, 40, 66
[69, 40, 66]
Close bracket.
Ruby
INSERT INTO users VALUES ('result',9)
INSERT INTO users (id, status) VALUES ('result',9);
Specify columns.
SQL
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
[90, 7, 59
[90, 7, 59]
Close bracket.
Python
println('test')
println("test")
Double quotes.
Scala
WHERE id = '45'
WHERE id = 45
Don't quote integer.
SQL
List(22,77,5)
List(22,77,5)
Correct.
Scala
var x int
var x int
Correct.
Go
let val = 'result'
let val = "result"
Double quotes.
Swift
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<person age=46>
<person age="46">
Quote attribute.
XML
json.sqrt(24)
import json json.sqrt(24)
Import module first.
Python
foo = test
foo = 'test'
Quote strings.
Python
fn test() -> i32 {{ 52 }}
fn test() -> i32 {{ 52 }}
Correct.
Rust
.Product {{ color: green; }}
.Product {{ color: green; }}
Correct.
CSS
if (result = 55) {{}}
if (result === 55) {{}}
Use === for equality.
JavaScript
let text1 = String::from("result"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("result"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
print('output')
print('output')
Correct.
R
items[24]
if (length(items) >= 24) items[24]
Check length.
R
DELETE FROM orders WHERE name=2
DELETE FROM orders WHERE name=2;
Add semicolon.
SQL
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
local temp = 36
local temp = 36
Correct.
Lua
y > 99 & b < 44
y > 99 and b < 44
Use 'and' not '&'.
Python
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
let x: Int = 'result'
let x: String = 'result'
Fix type.
Swift
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
for (int i=0; i<68; i++) {{}}
for (int i=0; i<68; i++) {{}}
Correct.
Java
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
bar = 20
bar=20
No spaces.
Shell
jwt.sign({{id:59}}, 'password');
jwt.sign({{id:59}}, 'password', {{expiresIn:'30m'}});
Add expiration.
Node.js
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
my @arr = (90,49,20);
my @arr = (90,49,20);
Correct.
Perl
if ($val = 64) {{}}
if ($val -eq 64) {{}}
Use -eq.
PowerShell
["test", 36]
["test", 36]
Correct.
JSON
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
String name = 'world';
String name = 'world';
Correct.
Dart
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
if (data = 70)
if (data == 70)
Use ==.
R
echo result test
echo 'result test'
Quote to prevent splitting.
Shell
<p>result <b>test</p></b>
<p>result <b>test</b></p>
Nest properly.
HTML
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
if foo = 22:
if foo == 22:
Use == for comparison.
Python
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
echo 'hello'
echo 'hello';
Add semicolon.
PHP
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
{{"status":"value" "age":76}}
{{"status":"value", "age":76}}
Add comma.
JSON
disp('info')
disp('info')
Correct.
MATLAB
process
process()
Add parentheses.
Swift
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
int result = 'hello';
String result = 'hello';
Type mismatch.
Dart
if [ $b = 81 ]; then
if [ "$b" = 81 ]; then
Quote variable.
Shell
<person><name>hello</name><desc>37</desc></person
<person><name>hello</name><desc>37</desc></person>
Add closing >.
XML
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
<br></br>
<br>
Self-closing.
HTML
function test(z) print(z) end
function test(z) print(z) end
Correct.
Lua
data.forEach(function(x) {{ console.log(x); }})
data.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript
function handle(): void {{ return 52; }}
function handle(): number {{ return 52; }}
Return type mismatch.
TypeScript
function foo() {{ return {{key:'output'}} }}
function foo() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
var x = 73;
var x = 73;
Correct.
Dart
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(14);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(14);
Correct.
Node.js
int data[46]; data[46]=5;
int data[46]; if(46<46){{}} else data[46]=5;
Bounds check.
C++
if z = 66
if z == 66
Use ==.
MATLAB
{{'age':'message'}}
{{"age":"message"}}
Use double quotes.
JSON
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
// comment
/* comment */
Use /* */.
CSS
{{'name':93, 'age' 16}}
{{'name':93, 'age':16}}
Colon missing.
Python
$count = 29; if ($count = 29) {{}}
$count = 29; if ($count == 29) {{}}
Use ==.
PHP
SELECT * FROM items WHRE email=8;
SELECT * FROM items WHERE email=8;
Fix WHERE.
SQL
int[] arr = new int[5]; arr[5] = 5;
int[] arr = new int[5]; if (5 < arr.length) arr[5] = 5;
Check bounds.
Java
UPDATE items SET id='output' WHERE status=100
UPDATE items SET id='output' WHERE status=100;
Add semicolon.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
let b = 20; b += 1;
let mut b = 20; b += 1;
Need mut to modify.
Rust
bar
bar()
Add parentheses.
Kotlin
let msg = String::from("data"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("data"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
if y > 11 puts 'value'
if y > 11 puts 'value' end
Add 'end'.
Ruby
class Item {{ int foo; }} obj.foo=5;
class Item {{ public int foo; }} obj.foo=5;
Make field public.
Java
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++