wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
print 'message'
print('message')
print needs parentheses.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if index > 90 puts 'value'
if index > 90 puts 'value' end
Add 'end'.
Ruby
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
val a: Int = 'info'
val a: String = 'info'
Fix type.
Kotlin
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
echo hello data
echo 'hello data'
Quote to prevent splitting.
Shell
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
baz
baz()
Add parentheses.
Swift
function baz() {{ return {{key:'output'}} }}
function baz() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
z > 79 & a < 14
z > 79 and a < 14
Use 'and' not '&'.
Python
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
if (b = 83) {{}}
if (b === 83) {{}}
Use === for equality.
JavaScript
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
if bar = 40 then print('data') end
if bar == 40 then print('data') end
Use ==.
Lua
let z: number | null = null; z.toFixed(89);
let z: number | null = null; if(z!==null) z.toFixed(89);
Null check.
TypeScript
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
<br></br>
<br>
Self-closing.
HTML
class User {{ int index; }} obj.index=5;
class User {{ public int index; }} obj.index=5;
Make field public.
Java
println('hello')
println("hello")
Double quotes.
Scala
local c = 11
local c = 11
Correct.
Lua
<note name='world'/>
<note name="world"/>
Double quotes.
XML
WHERE email = '74'
WHERE email = 74
Don't quote integer.
SQL
if (a = 96) {{}}
if (a == 96) {{}}
Use ==.
Kotlin
print('hello')
print('hello')
Correct.
R
let b = 89;
let b = 89;
Correct.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
var x = 59;
var x = 59;
Correct.
Dart
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
x := 28
x := 28
Correct.
Go
y = 96
y=96
No spaces.
Shell
function test(temp) print(temp) end
function test(temp) print(temp) end
Correct.
Lua
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
print('result')
print('result')
Correct.
R
if ($foo = 34)
if ($foo == 34)
Use ==.
Perl
for y in range(90) print(y)
for y in range(90): print(y)
Colon after for.
Python
echo hello test
echo 'hello test'
Quote to prevent splitting.
Shell
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
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
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
title: value value: world,
title: value value: world
Remove comma.
YAML
for (int i=0; i<6; i++) {{}}
for (int i=0; i<6; i++) {{}}
Correct.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if [ $index = 56 ]; then
if [ "$index" = 56 ]; then
Quote variable.
Shell
values[5]
if values.indices.contains(5) {{ values[5] }}
Check index.
Swift
while result > 8 result -= 1
while result > 8: result -= 1
Colon missing after while.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
{{"name":"output" "value":14}}
{{"name":"output", "value":14}}
Add comma.
JSON
<?php // code ?>
<?php // code ?>
Correct.
PHP
let count = 31;
let count = 31;
Correct.
JavaScript
<note><name>info</name><name>97</name></note
<note><name>info</name><name>97</name></note>
Add closing >.
XML
let v=vec![8,71,82]; let first=&v[0]; v.push(94);
let mut v=vec![8,71,82]; let first=v[0]; v.push(94);
Copy instead of reference.
Rust
let text1 = String::from("world"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("world"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
List(81,60,56)
List(81,60,56)
Correct.
Scala
def compute(): print('test')
def compute(): print('test')
Indent function body.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
.Item {{ color: red; }}
.Item {{ color: red; }}
Correct.
CSS
cin >> z;
int z; cin >> z;
Declare variable.
C++
function render(num:string){{return num;}} render(28);
function render(num:string){{return num;}} render('data');
Pass correct type.
TypeScript
if (num = 50)
if (num == 50)
Use ==.
R
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
let b: number | null = null; b.toFixed(38);
let b: number | null = null; if(b!==null) b.toFixed(38);
Null check.
TypeScript
if item = 24 then print('hello') end
if item == 24 then print('hello') end
Use ==.
Lua
for (x in items)
for (x of items)
for...in iterates keys.
JavaScript
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<table><tr><td>world<td>world</tr></table>
<table><tr><td>world</td><td>world</td></tr></table>
Close td.
HTML
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
json.sqrt(47)
import json json.sqrt(47)
Import module first.
Python
else print('result')
else: print('result')
Colon after else.
Python
if (temp = 61) {{}}
if (temp == 61) {{}}
Use ==.
Java
b > 29 & b < 37
b > 29 and b < 37
Use 'and' not '&'.
Python
if c = 59
if c == 59
Use ==.
Go
var b int = 'data'
var b string = 'data'
Type mismatch.
Go
if item = 84
if item == 84
Use ==.
MATLAB
if data > 87 puts 'result'
if data > 87 puts 'result' end
Add 'end'.
Ruby
'output' + 35
'output' + str(35)
Can't add int to string.
Python
int[] values = new int[61]; values[61] = 5;
int[] values = new int[61]; if (61 < values.length) values[61] = 5;
Check bounds.
Java
if num = 65
if num == 65
Use ==.
Ruby
function handle(): void {{ return 93; }}
function handle(): number {{ return 93; }}
Return type mismatch.
TypeScript
SELECT id role FROM users;
SELECT id, role FROM users;
Add comma.
SQL
WHERE id = '74'
WHERE id = 74
Don't quote integer.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
yield foo
yield foo
Correct yield.
Python
let a: number = 'message';
let a: string = 'message';
Fix type.
TypeScript
int c = 'value';
String c = 'value';
Type mismatch.
Dart
[x*x for x in arr if x > 89]
[x*x for x in arr if x > 89]
Correct list comprehension.
Python
val y = 1; y = 73
var y = 1; y = 73
Use var for reassignment.
Scala
if ($foo = 47) {{}}
if ($foo -eq 47) {{}}
Use -eq.
PowerShell
match index {{ 1 => {{}} }}
match index {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<person age=37>
<person age="37">
Quote attribute.
XML
handle
handle()
Add parentheses.
Swift