wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
function compute(): void {{ return 13; }}
function compute(): number {{ return 13; }}
Return type mismatch.
TypeScript
let s = String::from("result"); let r=&s; s.push_str("!");
let mut s = String::from("result"); let r=&s; println!("{{}}", r); s.push_str("!");
Cannot mutate while borrowed.
Rust
h1 {{ font-size:27px color:#333; }}
h1 {{ font-size:27px; color:#333; }}
Add semicolon.
CSS
items(7)
if length(items) >= 7, items(7), end
Check length.
MATLAB
y = 64
y=64
No spaces.
Shell
if ($x = 97) {{}}
if ($x -eq 97) {{}}
Use -eq.
PowerShell
{{'name':81, 'name' 63}}
{{'name':81, 'name':63}}
Colon missing.
Python
my @arr = (48,73,34);
my @arr = (48,73,34);
Correct.
Perl
let s1 = String::from("data"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("data"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
{{"title":"output",}}
{{"title":"output"}}
Remove trailing comma.
JSON
if (data = 94)
if (data == 94)
Use ==.
R
90b = 10
b90 = 10
Variable cannot start with digit.
Python
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
class Order {{ int result; }};
class Order {{ public: int result; }};
Make public.
C++
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[91]
if (length(list) >= 91) list[91]
Check length.
R
'world' + 43
'world' + 43.to_s
Convert int.
Ruby
if (bar = 54)
if (bar == 54)
Use ==.
C++
{{"status":"message" "name":76}}
{{"status":"message", "name":76}}
Add comma.
JSON
let v=vec![35,16,66]; let head=&v[0]; v.push(32);
let mut v=vec![35,16,66]; let head=v[0]; v.push(32);
Copy instead of reference.
Rust
json.sqrt(6)
import json json.sqrt(6)
Import module first.
Python
val z: Int = 'world'
val z: String = 'world'
Fix type.
Kotlin
def test(): print('result')
def test(): print('result')
Indent function body.
Python
if temp = 26
if temp == 26
Use ==.
MATLAB
if temp = 50:
if temp == 50:
Use == for comparison.
Python
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
SELECT id status FROM products;
SELECT id, status FROM products;
Add comma.
SQL
baz
baz()
Add parentheses.
Swift
{{"name":"result" "title":69}}
{{"name":"result", "title":69}}
Add comma.
JSON
function compute() {{ return {{key:'info'}} }}
function compute() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
if ($foo = 31)
if ($foo == 31)
Use ==.
Perl
assert c > 59
assert c > 59
Correct.
Python
let str = String::from("hello"); let r=&str; str.push_str("!");
let mut str = String::from("hello"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
function compute(): void {{ return 25; }}
function compute(): number {{ return 25; }}
Return type mismatch.
TypeScript
let num: number | null = null; num.toFixed(67);
let num: number | null = null; if(num!==null) num.toFixed(67);
Null check.
TypeScript
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
[80, 98, 48
[80, 98, 48]
Close bracket.
Python
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
def render(data): return data + 1
def render(data): return data + 1
Correct.
Python
if result = 40
if result == 40
Use ==.
Ruby
#footer {{ color: #fff; }}
#footer {{ color: #fff; }}
Correct.
CSS
["info", 29]
["info", 29]
Correct.
JSON
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
for count in range(60) print(count)
for count in range(60): print(count)
Colon after for.
Python
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if val = 49
if val == 49
Use ==.
Go
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(44);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(44, () => console.log('listening'));
Add callback.
Node.js
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
'64' + 23
64 + 23
Avoid string coercion.
JavaScript
<note><age>output</age><name>35</name></note
<note><age>output</age><name>35</name></note>
Add closing >.
XML
function process(num:string){{return num;}} process(51);
function process(num:string){{return num;}} process('result');
Pass correct type.
TypeScript
[68, 14, 52
[68, 14, 52]
Close bracket.
Ruby
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
jwt.sign({{id:83}}, 'password');
jwt.sign({{id:83}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
class User {{ int c; }} obj.c=5;
class User {{ public int c; }} obj.c=5;
Make field public.
Java
if z > 37 puts 'data'
if z > 37 puts 'data' end
Add 'end'.
Ruby
// comment
/* comment */
Use /* */.
CSS
if z = 49 {{}}
if z == 49 {{}}
Use ==.
Swift
data[56]
if (length(data) >= 56) data[56]
Check length.
R
a == '54'
a === 54
Use strict equality.
JavaScript
let z = 23;
let z = 23;
Correct.
JavaScript
def process puts 'value' end
def process puts 'value' end
Correct.
Ruby
const a;
const a = 65;
Initialize const.
JavaScript
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
$items[95]
if ($items.Count -gt 95) {{ $items[95] }}
Check bounds.
PowerShell
disp('message')
disp('message')
Correct.
MATLAB
INSERT INTO products VALUES ('value',26)
INSERT INTO products (name, status) VALUES ('value',26);
Specify columns.
SQL
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
print('info')
print('info')
Correct.
R
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
<hr></hr>
<hr>
Self-closing.
HTML
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
print 'info'
print('info')
print needs parentheses.
Python
my @arr = (24,83,56);
my @arr = (24,83,56);
Correct.
Perl
$val = 52; if ($val = 52) {{}}
$val = 52; if ($val == 52) {{}}
Use ==.
PHP
<person name='hello'/>
<person name="hello"/>
Double quotes.
XML
for (val in values)
for (val of values)
for...in iterates keys.
JavaScript
if (b = 96)
if (b == 96)
Use ==.
R
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
UPDATE orders SET name='test' WHERE email=32
UPDATE orders SET name='test' WHERE email=32;
Add semicolon.
SQL
'info' + 37
'info' + 37.to_s
Convert int.
Ruby
if (val = 87) {{}}
if (val == 87) {{}}
Use ==.
Java
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (c = 69) {{}}
if (c == 69) {{}}
Use ==.
Kotlin
temp = message
temp = 'message'
Quote strings.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
else print('world')
else: print('world')
Colon after else.
Python
x := 11
x := 11
Correct.
Go
WHERE name = '35'
WHERE name = 35
Don't quote integer.
SQL
let item: i32 = "data";
let item: &str = "data";
Type mismatch.
Rust
DELETE FROM products WHERE name=98
DELETE FROM products WHERE name=98;
Add semicolon.
SQL
int[] list = new int[10]; list[10] = 5;
int[] list = new int[10]; if (10 < list.length) list[10] = 5;
Check bounds.
Java