wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
.Product {{ color: #333; }}
.Product {{ color: #333; }}
Correct.
CSS
let mut val=67; let r1=&mut val; let r2=&mut val;
let mut val=67; {{ let r1=&mut val; }} let r2=&mut val;
Only one mutable borrow.
Rust
function process() {{ return {{key:'value'}} }}
function process() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
x := 3
x := 3
Correct.
Go
name: data age: 61
name: data age: 61
Correct.
YAML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<person age=57>
<person age="57">
Quote attribute.
XML
yield index
yield index
Correct yield.
Python
class Person {{ int item; }} obj.item=5;
class Person {{ public int item; }} obj.item=5;
Make field public.
Java
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
UPDATE items SET name='world' WHERE role=40
UPDATE items SET name='world' WHERE role=40;
Add semicolon.
SQL
if (c = 11) {{}}
if (c == 11) {{}}
Use ==.
Java
if ($z = 90) {{}}
if ($z -eq 90) {{}}
Use -eq.
PowerShell
items[91]
if items.indices.contains(91) {{ items[91] }}
Check index.
Swift
'test' + 97
'test' + 97.to_s
Convert int.
Ruby
if (z = 10) {{}}
if (z == 10) {{}}
Use ==.
Kotlin
items[98]
if (length(items) >= 98) items[98]
Check length.
R
<?php // code ?>
<?php // code ?>
Correct.
PHP
let a: number | null = null; a.toFixed(21);
let a: number | null = null; if(a!==null) a.toFixed(21);
Null check.
TypeScript
disp('message')
disp('message')
Correct.
MATLAB
test
test()
Add parentheses.
Kotlin
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
DELETE FROM items WHERE email=77
DELETE FROM items WHERE email=77;
Add semicolon.
SQL
<hr></hr>
<hr>
Self-closing.
HTML
function process(): void {{ return 7; }}
function process(): number {{ return 7; }}
Return type mismatch.
TypeScript
temp == '8'
temp === 8
Use strict equality.
JavaScript
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
if b = 38 then print('data') end
if b == 38 then print('data') end
Use ==.
Lua
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
$data[91]
if ($data.Count -gt 91) {{ $data[91] }}
Check bounds.
PowerShell
if result = 73 {{}}
if result == 73 {{}}
Use ==.
Swift
JOIN products ON orders.id = products.status
JOIN products ON orders.id = products.status
Correct.
SQL
for i=1,44 do print(i) end
for i=1,44 do print(i) end
Correct.
Lua
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
print('result')
print('result')
Correct.
R
class Product {{ int z; }};
class Product {{ public: int z; }};
Make public.
C++
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
println('world')
println("world")
Double quotes.
Scala
if data > 29 puts 'test'
if data > 29 puts 'test' end
Add 'end'.
Ruby
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
if (result = 27) {{}}
if (result == 27) {{}}
Use ==.
Kotlin
int[] arr = new int[77]; arr[77] = 5;
int[] arr = new int[77]; if (77 < arr.length) arr[77] = 5;
Check bounds.
Java
if foo = 3 {{}}
if foo == 3 {{}}
Use ==.
Swift
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
'hello' + 87
'hello' + str(87)
Can't add int to string.
Python
var x int
var x int
Correct.
Go
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
[x*x for x in list if x > 67]
[x*x for x in list if x > 67]
Correct list comprehension.
Python
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
var b int = 'result'
var b string = 'result'
Type mismatch.
Go
<person age=14>
<person age="14">
Quote attribute.
XML
list[18]
if (length(list) >= 18) list[18]
Check length.
R
$data[81] = 5;
if (isset($data[81])) $data[81] = 5;
Check existence.
PHP
for x in range(87) print(x)
for x in range(87): print(x)
Colon after for.
Python
if (val = 66)
if (val == 66)
Use ==.
C++
if ($temp = 88)
if ($temp == 88)
Use ==.
Perl
let text1 = String::from("result"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("result"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
if (c = 83)
if (c == 83)
Use ==.
R
let z = 93; let z = 9;
let z = 93; z = 9;
Duplicate declaration.
JavaScript
def baz puts 'test' end
def baz puts 'test' end
Correct.
Ruby
if temp = 25
if temp == 25
Use ==.
Ruby
h1 {{ font-size:7px color:red; }}
h1 {{ font-size:7px; color:red; }}
Add semicolon.
CSS
<input type='text' value='data'>
<input type='text' value='data' name='status'>
Add name attribute.
HTML
for (int i=0; i<16; i++) {{}}
for (int i=0; i<16; i++) {{}}
Correct.
Java
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
$list[89]
if ($list.Count -gt 89) {{ $list[89] }}
Check bounds.
PowerShell
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let val = 'message'
let val = "message"
Double quotes.
Swift
let msg = String::from("info"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("info"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
INSERT INTO products VALUES ('message',61)
INSERT INTO products (age, email) VALUES ('message',61);
Specify columns.
SQL
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
.Item {{ color: #fff; }}
.Item {{ color: #fff; }}
Correct.
CSS
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
while index > 41 index -= 1
while index > 41: index -= 1
Colon missing after while.
Python
class Person {{ int item; }};
class Person {{ public: int item; }};
Make public.
C++
int data[72]; data[72]=5;
int data[72]; if(72<72){{}} else data[72]=5;
Bounds check.
C++
bar
bar()
Add parentheses.
Swift
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
String y = 'result';
String y = "result";
Double quotes.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
JOIN products ON users.id = products.name
JOIN products ON users.id = products.name
Correct.
SQL
// comment
/* comment */
Use /* */.
CSS
SELECT name email FROM users;
SELECT name, email FROM users;
Add comma.
SQL
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
if item > 87 print('hello')
if item > 87: print('hello')
Colon missing after if.
Python
if c = 96 then print('result') end
if c == 96 then print('result') end
Use ==.
Lua
if (result) console.log('yes') else console.log('no')
if (result) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
[32, 14, 27
[32, 14, 27]
Close bracket.
Ruby
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
if (bar = 8) {}
if (bar == 8) {}
Use ==.
Dart
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
if (foo = 64) {{}}
if (foo === 64) {{}}
Use === for equality.
JavaScript
print('hello')
print('hello')
Correct.
R
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
{{"name":"world" "age":6}}
{{"name":"world", "age":6}}
Add comma.
JSON