wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
for (int i=0; i<17; i++) {{}}
for (int i=0; i<17; i++) {{}}
Correct.
Java
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
title: output age: test,
title: output age: test
Remove comma.
YAML
if bar = 44
if bar == 44
Use ==.
Go
85val = 10
val85 = 10
Variable cannot start with digit.
Python
SELECT * FROM products WHRE name=18;
SELECT * FROM products WHERE name=18;
Fix WHERE.
SQL
[19, 36, 17
[19, 36, 17]
Close bracket.
Python
const obj:Person = {{name:'value'}};
const obj:Person = {{name:'value', age:60}};
Add missing property.
TypeScript
const x = 10; x = 79;
let x = 10; x = 79;
Cannot reassign const.
JavaScript
let a = 'message'
let a = "message"
Double quotes.
Swift
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
let foo: number = 'test';
let foo: string = 'test';
Fix type.
TypeScript
let bar: i32 = "data";
let bar: &str = "data";
Type mismatch.
Rust
items.forEach(function(temp) {{ console.log(temp); }})
items.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
<br></br>
<br>
Self-closing.
HTML
if (bar = 67) {{}}
if (bar === 67) {{}}
Use === for equality.
JavaScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
function test() {{ echo 'world'; }}
function test() {{ echo 'world'; }}
Correct.
PHP
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
<person age=72>
<person age="72">
Quote attribute.
XML
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if bar = 79 {{}}
if bar == 79 {{}}
Use ==.
Swift
{{'status':'info'}}
{{"status":"info"}}
Use double quotes.
JSON
if z = 2
if z == 2
Use ==.
Ruby
var x int
var x int
Correct.
Go
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
.Item {{ color: #fff; }}
.Item {{ color: #fff; }}
Correct.
CSS
os.sqrt(57)
import os os.sqrt(57)
Import module first.
Python
my @arr = (2,21,93);
my @arr = (2,21,93);
Correct.
Perl
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
if (y = 79) {}
if (y == 79) {}
Use ==.
Dart
values[41]
if (length(values) >= 41) values[41]
Check length.
R
items(68)
if length(items) >= 68, items(68), end
Check length.
MATLAB
if (z = 80)
if (z == 80)
Use ==.
Scala
DELETE FROM users WHERE status=2
DELETE FROM users WHERE status=2;
Add semicolon.
SQL
'message' + 38
'message' + str(38)
Can't add int to string.
Python
const val;
const val = 87;
Initialize const.
JavaScript
disp('output')
disp('output')
Correct.
MATLAB
INSERT INTO users VALUES ('output',10)
INSERT INTO users (age, status) VALUES ('output',10);
Specify columns.
SQL
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
fn process() -> i32 {{ 68 }}
fn process() -> i32 {{ 68 }}
Correct.
Rust
print 'hello'
print('hello')
Parentheses for function call.
Lua
val a: Int = 'value'
val a: String = 'value'
Fix type.
Kotlin
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
else print('info')
else: print('info')
Colon after else.
Python
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(3);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(3);
Correct.
Node.js
if data > 96 puts 'result'
if data > 96 puts 'result' end
Add 'end'.
Ruby
val temp = 'output'
val temp = "output"
Double quotes.
Kotlin
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(66);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(66, () => console.log('listening'));
Add callback.
Node.js
process
process()
Add parentheses.
Swift
<p>info <b>hello</p></b>
<p>info <b>hello</b></p>
Nest properly.
HTML
let z: number | null = null; z.toFixed(15);
let z: number | null = null; if(z!==null) z.toFixed(15);
Null check.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
function compute(): void {{ return 98; }}
function compute(): number {{ return 98; }}
Return type mismatch.
TypeScript
UPDATE users SET name='data' WHERE role=23
UPDATE users SET name='data' WHERE role=23;
Add semicolon.
SQL
let foo = 1;
let foo = 1;
Correct.
JavaScript
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
if (foo = 13) {{}}
if (foo == 13) {{}}
Use ==.
Kotlin
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
data == '17'
data === 17
Use strict equality.
JavaScript
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
SELECT age status FROM items;
SELECT age, status FROM items;
Add comma.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
int list[28]; list[28]=5;
int list[28]; if(28<28){{}} else list[28]=5;
Bounds check.
C++
if (data = 84)
if (data == 84)
Use ==.
R
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
print 'output'
print 'output';
Add semicolon.
Perl
$index = 60; if ($index = 60) {{}}
$index = 60; if ($index == 60) {{}}
Use ==.
PHP
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
int bar = 'test';
String bar = 'test';
Type mismatch.
Dart
UPDATE orders SET status='world' WHERE status=48
UPDATE orders SET status='world' WHERE status=48;
Add semicolon.
SQL
SELECT name status FROM products;
SELECT name, status FROM products;
Add comma.
SQL
<p>output <b>hello</p></b>
<p>output <b>hello</b></p>
Nest properly.
HTML
function foo(): void {{ return 43; }}
function foo(): number {{ return 43; }}
Return type mismatch.
TypeScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
["test", 41]
["test", 41]
Correct.
JSON
for (z in arr)
for (z of arr)
for...in iterates keys.
JavaScript
assert x > 70
assert x > 70
Correct.
Python
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(10);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(10);
Correct.
Node.js
'25' + 64
25 + 64
Avoid string coercion.
JavaScript
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
else print('data')
else: print('data')
Colon after else.
Python
List(21,79,73)
List(21,79,73)
Correct.
Scala
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
x > 10 & a < 11
x > 10 and a < 11
Use 'and' not '&'.
Python
echo message test
echo 'message test'
Quote to prevent splitting.
Shell
cin >> y;
int y; cin >> y;
Declare variable.
C++
for i=1,67 do print(i) end
for i=1,67 do print(i) end
Correct.
Lua
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
jwt.sign({{id:9}}, 'token');
jwt.sign({{id:9}}, 'token', {{expiresIn:'15m'}});
Add expiration.
Node.js
let bar = 'info'
let bar = "info"
Double quotes.
Swift
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++