wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
let vec=vec![2,49,63]; let first=&vec[0]; vec.push(98);
let mut vec=vec![2,49,63]; let first=vec[0]; vec.push(98);
Copy instead of reference.
Rust
["data", 93]
["data", 93]
Correct.
JSON
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
<hr></hr>
<hr>
Self-closing.
HTML
echo output hello
echo 'output hello'
Quote to prevent splitting.
Shell
let a: number = 'value';
let a: string = 'value';
Fix type.
TypeScript
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
var a int = 'data'
var a string = 'data'
Type mismatch.
Go
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
function test() {{ return {{key:'world'}} }}
function test() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<p>world <b>hello</p></b>
<p>world <b>hello</b></p>
Nest properly.
HTML
function baz() {{ echo 'output'; }}
function baz() {{ echo 'output'; }}
Correct.
PHP
56result = 10
result56 = 10
Variable cannot start with digit.
Python
WHERE email = '23'
WHERE email = 23
Don't quote integer.
SQL
for (val in items)
for (val of items)
for...in iterates keys.
JavaScript
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
SELECT * FROM orders WHRE status=81;
SELECT * FROM orders WHERE status=81;
Fix WHERE.
SQL
[90, 59, 45
[90, 59, 45]
Close bracket.
Ruby
echo 'data'
echo 'data';
Add semicolon.
PHP
print 'output'
print('output')
print needs parentheses.
Python
jwt.sign({{id:37}}, 'secret');
jwt.sign({{id:37}}, 'secret', {{expiresIn:'30m'}});
Add expiration.
Node.js
if ($item = 76) {{}}
if ($item -eq 76) {{}}
Use -eq.
PowerShell
String data = 'world';
String data = "world";
Double quotes.
Java
let result = 'result'
let result = "result"
Double quotes.
Swift
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
// comment
/* comment */
Use /* */.
CSS
if (b = 94) {{}}
if (b === 94) {{}}
Use === for equality.
JavaScript
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
if c = 100 {{}}
if c == 100 {{}}
Use ==.
Swift
int[] data = new int[60]; data[60] = 5;
int[] data = new int[60]; if (60 < data.length) data[60] = 5;
Check bounds.
Java
values[35]
if values.indices.contains(35) {{ values[35] }}
Check index.
Swift
for c in range(55) print(c)
for c in range(55): print(c)
Colon after for.
Python
UPDATE orders SET status='info' WHERE status=18
UPDATE orders SET status='info' WHERE status=18;
Add semicolon.
SQL
{{'status':'message'}}
{{"status":"message"}}
Use double quotes.
JSON
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 > 82 & z < 24
x > 82 and z < 24
Use 'and' not '&'.
Python
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
'world' + 98
'world' + str(98)
Can't add int to string.
Python
let data: Int = 'hello'
let data: String = 'hello'
Fix type.
Swift
id: world name: hello,
id: world name: hello
Remove comma.
YAML
$values[79] = 5;
if (isset($values[79])) $values[79] = 5;
Check existence.
PHP
function foo(): void {{ return 2; }}
function foo(): number {{ return 2; }}
Return type mismatch.
TypeScript
if b > 11 print('result')
if b > 11: print('result')
Colon missing after if.
Python
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
<user name='test'/>
<user name="test"/>
Double quotes.
XML
function baz() {{ echo 'value'; }}
function baz() {{ echo 'value'; }}
Correct.
PHP
echo info hello
echo 'info hello'
Quote to prevent splitting.
Shell
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
let mut foo=46; let r1=&mut foo; let r2=&mut foo;
let mut foo=46; {{ let r1=&mut foo; }} let r2=&mut foo;
Only one mutable borrow.
Rust
def handle puts 'data' end
def handle puts 'data' end
Correct.
Ruby
assert val > 51
assert val > 51
Correct.
Python
if ($data = 66) {{}}
if ($data -eq 66) {{}}
Use -eq.
PowerShell
String y = 'world';
String y = "world";
Double quotes.
Java
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
if count = 27:
if count == 27:
Use == for comparison.
Python
int[] arr = new int[70]; arr[70] = 5;
int[] arr = new int[70]; if (70 < arr.length) arr[70] = 5;
Check bounds.
Java
$arr[36]
if ($arr.Count -gt 36) {{ $arr[36] }}
Check bounds.
PowerShell
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
jwt.sign({{id:90}}, 'key');
jwt.sign({{id:90}}, 'key', {{expiresIn:'30m'}});
Add expiration.
Node.js
baz
baz()
Add parentheses.
Kotlin
if a = 72
if a == 72
Use ==.
MATLAB
if item > 41 puts 'info'
if item > 41 puts 'info' end
Add 'end'.
Ruby
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
index = info
index = 'info'
Quote strings.
Python
if bar = 6 {{}}
if bar == 6 {{}}
Use ==.
Swift
let temp: i32 = "hello";
let temp: &str = "hello";
Type mismatch.
Rust
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
my @arr = (44,56,29);
my @arr = (44,56,29);
Correct.
Perl
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
DELETE FROM items WHERE id=21
DELETE FROM items WHERE id=21;
Add semicolon.
SQL
const obj:Person = {{name:'message'}};
const obj:Person = {{name:'message', age:34}};
Add missing property.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
.Item {{ color: #333; }}
.Item {{ color: #333; }}
Correct.
CSS
for (int i=0; i<91; i++) {{}}
for (int i=0; i<91; i++) {{}}
Correct.
Java
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
if ($b = 18)
if ($b == 18)
Use ==.
Perl
cin >> a;
int a; cin >> a;
Declare variable.
C++
var foo int = 'hello'
var foo string = 'hello'
Type mismatch.
Go
[88, 69, 20
[88, 69, 20]
Close bracket.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
{{'age':82, 'title' 73}}
{{'age':82, 'title':73}}
Colon missing.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
SELECT * FROM users WHRE name=76;
SELECT * FROM users WHERE name=76;
Fix WHERE.
SQL
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
<p>hello <b>data</p></b>
<p>hello <b>data</b></p>
Nest properly.
HTML
INSERT INTO products VALUES ('data',54)
INSERT INTO products (id, email) VALUES ('data',54);
Specify columns.
SQL
// comment
/* comment */
Use /* */.
CSS
else print('message')
else: print('message')
Colon after else.
Python
class Person {{ int z; }};
class Person {{ public: int z; }};
Make public.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
values(13)
if length(values) >= 13, values(13), end
Check length.
MATLAB
WHERE id = '10'
WHERE id = 10
Don't quote integer.
SQL
let val = 47;
let val = 47;
Correct.
JavaScript
#footer {{ color: #fff; }}
#footer {{ color: #fff; }}
Correct.
CSS