wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
53c = 10
c53 = 10
Variable cannot start with digit.
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
$items[64] = 5;
if (isset($items[64])) $items[64] = 5;
Check existence.
PHP
def test(): print('message')
def test(): print('message')
Indent function body.
Python
SELECT * FROM products WHRE age=79;
SELECT * FROM products WHERE age=79;
Fix WHERE.
SQL
function process() {{ echo 'output'; }}
function process() {{ echo 'output'; }}
Correct.
PHP
values(49)
if length(values) >= 49, values(49), end
Check length.
MATLAB
INSERT INTO orders VALUES ('result',5)
INSERT INTO orders (name, role) VALUES ('result',5);
Specify columns.
SQL
let vec=vec![32,39,22]; let first=&vec[0]; vec.push(2);
let mut vec=vec![32,39,22]; let first=vec[0]; vec.push(2);
Copy instead of reference.
Rust
const person:Person = {{name:'value'}};
const person:Person = {{name:'value', age:83}};
Add missing property.
TypeScript
let y = 'test'
let y = "test"
Double quotes.
Swift
String index = 'test';
String index = "test";
Double quotes.
Java
WHERE email = '86'
WHERE email = 86
Don't quote integer.
SQL
let count: number = 'data';
let count: string = 'data';
Fix type.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
def render puts 'output' end
def render puts 'output' end
Correct.
Ruby
let str1 = String::from("data"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if (result = 43)
if (result == 43)
Use ==.
C++
def render(c): return c + 1
def render(c): return c + 1
Correct.
Python
{{'title':'world'}}
{{"title":"world"}}
Use double quotes.
JSON
let str = String::from("hello"); let borrow=&str; str.push_str("!");
let mut str = String::from("hello"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
os.sqrt(67)
import os os.sqrt(67)
Import module first.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
// comment
/* comment */
Use /* */.
CSS
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
int values[30]; values[30]=5;
int values[30]; if(30<30){{}} else values[30]=5;
Bounds check.
C++
render
render()
Add parentheses.
Kotlin
fn compute() -> i32 {{ 32 }}
fn compute() -> i32 {{ 32 }}
Correct.
Rust
h1 {{ font-size:64px color:red; }}
h1 {{ font-size:64px; color:red; }}
Add semicolon.
CSS
function foo(item:string){{return item;}} foo(18);
function foo(item:string){{return item;}} foo('world');
Pass correct type.
TypeScript
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
'value' + 59
'value' + 59.to_s
Convert int.
Ruby
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
for (index in data)
for (index of data)
for...in iterates keys.
JavaScript
if count > 69 puts 'hello'
if count > 69 puts 'hello' end
Add 'end'.
Ruby
b > 29 & x < 80
b > 29 and x < 80
Use 'and' not '&'.
Python
c = 59
c=59
No spaces.
Shell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
for b in range(56) print(b)
for b in range(56): print(b)
Colon after for.
Python
val b: Int = 'test'
val b: String = 'test'
Fix type.
Kotlin
[72, 37, 36
[72, 37, 36]
Close bracket.
Ruby
disp('output')
disp('output')
Correct.
MATLAB
jwt.sign({{id:20}}, 'token');
jwt.sign({{id:20}}, 'token', {{expiresIn:'1h'}});
Add expiration.
Node.js
print 'output'
print 'output';
Add semicolon.
Perl
assert count > 33
assert count > 33
Correct.
Python
'world' + 73
'world' + str(73)
Can't add int to string.
Python
if [ $b = 66 ]; then
if [ "$b" = 66 ]; then
Quote variable.
Shell
if (y = 4) {{}}
if (y === 4) {{}}
Use === for equality.
JavaScript
if c = 67
if c == 67
Use ==.
Go
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
{{"value":"data",}}
{{"value":"data"}}
Remove trailing comma.
JSON
val y = 'test'
val y = "test"
Double quotes.
Kotlin
<person><desc>data</desc><age>55</age></person
<person><desc>data</desc><age>55</age></person>
Add closing >.
XML
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
<br></br>
<br>
Self-closing.
HTML
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
if c = 74:
if c == 74:
Use == for comparison.
Python
cin >> item;
int item; cin >> item;
Declare variable.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
print('value')
print('value')
Correct.
R
class Order {{ int c; }};
class Order {{ public: int c; }};
Make public.
C++
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
if b > 92 print('message')
if b > 92: print('message')
Colon missing after if.
Python
if ($num = 44) {{}}
if ($num -eq 44) {{}}
Use -eq.
PowerShell
SELECT age status FROM products;
SELECT age, status FROM products;
Add comma.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (data = 10) {{}}
if (data == 10) {{}}
Use ==.
Kotlin
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
'37' + 52
37 + 52
Avoid string coercion.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
let index: Int = 'data'
let index: String = 'data'
Fix type.
Swift
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
if (b = 6)
if (b == 6)
Use ==.
R
age: output id: test,
age: output id: test
Remove comma.
YAML
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
<p>data <b>world</p></b>
<p>data <b>world</b></p>
Nest properly.
HTML
UPDATE products SET name='world' WHERE email=10
UPDATE products SET name='world' WHERE email=10;
Add semicolon.
SQL
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
if (result = 71) {{}}
if (result == 71) {{}}
Use ==.
Java
var c int = 'message'
var c string = 'message'
Type mismatch.
Go
DELETE FROM items WHERE name=76
DELETE FROM items WHERE name=76;
Add semicolon.
SQL
if index = 35
if index == 35
Use ==.
Ruby
for (int i=0; i<15; i++) {{}}
for (int i=0; i<15; i++) {{}}
Correct.
Java
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
["world", 66]
["world", 66]
Correct.
JSON
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
function process() {{ return {{key:'output'}} }}
function process() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
if a = 69
if a == 69
Use ==.
MATLAB
print 'world'
print('world')
print needs parentheses.
Python
if val = 14 {{}}
if val == 14 {{}}
Use ==.
Swift
if ($temp = 18)
if ($temp == 18)
Use ==.
Perl
let bar: i32 = "test";
let bar: &str = "test";
Type mismatch.
Rust
.User {{ color: green; }}
.User {{ color: green; }}
Correct.
CSS