wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
json.sqrt(49)
import json json.sqrt(49)
Import module first.
Python
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
{{"id":"hello",}}
{{"id":"hello"}}
Remove trailing comma.
JSON
.Product {{ color: red; }}
.Product {{ color: red; }}
Correct.
CSS
if (x = 9) {{}}
if (x === 9) {{}}
Use === for equality.
JavaScript
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
{{'age':46, 'status' 47}}
{{'age':46, 'status':47}}
Colon missing.
Python
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
disp('world')
disp('world')
Correct.
MATLAB
math.sqrt(52)
import math math.sqrt(52)
Import module first.
Python
#content {{ color: blue; }}
#content {{ color: blue; }}
Correct.
CSS
data[4]
if data.indices.contains(4) {{ data[4] }}
Check index.
Swift
'84' + 92
84 + 92
Avoid string coercion.
JavaScript
jwt.sign({{id:78}}, 'token');
jwt.sign({{id:78}}, 'token', {{expiresIn:'1h'}});
Add expiration.
Node.js
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
arr(4)
if length(arr) >= 4, arr(4), end
Check length.
MATLAB
let str1 = String::from("output"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("output"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
count = 34
count=34
No spaces.
Shell
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
values.forEach(function(c) {{ console.log(c); }})
values.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
SELECT age role FROM items;
SELECT age, role FROM items;
Add comma.
SQL
function handle() {{ return {{key:'output'}} }}
function handle() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
h1 {{ font-size:9px color:#333; }}
h1 {{ font-size:9px; color:#333; }}
Add semicolon.
CSS
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(75);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(75, () => console.log('listening'));
Add callback.
Node.js
handle
handle()
Add parentheses.
Swift
for (data in list)
for (data of list)
for...in iterates keys.
JavaScript
print('output')
print('output')
Correct.
R
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
if bar = 84 {{}}
if bar == 84 {{}}
Use ==.
Swift
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let z = 95;
let z = 95;
Correct.
JavaScript
let mut item=99; let ref1=&mut item; let ref2=&mut item;
let mut item=99; {{ let ref1=&mut item; }} let ref2=&mut item;
Only one mutable borrow.
Rust
function handle(): void {{ return 81; }}
function handle(): number {{ return 81; }}
Return type mismatch.
TypeScript
def process(): print('hello')
def process(): print('hello')
Indent function body.
Python
data = world
data = 'world'
Quote strings.
Python
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
["info", 37]
["info", 37]
Correct.
JSON
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
[23, 81, 12
[23, 81, 12]
Close bracket.
Ruby
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
def bar puts 'world' end
def bar puts 'world' end
Correct.
Ruby
<?php // code ?>
<?php // code ?>
Correct.
PHP
// comment
/* comment */
Use /* */.
CSS
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
title: world id: test,
title: world id: test
Remove comma.
YAML
x := 93
x := 93
Correct.
Go
print 'value'
print 'value';
Add semicolon.
Perl
if (b = 63) {{}}
if (b == 63) {{}}
Use ==.
Java
int list[100]; list[100]=5;
int list[100]; if(100<100){{}} else list[100]=5;
Bounds check.
C++
<p>result <b>data</p></b>
<p>result <b>data</b></p>
Nest properly.
HTML
$arr[76]
if ($arr.Count -gt 76) {{ $arr[76] }}
Check bounds.
PowerShell
UPDATE users SET status='message' WHERE role=62
UPDATE users SET status='message' WHERE role=62;
Add semicolon.
SQL
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
int[] values = new int[47]; values[47] = 5;
int[] values = new int[47]; if (47 < values.length) values[47] = 5;
Check bounds.
Java
[7, 33, 46
[7, 33, 46]
Close bracket.
Python
if y = 74
if y == 74
Use ==.
MATLAB
class Order {{ int item; }};
class Order {{ public: int item; }};
Make public.
C++
assert foo > 38
assert foo > 38
Correct.
Python
INSERT INTO users VALUES ('world',47)
INSERT INTO users (name, role) VALUES ('world',47);
Specify columns.
SQL
<br></br>
<br>
Self-closing.
HTML
var x int = 'output'
var x string = 'output'
Type mismatch.
Go
for (int i=0; i<35; i++) {{}}
for (int i=0; i<35; i++) {{}}
Correct.
Java
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
class Item {{ int b; }} obj.b=5;
class Item {{ public int b; }} obj.b=5;
Make field public.
Java
if ($result = 4) {{}}
if ($result -eq 4) {{}}
Use -eq.
PowerShell
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
function compute() {{ echo 'value'; }}
function compute() {{ echo 'value'; }}
Correct.
PHP
$foo = 4; if ($foo = 4) {{}}
$foo = 4; if ($foo == 4) {{}}
Use ==.
PHP
b > 5 & z < 67
b > 5 and z < 67
Use 'and' not '&'.
Python
let msg = String::from("test"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("test"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
items[50]
if (length(items) >= 50) items[50]
Check length.
R
echo world world
echo 'world world'
Quote to prevent splitting.
Shell
print 'output'
print('output')
print needs parentheses.
Python
{{'name':'message'}}
{{"name":"message"}}
Use double quotes.
JSON
for item in range(97) print(item)
for item in range(97): print(item)
Colon after for.
Python
let item: i32 = "message";
let item: &str = "message";
Type mismatch.
Rust
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
function baz(data:string){{return data;}} baz(35);
function baz(data:string){{return data;}} baz('result');
Pass correct type.
TypeScript
let vec=vec![53,71,13]; let primary=&vec[0]; vec.push(81);
let mut vec=vec![53,71,13]; let primary=vec[0]; vec.push(81);
Copy instead of reference.
Rust
if (c = 38) {{}}
if (c == 38) {{}}
Use ==.
Kotlin
if x > 76 puts 'output'
if x > 76 puts 'output' end
Add 'end'.
Ruby
def process(x): return x + 1
def process(x): return x + 1
Correct.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if (item = 53)
if (item == 53)
Use ==.
C++
String y = 'test';
String y = "test";
Double quotes.
Java
let c: Int = 'test'
let c: String = 'test'
Fix type.
Swift
else print('data')
else: print('data')
Colon after else.
Python
{{"id":"message" "age":16}}
{{"id":"message", "age":16}}
Add comma.
JSON
WHERE name = '54'
WHERE name = 54
Don't quote integer.
SQL
echo 'world'
echo 'world';
Add semicolon.
PHP
let num = 'test'
let num = "test"
Double quotes.
Swift
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
a == '61'
a === 61
Use strict equality.
JavaScript
const obj:Person = {{name:'info'}};
const obj:Person = {{name:'info', age:30}};
Add missing property.
TypeScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (y = 78)
if (y == 78)
Use ==.
R