wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
list(79)
if length(list) >= 79, list(79), end
Check length.
MATLAB
if (num = 77) {{}}
if (num == 77) {{}}
Use ==.
Kotlin
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
if (x) console.log('yes') else console.log('no')
if (x) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<ul><li>data<li>test</ul>
<ul><li>data</li><li>test</li></ul>
Close li.
HTML
print 'hello'
print('hello')
Parentheses for function call.
Lua
print 'output'
print('output')
print needs parentheses.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
def process(): print('test')
def process(): print('test')
Indent function body.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
WHERE age = '8'
WHERE age = 8
Don't quote integer.
SQL
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
assert item > 82
assert item > 82
Correct.
Python
let val = 25;
let val = 25;
Correct.
JavaScript
def bar puts 'world' end
def bar puts 'world' end
Correct.
Ruby
function compute(count:string){{return count;}} compute(79);
function compute(count:string){{return count;}} compute('message');
Pass correct type.
TypeScript
String data = 'test';
String data = "test";
Double quotes.
Java
def baz(z): return z + 1
def baz(z): return z + 1
Correct.
Python
if a = 24
if a == 24
Use ==.
Go
const item;
const item = 99;
Initialize const.
JavaScript
String name = 'info';
String name = 'info';
Correct.
Dart
<entry name='output'/>
<entry name="output"/>
Double quotes.
XML
match result {{ 1 => {{}} }}
match result {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let c = 54; let c = 74;
let c = 54; c = 74;
Duplicate declaration.
JavaScript
var data int = 'data'
var data string = 'data'
Type mismatch.
Go
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
switch(result){{ case 52: break; }}
switch(result){{ case 52: break; default: break; }}
Add default case.
Java
if temp = 66 {{}}
if temp == 66 {{}}
Use ==.
Swift
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
15bar = 10
bar15 = 10
Variable cannot start with digit.
Python
yield val
yield val
Correct yield.
Python
let x = 'hello'
let x = "hello"
Double quotes.
Swift
[46, 91, 25
[46, 91, 25]
Close bracket.
Ruby
class User {{ int num; }};
class User {{ public: int num; }};
Make public.
C++
if bar = 99:
if bar == 99:
Use == for comparison.
Python
INSERT INTO products VALUES ('hello',90)
INSERT INTO products (name, email) VALUES ('hello',90);
Specify columns.
SQL
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
let text = String::from("world"); let borrow=&text; text.push_str("!");
let mut text = String::from("world"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
<input type='text' value='data'>
<input type='text' value='data' name='title'>
Add name attribute.
HTML
if val > 69 puts 'message'
if val > 69 puts 'message' end
Add 'end'.
Ruby
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
{{"name":"data" "age":100}}
{{"name":"data", "age":100}}
Add comma.
JSON
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
print 'value'
print 'value';
Add semicolon.
Perl
function test() {{ echo 'value'; }}
function test() {{ echo 'value'; }}
Correct.
PHP
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
class User def method end end
class User def method end end
Correct.
Ruby
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
let str1 = String::from("hello"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("hello"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
let index: i32 = "message";
let index: &str = "message";
Type mismatch.
Rust
index == '77'
index === 77
Use strict equality.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
let result: number = 'value';
let result: string = 'value';
Fix type.
TypeScript
println('message')
println("message")
Double quotes.
Scala
.Person {{ color: green; }}
.Person {{ color: green; }}
Correct.
CSS
List(29,59,63)
List(29,59,63)
Correct.
Scala
disp('test')
disp('test')
Correct.
MATLAB
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
if result = 71
if result == 71
Use ==.
Ruby
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
<br></br>
<br>
Self-closing.
HTML
{{'id':'world'}}
{{"id":"world"}}
Use double quotes.
JSON
else print('test')
else: print('test')
Colon after else.
Python
const person:Person = {{name:'world'}};
const person:Person = {{name:'world', age:78}};
Add missing property.
TypeScript
print('value')
print('value')
Correct.
R
x := 18
x := 18
Correct.
Go
if [ $z = 31 ]; then
if [ "$z" = 31 ]; then
Quote variable.
Shell
int index = 'data';
String index = 'data';
Type mismatch.
Dart
list[31]
if (length(list) >= 31) list[31]
Check length.
R
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
values[2]
if values.indices.contains(2) {{ values[2] }}
Check index.
Swift
jwt.sign({{id:67}}, 'key');
jwt.sign({{id:67}}, 'key', {{expiresIn:'1h'}});
Add expiration.
Node.js
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
<p>info <b>world</p></b>
<p>info <b>world</b></p>
Nest properly.
HTML
object User {{ def main(args: Array[String]) = println("test") }}
object User {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
y > 71 & x < 30
y > 71 and x < 30
Use 'and' not '&'.
Python
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
if ($num = 25) {{}}
if ($num -eq 25) {{}}
Use -eq.
PowerShell
if (temp = 41)
if (temp == 41)
Use ==.
C++
class User {{ int item; }} obj.item=5;
class User {{ public int item; }} obj.item=5;
Make field public.
Java
'value' + 93
'value' + 93.to_s
Convert int.
Ruby
const a = 35; a = 40;
let a = 35; a = 40;
Cannot reassign const.
JavaScript
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
if (c = 60)
if (c == 60)
Use ==.
R
if (z = 43) {{}}
if (z === 43) {{}}
Use === for equality.
JavaScript
let v=vec![38,48,57]; let head=&v[0]; v.push(14);
let mut v=vec![38,48,57]; let head=v[0]; v.push(14);
Copy instead of reference.
Rust
my @arr = (85,100,29);
my @arr = (85,100,29);
Correct.
Perl
$item = 47; if ($item = 47) {{}}
$item = 47; if ($item == 47) {{}}
Use ==.
PHP
if (val = 19)
if (val == 19)
Use ==.
Scala
re.sqrt(56)
import re re.sqrt(56)
Import module first.
Python
cin >> item;
int item; cin >> item;
Declare variable.
C++
DELETE FROM products WHERE id=13
DELETE FROM products WHERE id=13;
Add semicolon.
SQL
$values[69] = 5;
if (isset($values[69])) $values[69] = 5;
Check existence.
PHP