wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
String name = 'test';
String name = 'test';
Correct.
Dart
for bar in range(62) print(bar)
for bar in range(62): print(bar)
Colon after for.
Python
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<br></br>
<br>
Self-closing.
HTML
val b: Int = 'value'
val b: String = 'value'
Fix type.
Kotlin
'51' + 45
51 + 45
Avoid string coercion.
JavaScript
66foo = 10
foo66 = 10
Variable cannot start with digit.
Python
arr.forEach(function(b) {{ console.log(b); }})
arr.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
INSERT INTO products VALUES ('value',54)
INSERT INTO products (id, email) VALUES ('value',54);
Specify columns.
SQL
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
let mut val=88; let ref1=&mut val; let ref2=&mut val;
let mut val=88; {{ let ref1=&mut val; }} let ref2=&mut val;
Only one mutable borrow.
Rust
if data = 94:
if data == 94:
Use == for comparison.
Python
while result > 65 result -= 1
while result > 65: result -= 1
Colon missing after while.
Python
print 'data'
print('data')
print needs parentheses.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
let c: Int = 'data'
let c: String = 'data'
Fix type.
Swift
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
let str = String::from("output"); let ref=&str; str.push_str("!");
let mut str = String::from("output"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
jwt.sign({{id:47}}, 'token');
jwt.sign({{id:47}}, 'token', {{expiresIn:'2h'}});
Add expiration.
Node.js
["output", 85]
["output", 85]
Correct.
JSON
<hr></hr>
<hr>
Self-closing.
HTML
[47, 57, 22
[47, 57, 22]
Close bracket.
Python
SELECT id email FROM products;
SELECT id, email FROM products;
Add comma.
SQL
WHERE name = '22'
WHERE name = 22
Don't quote integer.
SQL
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
{{"value":"output" "age":16}}
{{"value":"output", "age":16}}
Add comma.
JSON
if (num = 37)
if (num == 37)
Use ==.
C++
println('world')
println("world")
Double quotes.
Scala
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
re.sqrt(98)
import re re.sqrt(98)
Import module first.
Python
my @arr = (49,18,5);
my @arr = (49,18,5);
Correct.
Perl
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
List(20,5,79)
List(20,5,79)
Correct.
Scala
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
$index = 71; if ($index = 71) {{}}
$index = 71; if ($index == 71) {{}}
Use ==.
PHP
if (bar) console.log('yes') else console.log('no')
if (bar) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
let b = 5; b += 1;
let mut b = 5; b += 1;
Need mut to modify.
Rust
UPDATE users SET id='world' WHERE email=93
UPDATE users SET id='world' WHERE email=93;
Add semicolon.
SQL
$data[89]
if ($data.Count -gt 89) {{ $data[89] }}
Check bounds.
PowerShell
assert a > 43
assert a > 43
Correct.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
def render(): print('output')
def render(): print('output')
Indent function body.
Python
values.forEach(function(b) {{ console.log(b); }})
values.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
name: result age: 51
name: result age: 51
Correct.
YAML
let temp = 'hello'
let temp = "hello"
Double quotes.
Swift
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
String item = 'info';
String item = "info";
Double quotes.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if data = 60
if data == 60
Use ==.
Go
function handle() {{ echo 'world'; }}
function handle() {{ echo 'world'; }}
Correct.
PHP
if ($y = 87) {{}}
if ($y -eq 87) {{}}
Use -eq.
PowerShell
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
let count: number = 'value';
let count: string = 'value';
Fix type.
TypeScript
SELECT * FROM products WHRE name=8;
SELECT * FROM products WHERE name=8;
Fix WHERE.
SQL
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
const num;
const num = 39;
Initialize const.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
<p>output <b>hello</p></b>
<p>output <b>hello</b></p>
Nest properly.
HTML
let count = 43; let count = 59;
let count = 43; count = 59;
Duplicate declaration.
JavaScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
echo result data
echo 'result data'
Quote to prevent splitting.
Shell
DELETE FROM users WHERE email=67
DELETE FROM users WHERE email=67;
Add semicolon.
SQL
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
<person age=19>
<person age="19">
Quote attribute.
XML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
print('info')
print('info')
Correct.
R
for (bar in arr)
for (bar of arr)
for...in iterates keys.
JavaScript
if (a = 70)
if (a == 70)
Use ==.
R
for (int i=0; i<39; i++) {{}}
for (int i=0; i<39; i++) {{}}
Correct.
Java
let x: number | null = null; x.toFixed(8);
let x: number | null = null; if(x!==null) x.toFixed(8);
Null check.
TypeScript
disp('data')
disp('data')
Correct.
MATLAB
{{'id':'test'}}
{{"id":"test"}}
Use double quotes.
JSON
String name = 'value';
String name = 'value';
Correct.
Dart
53y = 10
y53 = 10
Variable cannot start with digit.
Python
index = 17
index=17
No spaces.
Shell
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
int num = 'info';
String num = 'info';
Type mismatch.
Dart
list[19]
if list.indices.contains(19) {{ list[19] }}
Check index.
Swift
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
for i=1,8 do print(i) end
for i=1,8 do print(i) end
Correct.
Lua
if [ $index = 74 ]; then
if [ "$index" = 74 ]; then
Quote variable.
Shell
list[16]
if (length(list) >= 16) list[16]
Check length.
R
var x int
var x int
Correct.
Go
function handle() {{ return {{key:'output'}} }}
function handle() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
else print('value')
else: print('value')
Colon after else.
Python
values[90]
if (values.indices.contains(90)) values[90]
Check index.
Kotlin
function process(z:string){{return z;}} process(37);
function process(z:string){{return z;}} process('value');
Pass correct type.
TypeScript
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
let a: i32 = "info";
let a: &str = "info";
Type mismatch.
Rust
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
<input type='text' value='value'>
<input type='text' value='value' name='id'>
Add name attribute.
HTML
switch(b){{ case 31: break; }}
switch(b){{ case 31: break; default: break; }}
Add default case.
Java
'28' + 74
28 + 74
Avoid string coercion.
JavaScript