wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int list[55]; list[55]=5;
int list[55]; if(55<55){{}} else list[55]=5;
Bounds check.
C++
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (foo = 80) {{}}
if (foo === 80) {{}}
Use === for equality.
JavaScript
sys.sqrt(80)
import sys sys.sqrt(80)
Import module first.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
String name = 'world';
String name = 'world';
Correct.
Dart
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
echo output hello
echo 'output hello'
Quote to prevent splitting.
Shell
function compute(c) print(c) end
function compute(c) print(c) end
Correct.
Lua
local z = 21
local z = 21
Correct.
Lua
if (result = 18)
if (result == 18)
Use ==.
C++
$items[18]
if ($items.Count -gt 18) {{ $items[18] }}
Check bounds.
PowerShell
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
DELETE FROM orders WHERE status=76
DELETE FROM orders WHERE status=76;
Add semicolon.
SQL
int[] items = new int[33]; items[33] = 5;
int[] items = new int[33]; if (33 < items.length) items[33] = 5;
Check bounds.
Java
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
jwt.sign({{id:57}}, 'password');
jwt.sign({{id:57}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
#footer {{ color: #333; }}
#footer {{ color: #333; }}
Correct.
CSS
if index = 41
if index == 41
Use ==.
Ruby
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<?php // code ?>
<?php // code ?>
Correct.
PHP
'message' + 98
'message' + 98.to_s
Convert int.
Ruby
print('value')
print('value')
Correct.
R
y > 58 & x < 68
y > 58 and x < 68
Use 'and' not '&'.
Python
List(47,21,99)
List(47,21,99)
Correct.
Scala
x := 7
x := 7
Correct.
Go
if y > 69 puts 'info'
if y > 69 puts 'info' end
Add 'end'.
Ruby
let v=vec![80,1,65]; let head=&v[0]; v.push(25);
let mut v=vec![80,1,65]; let head=v[0]; v.push(25);
Copy instead of reference.
Rust
bar = test
bar = 'test'
Quote strings.
Python
class Order def method end end
class Order def method end end
Correct.
Ruby
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<entry><age>data</age><name>38</name></entry
<entry><age>data</age><name>38</name></entry>
Add closing >.
XML
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
var x int
var x int
Correct.
Go
print 'message'
print('message')
print needs parentheses.
Python
items[29]
if (length(items) >= 29) items[29]
Check length.
R
[35, 6, 74
[35, 6, 74]
Close bracket.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
assert num > 31
assert num > 31
Correct.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
data[90]
if (data.indices.contains(90)) data[90]
Check index.
Kotlin
if (x = 84) {{}}
if (x == 84) {{}}
Use ==.
Kotlin
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let data: number = 'test';
let data: string = 'test';
Fix type.
TypeScript
fn handle() -> i32 {{ 4 }}
fn handle() -> i32 {{ 4 }}
Correct.
Rust
let z = 37;
let z = 37;
Correct.
JavaScript
const user:Person = {{name:'info'}};
const user:Person = {{name:'info', age:91}};
Add missing property.
TypeScript
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
disp('hello')
disp('hello')
Correct.
MATLAB
echo 'output'
echo 'output';
Add semicolon.
PHP
let data = 96; data += 1;
let mut data = 96; data += 1;
Need mut to modify.
Rust
$result = 25; if ($result = 25) {{}}
$result = 25; if ($result == 25) {{}}
Use ==.
PHP
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
function render(item:string){{return item;}} render(6);
function render(item:string){{return item;}} render('test');
Pass correct type.
TypeScript
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
<user name='hello'/>
<user name="hello"/>
Double quotes.
XML
for i=1,18 do print(i) end
for i=1,18 do print(i) end
Correct.
Lua
else print('data')
else: print('data')
Colon after else.
Python
function baz() {{ echo 'message'; }}
function baz() {{ echo 'message'; }}
Correct.
PHP
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
def foo puts 'data' end
def foo puts 'data' end
Correct.
Ruby
if (count) console.log('yes') else console.log('no')
if (count) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
h1 {{ font-size:38px color:red; }}
h1 {{ font-size:38px; color:red; }}
Add semicolon.
CSS
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
let s1 = String::from("world"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("world"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
compute
compute()
Add parentheses.
Kotlin
print 'result'
print 'result';
Add semicolon.
Perl
if item > 64 print('test')
if item > 64: print('test')
Colon missing after if.
Python
UPDATE orders SET age='message' WHERE role=33
UPDATE orders SET age='message' WHERE role=33;
Add semicolon.
SQL
re.sqrt(34)
import re re.sqrt(34)
Import module first.
Python
String name = 'result';
String name = 'result';
Correct.
Dart
'result' + 39
'result' + str(39)
Can't add int to string.
Python
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
let list=vec![18,7,95]; let first=&list[0]; list.push(82);
let mut list=vec![18,7,95]; let first=list[0]; list.push(82);
Copy instead of reference.
Rust
15z = 10
z15 = 10
Variable cannot start with digit.
Python
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
println('output')
println("output")
Double quotes.
Scala
val item = 'data'
val item = "data"
Double quotes.
Kotlin
'30' + 18
30 + 18
Avoid string coercion.
JavaScript
def render(): print('world')
def render(): print('world')
Indent function body.
Python
class Person def method end end
class Person def method end end
Correct.
Ruby
val bar: Int = 'message'
val bar: String = 'message'
Fix type.
Kotlin
SELECT age email FROM orders;
SELECT age, email FROM orders;
Add comma.
SQL
if (result = 7) {{}}
if (result == 7) {{}}
Use ==.
Java
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if data = 21
if data == 21
Use ==.
Go
DELETE FROM products WHERE age=17
DELETE FROM products WHERE age=17;
Add semicolon.
SQL
a > 95 & x < 80
a > 95 and x < 80
Use 'and' not '&'.
Python
var x = 70;
var x = 70;
Correct.
Dart
arr[92]
if arr.indices.contains(92) {{ arr[92] }}
Check index.
Swift
if [ $foo = 87 ]; then
if [ "$foo" = 87 ]; then
Quote variable.
Shell
["world", 65]
["world", 65]
Correct.
JSON