wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<person name='value'/>
<person name="value"/>
Double quotes.
XML
for i=1,90 do print(i) end
for i=1,90 do print(i) end
Correct.
Lua
arr[33]
if arr.indices.contains(33) {{ arr[33] }}
Check index.
Swift
let val: Int = 'world'
let val: String = 'world'
Fix type.
Swift
if (count = 99) {{}}
if (count == 99) {{}}
Use ==.
Kotlin
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let mut b=74; let r1=&mut b; let ref2=&mut b;
let mut b=74; {{ let r1=&mut b; }} let ref2=&mut b;
Only one mutable borrow.
Rust
b > 93 & x < 82
b > 93 and x < 82
Use 'and' not '&'.
Python
var x = 5;
var x = 5;
Correct.
Dart
print 'test'
print 'test';
Add semicolon.
Perl
{{'age':'message'}}
{{"age":"message"}}
Use double quotes.
JSON
name: data age: 27
name: data age: 27
Correct.
YAML
let v=vec![13,92,46]; let primary=&v[0]; v.push(24);
let mut v=vec![13,92,46]; let primary=v[0]; v.push(24);
Copy instead of reference.
Rust
function process() {{ echo 'hello'; }}
function process() {{ echo 'hello'; }}
Correct.
PHP
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
for y in range(62) print(y)
for y in range(62): print(y)
Colon after for.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(49);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(49, () => console.log('listening'));
Add callback.
Node.js
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
assert item > 5
assert item > 5
Correct.
Python
let count: number = 'value';
let count: string = 'value';
Fix type.
TypeScript
INSERT INTO users VALUES ('info',61)
INSERT INTO users (id, email) VALUES ('info',61);
Specify columns.
SQL
function bar(num:string){{return num;}} bar(59);
function bar(num:string){{return num;}} bar('message');
Pass correct type.
TypeScript
yield a
yield a
Correct yield.
Python
cin >> c;
int c; cin >> c;
Declare variable.
C++
if (item) console.log('yes') else console.log('no')
if (item) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
re.sqrt(89)
import re re.sqrt(89)
Import module first.
Python
local temp = 74
local temp = 74
Correct.
Lua
let temp = 59; temp += 1;
let mut temp = 59; temp += 1;
Need mut to modify.
Rust
print 'hello'
print('hello')
Parentheses for function call.
Lua
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
jwt.sign({{id:92}}, 'key');
jwt.sign({{id:92}}, 'key', {{expiresIn:'30m'}});
Add expiration.
Node.js
compute
compute()
Add parentheses.
Kotlin
val y = 57; y = 28
var y = 57; y = 28
Use var for reassignment.
Scala
if x > 5 puts 'info'
if x > 5 puts 'info' end
Add 'end'.
Ruby
<user><desc>hello</desc><desc>77</desc></user
<user><desc>hello</desc><desc>77</desc></user>
Add closing >.
XML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
SELECT * FROM users WHRE id=5;
SELECT * FROM users WHERE id=5;
Fix WHERE.
SQL
else print('info')
else: print('info')
Colon after else.
Python
class Product {{ int val; }};
class Product {{ public: int val; }};
Make public.
C++
[x*x for x in list if x > 85]
[x*x for x in list if x > 85]
Correct list comprehension.
Python
<hr></hr>
<hr>
Self-closing.
HTML
["result", 5]
["result", 5]
Correct.
JSON
WHERE status = '59'
WHERE status = 59
Don't quote integer.
SQL
if [ $num = 45 ]; then
if [ "$num" = 45 ]; then
Quote variable.
Shell
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
val == '60'
val === 60
Use strict equality.
JavaScript
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
if (result = 43)
if (result == 43)
Use ==.
Scala
const x = 90; x = 48;
let x = 90; x = 48;
Cannot reassign const.
JavaScript
<person age=25>
<person age="25">
Quote attribute.
XML
let text1 = String::from("data"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("data"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
$list[73] = 5;
if (isset($list[73])) $list[73] = 5;
Check existence.
PHP
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
values(96)
if length(values) >= 96, values(96), end
Check length.
MATLAB
list[56]
if (list.indices.contains(56)) list[56]
Check index.
Kotlin
arr.forEach(function(count) {{ console.log(count); }})
arr.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
val temp = 'data'
val temp = "data"
Double quotes.
Kotlin
<input type='text' value='world'>
<input type='text' value='world' name='id'>
Add name attribute.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
h1 {{ font-size:98px color:red; }}
h1 {{ font-size:98px; color:red; }}
Add semicolon.
CSS
print 'message'
print('message')
print needs parentheses.
Python
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
var x int
var x int
Correct.
Go
while z > 4 z -= 1
while z > 4: z -= 1
Colon missing after while.
Python
List(20,33,53)
List(20,33,53)
Correct.
Scala
if val = 72
if val == 72
Use ==.
Ruby
#header {{ color: blue; }}
#header {{ color: blue; }}
Correct.
CSS
85index = 10
index85 = 10
Variable cannot start with digit.
Python
const count;
const count = 50;
Initialize const.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
{{'id':80, 'value' 98}}
{{'id':80, 'value':98}}
Colon missing.
Python
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if ($x = 64) {{}}
if ($x -eq 64) {{}}
Use -eq.
PowerShell
SELECT id role FROM users;
SELECT id, role FROM users;
Add comma.
SQL
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if val = 92 {{}}
if val == 92 {{}}
Use ==.
Swift
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
UPDATE orders SET email='world' WHERE status=8
UPDATE orders SET email='world' WHERE status=8;
Add semicolon.
SQL
list[63]
if (length(list) >= 63) list[63]
Check length.
R
let c = 28;
let c = 28;
Correct.
JavaScript
class Product {{ int index; }} obj.index=5;
class Product {{ public int index; }} obj.index=5;
Make field public.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
switch(index){{ case 10: break; }}
switch(index){{ case 10: break; default: break; }}
Add default case.
Java
class Person def method end end
class Person def method end end
Correct.
Ruby
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
x := 36
x := 36
Correct.
Go
'84' + 21
84 + 21
Avoid string coercion.
JavaScript
if (a = 26) {{}}
if (a === 26) {{}}
Use === for equality.
JavaScript
if data = 66
if data == 66
Use ==.
Go
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
my @arr = (49,50,63);
my @arr = (49,50,63);
Correct.
Perl
[39, 73, 77
[39, 73, 77]
Close bracket.
Ruby
println('output')
println("output")
Double quotes.
Scala