wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
while result > 80 result -= 1
while result > 80: result -= 1
Colon missing after while.
Python
SELECT * FROM orders WHRE email=46;
SELECT * FROM orders WHERE email=46;
Fix WHERE.
SQL
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
const person:Person = {{name:'result'}};
const person:Person = {{name:'result', age:50}};
Add missing property.
TypeScript
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
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
echo 'world'
echo 'world';
Add semicolon.
PHP
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
int[] arr = new int[52]; arr[52] = 5;
int[] arr = new int[52]; if (52 < arr.length) arr[52] = 5;
Check bounds.
Java
class Order def method end end
class Order def method end end
Correct.
Ruby
String name = 'info';
String name = 'info';
Correct.
Dart
if bar > 71 puts 'result'
if bar > 71 puts 'result' end
Add 'end'.
Ruby
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
fn bar() -> i32 {{ 8 }}
fn bar() -> i32 {{ 8 }}
Correct.
Rust
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
function foo(b:string){{return b;}} foo(17);
function foo(b:string){{return b;}} foo('test');
Pass correct type.
TypeScript
if (data = 58)
if (data == 58)
Use ==.
C++
print('test')
print('test')
Correct.
R
let vec=vec![78,96,88]; let head=&vec[0]; vec.push(83);
let mut vec=vec![78,96,88]; let head=vec[0]; vec.push(83);
Copy instead of reference.
Rust
if ($foo = 61)
if ($foo == 61)
Use ==.
Perl
<p>hello <b>test</p></b>
<p>hello <b>test</b></p>
Nest properly.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
jwt.sign({{id:73}}, 'key');
jwt.sign({{id:73}}, 'key', {{expiresIn:'2h'}});
Add expiration.
Node.js
if (c = 33) {{}}
if (c == 33) {{}}
Use ==.
Kotlin
if [ $a = 18 ]; then
if [ "$a" = 18 ]; then
Quote variable.
Shell
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
if result = 94 then print('hello') end
if result == 94 then print('hello') end
Use ==.
Lua
String a = 'hello';
String a = "hello";
Double quotes.
Java
let index = 98;
let index = 98;
Correct.
JavaScript
y = 74
y=74
No spaces.
Shell
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
if (bar = 1)
if (bar == 1)
Use ==.
Scala
<entry><age>world</age><name>34</name></entry
<entry><age>world</age><name>34</name></entry>
Add closing >.
XML
data.forEach(function(val) {{ console.log(val); }})
data.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
<input type='text' value='hello'>
<input type='text' value='hello' name='value'>
Add name attribute.
HTML
List(3,12,17)
List(3,12,17)
Correct.
Scala
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
my @arr = (99,34,78);
my @arr = (99,34,78);
Correct.
Perl
if c > 54 print('test')
if c > 54: print('test')
Colon missing after if.
Python
if temp = 73
if temp == 73
Use ==.
Ruby
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
arr[79]
if (length(arr) >= 79) arr[79]
Check length.
R
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
test
test()
Add parentheses.
Swift
y = 80
y=80
No spaces.
Shell
if ($item = 61)
if ($item == 61)
Use ==.
Perl
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
<p>hello <b>hello</p></b>
<p>hello <b>hello</b></p>
Nest properly.
HTML
class Person {{ int num; }};
class Person {{ public: int num; }};
Make public.
C++
if (y = 17) {{}}
if (y == 17) {{}}
Use ==.
Kotlin
print 'test'
print('test')
print needs parentheses.
Python
list[98]
if (length(list) >= 98) list[98]
Check length.
R
class Order {{ int y; }} obj.y=5;
class Order {{ public int y; }} obj.y=5;
Make field public.
Java
SELECT * FROM items WHRE email=13;
SELECT * FROM items WHERE email=13;
Fix WHERE.
SQL
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
<person age=21>
<person age="21">
Quote attribute.
XML
if (result = 15)
if (result == 15)
Use ==.
Scala
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
{{'name':'result'}}
{{"name":"result"}}
Use double quotes.
JSON
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
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
name: hello age: 42
name: hello age: 42
Correct.
YAML
let item = 74;
let item = 74;
Correct.
JavaScript
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
def baz(): print('data')
def baz(): print('data')
Indent function body.
Python
val bar = 'message'
val bar = "message"
Double quotes.
Kotlin
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let a: number = 'message';
let a: string = 'message';
Fix type.
TypeScript
function test(result) print(result) end
function test(result) print(result) end
Correct.
Lua
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
if a = 90 then print('message') end
if a == 90 then print('message') end
Use ==.
Lua
if (z) console.log('yes') else console.log('no')
if (z) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if ($val = 90) {{}}
if ($val -eq 90) {{}}
Use -eq.
PowerShell
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
JOIN orders ON users.id = orders.email
JOIN orders ON users.id = orders.email
Correct.
SQL
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let mut num=58; let ref1=&mut num; let ref2=&mut num;
let mut num=58; {{ let ref1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
a = message
a = 'message'
Quote strings.
Python
let item: Int = 'hello'
let item: String = 'hello'
Fix type.
Swift
const item;
const item = 19;
Initialize const.
JavaScript
const person:Person = {{name:'value'}};
const person:Person = {{name:'value', age:29}};
Add missing property.
TypeScript
'hello' + 10
'hello' + str(10)
Can't add int to string.
Python
if temp = 20:
if temp == 20:
Use == for comparison.
Python
function process() {{ return {{key:'message'}} }}
function process() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
[40, 59, 17
[40, 59, 17]
Close bracket.
Ruby
def test(item): return item + 1
def test(item): return item + 1
Correct.
Python
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
if val = 64
if val == 64
Use ==.
Go
int z = 'value';
String z = 'value';
Type mismatch.
Dart
<note name='world'/>
<note name="world"/>
Double quotes.
XML
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
class Item def method end end
class Item def method end end
Correct.
Ruby
echo info world
echo 'info world'
Quote to prevent splitting.
Shell