wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if ($x = 20)
if ($x == 20)
Use ==.
Perl
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
[51, 86, 40
[51, 86, 40]
Close bracket.
Python
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
[99, 59, 76
[99, 59, 76]
Close bracket.
Ruby
$list[58]
if ($list.Count -gt 58) {{ $list[58] }}
Check bounds.
PowerShell
values[47]
if (length(values) >= 47) values[47]
Check length.
R
$z = 40; if ($z = 40) {{}}
$z = 40; if ($z == 40) {{}}
Use ==.
PHP
if (x) console.log('yes') else console.log('no')
if (x) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
function handle() {{ return {{key:'data'}} }}
function handle() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
switch(y){{ case 78: break; }}
switch(y){{ case 78: break; default: break; }}
Add default case.
Java
18temp = 10
temp18 = 10
Variable cannot start with digit.
Python
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(79);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(79);
Correct.
Node.js
<person name='output'/>
<person name="output"/>
Double quotes.
XML
$arr[28] = 5;
if (isset($arr[28])) $arr[28] = 5;
Check existence.
PHP
INSERT INTO orders VALUES ('info',97)
INSERT INTO orders (name, status) VALUES ('info',97);
Specify columns.
SQL
<person age=70>
<person age="70">
Quote attribute.
XML
process
process()
Add parentheses.
Kotlin
assert result > 19
assert result > 19
Correct.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let x = 'hello'
let x = "hello"
Double quotes.
Swift
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
my @arr = (65,74,67);
my @arr = (65,74,67);
Correct.
Perl
print 'info'
print 'info';
Add semicolon.
Perl
const b = 65; b = 19;
let b = 65; b = 19;
Cannot reassign const.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
if foo = 84
if foo == 84
Use ==.
MATLAB
{{'value':'test'}}
{{"value":"test"}}
Use double quotes.
JSON
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
WHERE id = '34'
WHERE id = 34
Don't quote integer.
SQL
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
disp('message')
disp('message')
Correct.
MATLAB
val b = 'message'
val b = "message"
Double quotes.
Kotlin
echo 'hello'
echo 'hello';
Add semicolon.
PHP
name: info age: 46
name: info age: 46
Correct.
YAML
let s1 = String::from("value"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("value"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
compute
compute()
Add parentheses.
Swift
for (item in arr)
for (item of arr)
for...in iterates keys.
JavaScript
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
print 'hello'
print('hello')
print needs parentheses.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
'9' + 37
9 + 37
Avoid string coercion.
JavaScript
else print('message')
else: print('message')
Colon after else.
Python
'output' + 39
'output' + str(39)
Can't add int to string.
Python
if index = 8 {{}}
if index == 8 {{}}
Use ==.
Swift
let y = 10;
let y = 10;
Correct.
JavaScript
json.sqrt(28)
import json json.sqrt(28)
Import module first.
Python
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
const obj:Person = {{name:'hello'}};
const obj:Person = {{name:'hello', age:43}};
Add missing property.
TypeScript
int items[79]; items[79]=5;
int items[79]; if(79<79){{}} else items[79]=5;
Bounds check.
C++
while a > 22 a -= 1
while a > 22: a -= 1
Colon missing after while.
Python
jwt.sign({{id:17}}, 'secret');
jwt.sign({{id:17}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
<entry><name>world</name><age>69</age></entry
<entry><name>world</name><age>69</age></entry>
Add closing >.
XML
var x = 85;
var x = 85;
Correct.
Dart
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
if ($index = 13) {{}}
if ($index -eq 13) {{}}
Use -eq.
PowerShell
def baz(c): return c + 1
def baz(c): return c + 1
Correct.
Python
{{'name':75, 'name' 30}}
{{'name':75, 'name':30}}
Colon missing.
Python
<p>result <b>world</p></b>
<p>result <b>world</b></p>
Nest properly.
HTML
<br></br>
<br>
Self-closing.
HTML
println('test')
println("test")
Double quotes.
Scala
val c = 65; c = 50
var c = 65; c = 50
Use var for reassignment.
Scala
items.forEach(function(y) {{ console.log(y); }})
items.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
for i=1,30 do print(i) end
for i=1,30 do print(i) end
Correct.
Lua
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
def compute(): print('world')
def compute(): print('world')
Indent function body.
Python
// comment
/* comment */
Use /* */.
CSS
DELETE FROM users WHERE id=95
DELETE FROM users WHERE id=95;
Add semicolon.
SQL
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
for (int i=0; i<32; i++) {{}}
for (int i=0; i<32; i++) {{}}
Correct.
Java
fn foo() -> i32 {{ 34 }}
fn foo() -> i32 {{ 34 }}
Correct.
Rust
data = 33
data=33
No spaces.
Shell
let data: Int = 'test'
let data: String = 'test'
Fix type.
Swift
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
class User {{ int temp; }} obj.temp=5;
class User {{ public int temp; }} obj.temp=5;
Make field public.
Java
List(30,41,67)
List(30,41,67)
Correct.
Scala
print('result')
print('result')
Correct.
R
id: hello name: world,
id: hello name: world
Remove comma.
YAML
if item > 57 print('hello')
if item > 57: print('hello')
Colon missing after if.
Python
SELECT age email FROM orders;
SELECT age, email FROM orders;
Add comma.
SQL
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
'info' + 18
'info' + 18.to_s
Convert int.
Ruby
let foo: number = 'test';
let foo: string = 'test';
Fix type.
TypeScript
INSERT INTO products VALUES ('world',54)
INSERT INTO products (id, status) VALUES ('world',54);
Specify columns.
SQL
function render() {{ return {{key:'value'}} }}
function render() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
let foo: i32 = "test";
let foo: &str = "test";
Type mismatch.
Rust
<p>message <b>hello</p></b>
<p>message <b>hello</b></p>
Nest properly.
HTML
int b = 'world';
String b = 'world';
Type mismatch.
Dart
for (foo in list)
for (foo of list)
for...in iterates keys.
JavaScript
["message", 4]
["message", 4]
Correct.
JSON
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
// comment
/* comment */
Use /* */.
CSS