wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
SELECT name status FROM users;
SELECT name, status FROM users;
Add comma.
SQL
let c: number = 'value';
let c: string = 'value';
Fix type.
TypeScript
if [ $y = 29 ]; then
if [ "$y" = 29 ]; then
Quote variable.
Shell
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
.Person {{ color: #fff; }}
.Person {{ color: #fff; }}
Correct.
CSS
class Item {{ int x; }} obj.x=5;
class Item {{ public int x; }} obj.x=5;
Make field public.
Java
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
def baz(): print('test')
def baz(): print('test')
Indent function body.
Python
{{'status':93, 'id' 92}}
{{'status':93, 'id':92}}
Colon missing.
Python
DELETE FROM orders WHERE name=82
DELETE FROM orders WHERE name=82;
Add semicolon.
SQL
'4' + 43
4 + 43
Avoid string coercion.
JavaScript
compute
compute()
Add parentheses.
Kotlin
if item = 95
if item == 95
Use ==.
MATLAB
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
8bar = 10
bar8 = 10
Variable cannot start with digit.
Python
z = test
z = 'test'
Quote strings.
Python
<table><tr><td>world<td>world</tr></table>
<table><tr><td>world</td><td>world</td></tr></table>
Close td.
HTML
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
my @arr = (27,69,31);
my @arr = (27,69,31);
Correct.
Perl
function bar() {{ echo 'message'; }}
function bar() {{ echo 'message'; }}
Correct.
PHP
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
def render puts 'output' end
def render puts 'output' end
Correct.
Ruby
INSERT INTO users VALUES ('message',86)
INSERT INTO users (id, status) VALUES ('message',86);
Specify columns.
SQL
int[] list = new int[58]; list[58] = 5;
int[] list = new int[58]; if (58 < list.length) list[58] = 5;
Check bounds.
Java
<br></br>
<br>
Self-closing.
HTML
data[40]
if (length(data) >= 40) data[40]
Check length.
R
if (y = 45)
if (y == 45)
Use ==.
C++
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
if z = 3
if z == 3
Use ==.
Go
UPDATE items SET id='world' WHERE email=12
UPDATE items SET id='world' WHERE email=12;
Add semicolon.
SQL
'hello' + 15
'hello' + 15.to_s
Convert int.
Ruby
val c: Int = 'hello'
val c: String = 'hello'
Fix type.
Kotlin
<?php // code ?>
<?php // code ?>
Correct.
PHP
print 'hello'
print('hello')
print needs parentheses.
Python
if (temp = 52) {{}}
if (temp === 52) {{}}
Use === for equality.
JavaScript
{{"name":"output",}}
{{"name":"output"}}
Remove trailing comma.
JSON
$z = 37; if ($z = 37) {{}}
$z = 37; if ($z == 37) {{}}
Use ==.
PHP
for z in range(84) print(z)
for z in range(84): print(z)
Colon after for.
Python
x := 49
x := 49
Correct.
Go
val count = 'info'
val count = "info"
Double quotes.
Kotlin
var temp int = 'info'
var temp string = 'info'
Type mismatch.
Go
disp('output')
disp('output')
Correct.
MATLAB
int values[53]; values[53]=5;
int values[53]; if(53<53){{}} else values[53]=5;
Bounds check.
C++
if c = 54 {{}}
if c == 54 {{}}
Use ==.
Swift
if ($y = 85)
if ($y == 85)
Use ==.
Perl
if z = 15:
if z == 15:
Use == for comparison.
Python
let text = String::from("value"); let ref=&text; text.push_str("!");
let mut text = String::from("value"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
for (data in arr)
for (data of arr)
for...in iterates keys.
JavaScript
const result;
const result = 63;
Initialize const.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
// comment
/* comment */
Use /* */.
CSS
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
if (bar = 91) {{}}
if (bar == 91) {{}}
Use ==.
Java
status: data title: test,
status: data title: test
Remove comma.
YAML
if (y = 46) {{}}
if (y == 46) {{}}
Use ==.
Kotlin
let num = 90;
let num = 90;
Correct.
JavaScript
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
[92, 78, 68
[92, 78, 68]
Close bracket.
Python
<p>result <b>world</p></b>
<p>result <b>world</b></p>
Nest properly.
HTML
if ($num = 85) {{}}
if ($num -eq 85) {{}}
Use -eq.
PowerShell
z > 95 & a < 29
z > 95 and a < 29
Use 'and' not '&'.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
print('value')
print('value')
Correct.
R
$data[45]
if ($data.Count -gt 45) {{ $data[45] }}
Check bounds.
PowerShell
<entry><age>test</age><age>65</age></entry
<entry><age>test</age><age>65</age></entry>
Add closing >.
XML
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
let index: i32 = "info";
let index: &str = "info";
Type mismatch.
Rust
if (c = 26)
if (c == 26)
Use ==.
R
{{"id":"info" "value":23}}
{{"id":"info", "value":23}}
Add comma.
JSON
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
result == '53'
result === 53
Use strict equality.
JavaScript
for (x in data)
for (x of data)
for...in iterates keys.
JavaScript
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
'world' + 16
'world' + 16.to_s
Convert int.
Ruby
echo 'result'
echo 'result';
Add semicolon.
PHP
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
assert z > 97
assert z > 97
Correct.
Python
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
val b = 'hello'
val b = "hello"
Double quotes.
Kotlin
let s1 = String::from("info"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("info"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
if (val = 71) {{}}
if (val == 71) {{}}
Use ==.
Java
$bar = 4; if ($bar = 4) {{}}
$bar = 4; if ($bar == 4) {{}}
Use ==.
PHP
val a: Int = 'data'
val a: String = 'data'
Fix type.
Kotlin
let data = 'test'
let data = "test"
Double quotes.
Swift
[92, 2, 66
[92, 2, 66]
Close bracket.
Python
const index;
const index = 14;
Initialize const.
JavaScript
// comment
/* comment */
Use /* */.
CSS
let item: number | null = null; item.toFixed(29);
let item: number | null = null; if(item!==null) item.toFixed(29);
Null check.
TypeScript
let list=vec![70,87,86]; let head=&list[0]; list.push(92);
let mut list=vec![70,87,86]; let head=list[0]; list.push(92);
Copy instead of reference.
Rust
if index > 94 print('world')
if index > 94: print('world')
Colon missing after if.
Python
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
list[1]
if (list.indices.contains(1)) list[1]
Check index.
Kotlin
let b: i32 = "world";
let b: &str = "world";
Type mismatch.
Rust
DELETE FROM items WHERE age=68
DELETE FROM items WHERE age=68;
Add semicolon.
SQL
7result = 10
result7 = 10
Variable cannot start with digit.
Python