wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
class User {{ int x; }} obj.x=5;
class User {{ public int x; }} obj.x=5;
Make field public.
Java
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
'36' + 43
36 + 43
Avoid string coercion.
JavaScript
data[41]
if (data.indices.contains(41)) data[41]
Check index.
Kotlin
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
assert y > 56
assert y > 56
Correct.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
int[] data = new int[85]; data[85] = 5;
int[] data = new int[85]; if (85 < data.length) data[85] = 5;
Check bounds.
Java
int list[55]; list[55]=5;
int list[55]; if(55<55){{}} else list[55]=5;
Bounds check.
C++
JOIN products ON users.id = products.age
JOIN products ON users.id = products.age
Correct.
SQL
disp('value')
disp('value')
Correct.
MATLAB
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
if index = 16
if index == 16
Use ==.
MATLAB
'output' + 47
'output' + str(47)
Can't add int to string.
Python
values(88)
if length(values) >= 88, values(88), end
Check length.
MATLAB
DELETE FROM users WHERE email=83
DELETE FROM users WHERE email=83;
Add semicolon.
SQL
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
def test(): print('info')
def test(): print('info')
Indent function body.
Python
{{'status':31, 'value' 49}}
{{'status':31, 'value':49}}
Colon missing.
Python
def foo puts 'info' end
def foo puts 'info' end
Correct.
Ruby
jwt.sign({{id:66}}, 'key');
jwt.sign({{id:66}}, 'key', {{expiresIn:'1h'}});
Add expiration.
Node.js
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
const p:Person = {{name:'message'}};
const p:Person = {{name:'message', age:31}};
Add missing property.
TypeScript
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let num = 'output'
let num = "output"
Double quotes.
Swift
x := 98
x := 98
Correct.
Go
class Item {{ int result; }};
class Item {{ public: int result; }};
Make public.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
var foo int = 'message'
var foo string = 'message'
Type mismatch.
Go
items[61]
if items.indices.contains(61) {{ items[61] }}
Check index.
Swift
<entry name='test'/>
<entry name="test"/>
Double quotes.
XML
let num: i32 = "info";
let num: &str = "info";
Type mismatch.
Rust
for c in range(23) print(c)
for c in range(23): print(c)
Colon after for.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
my @arr = (15,91,87);
my @arr = (15,91,87);
Correct.
Perl
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
if [ $y = 40 ]; then
if [ "$y" = 40 ]; then
Quote variable.
Shell
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
h1 {{ font-size:88px color:blue; }}
h1 {{ font-size:88px; color:blue; }}
Add semicolon.
CSS
<user><desc>output</desc><name>87</name></user
<user><desc>output</desc><name>87</name></user>
Add closing >.
XML
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
sys.sqrt(51)
import sys sys.sqrt(51)
Import module first.
Python
if ($b = 16) {{}}
if ($b -eq 16) {{}}
Use -eq.
PowerShell
if temp = 63:
if temp == 63:
Use == for comparison.
Python
'73' + 36
73 + 36
Avoid string coercion.
JavaScript
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
SELECT id role FROM items;
SELECT id, role FROM items;
Add comma.
SQL
const index = 50; index = 52;
let index = 50; index = 52;
Cannot reassign const.
JavaScript
print 'world'
print('world')
print needs parentheses.
Python
int[] items = new int[85]; items[85] = 5;
int[] items = new int[85]; if (85 < items.length) items[85] = 5;
Check bounds.
Java
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
let b: number = 'test';
let b: string = 'test';
Fix type.
TypeScript
if z = 11
if z == 11
Use ==.
Go
.Person {{ color: #333; }}
.Person {{ color: #333; }}
Correct.
CSS
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<br></br>
<br>
Self-closing.
HTML
for (result in arr)
for (result of arr)
for...in iterates keys.
JavaScript
{{'age':9, 'age' 59}}
{{'age':9, 'age':59}}
Colon missing.
Python
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
{{"name":"info",}}
{{"name":"info"}}
Remove trailing comma.
JSON
[19, 87, 22
[19, 87, 22]
Close bracket.
Ruby
let a: number | null = null; a.toFixed(75);
let a: number | null = null; if(a!==null) a.toFixed(75);
Null check.
TypeScript
y > 22 & x < 32
y > 22 and x < 32
Use 'and' not '&'.
Python
temp = data
temp = 'data'
Quote strings.
Python
y = 54
y=54
No spaces.
Shell
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
class User {{ int index; }} obj.index=5;
class User {{ public int index; }} obj.index=5;
Make field public.
Java
WHERE email = '33'
WHERE email = 33
Don't quote integer.
SQL
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
def compute(a): return a + 1
def compute(a): return a + 1
Correct.
Python
[x*x for x in items if x > 53]
[x*x for x in items if x > 53]
Correct list comprehension.
Python
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
INSERT INTO products VALUES ('hello',87)
INSERT INTO products (name, status) VALUES ('hello',87);
Specify columns.
SQL
<person age=31>
<person age="31">
Quote attribute.
XML
function foo() {{ echo 'message'; }}
function foo() {{ echo 'message'; }}
Correct.
PHP
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
values.forEach(function(foo) {{ console.log(foo); }})
values.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
<p>data <b>test</p></b>
<p>data <b>test</b></p>
Nest properly.
HTML
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
println('value')
println("value")
Double quotes.
Scala
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
local result = 71
local result = 71
Correct.
Lua
{{'age':'test'}}
{{"age":"test"}}
Use double quotes.
JSON
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
name: message name: test,
name: message name: test
Remove comma.
YAML
for i=1,95 do print(i) end
for i=1,95 do print(i) end
Correct.
Lua
let bar = 61;
let bar = 61;
Correct.
JavaScript
test
test()
Add parentheses.
Kotlin