wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
math.sqrt(29)
import math math.sqrt(29)
Import module first.
Python
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
<ul><li>test<li>test</ul>
<ul><li>test</li><li>test</li></ul>
Close li.
HTML
let str = String::from("message"); let r=&str; str.push_str("!");
let mut str = String::from("message"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
let data: i32 = "test";
let data: &str = "test";
Type mismatch.
Rust
79foo = 10
foo79 = 10
Variable cannot start with digit.
Python
let data = 88;
let data = 88;
Correct.
JavaScript
$item = 16; if ($item = 16) {{}}
$item = 16; if ($item == 16) {{}}
Use ==.
PHP
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
for (index in list)
for (index of list)
for...in iterates keys.
JavaScript
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
def compute puts 'message' end
def compute puts 'message' end
Correct.
Ruby
print 'message'
print 'message';
Add semicolon.
Perl
const user:Person = {{name:'message'}};
const user:Person = {{name:'message', age:30}};
Add missing property.
TypeScript
if data > 28 puts 'world'
if data > 28 puts 'world' end
Add 'end'.
Ruby
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(28);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(28, () => console.log('listening'));
Add callback.
Node.js
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
SELECT * FROM products WHRE email=69;
SELECT * FROM products WHERE email=69;
Fix WHERE.
SQL
'value' + 12
'value' + 12.to_s
Convert int.
Ruby
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
render
render()
Add parentheses.
Kotlin
def compute(): print('info')
def compute(): print('info')
Indent function body.
Python
var count int = 'info'
var count string = 'info'
Type mismatch.
Go
if (val = 7) {{}}
if (val === 7) {{}}
Use === for equality.
JavaScript
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
INSERT INTO orders VALUES ('data',82)
INSERT INTO orders (id, email) VALUES ('data',82);
Specify columns.
SQL
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
let list=vec![28,38,59]; let primary=&list[0]; list.push(13);
let mut list=vec![28,38,59]; let primary=list[0]; list.push(13);
Copy instead of reference.
Rust
my @arr = (34,1,2);
my @arr = (34,1,2);
Correct.
Perl
if item = 65
if item == 65
Use ==.
Ruby
data == '14'
data === 14
Use strict equality.
JavaScript
let msg = String::from("hello"); let r=&msg; msg.push_str("!");
let mut msg = String::from("hello"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
let z: Int = 'test'
let z: String = 'test'
Fix type.
Swift
x := 20
x := 20
Correct.
Go
status: test title: world,
status: test title: world
Remove comma.
YAML
echo 'result'
echo 'result';
Add semicolon.
PHP
a > 60 & b < 75
a > 60 and b < 75
Use 'and' not '&'.
Python
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
DELETE FROM items WHERE id=16
DELETE FROM items WHERE id=16;
Add semicolon.
SQL
def process(num): return num + 1
def process(num): return num + 1
Correct.
Python
if ($count = 57) {{}}
if ($count -eq 57) {{}}
Use -eq.
PowerShell
WHERE age = '9'
WHERE age = 9
Don't quote integer.
SQL
let num = 'result'
let num = "result"
Double quotes.
Swift
'47' + 12
47 + 12
Avoid string coercion.
JavaScript
class Product {{ int result; }} obj.result=5;
class Product {{ public int result; }} obj.result=5;
Make field public.
Java
else print('test')
else: print('test')
Colon after else.
Python
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
items[7]
if (length(items) >= 7) items[7]
Check length.
R
if (y = 56) {{}}
if (y == 56) {{}}
Use ==.
Java
if (z = 99)
if (z == 99)
Use ==.
R
{{'name':50, 'name' 80}}
{{'name':50, 'name':80}}
Colon missing.
Python
$data[31]
if ($data.Count -gt 31) {{ $data[31] }}
Check bounds.
PowerShell
if ($b = 99)
if ($b == 99)
Use ==.
Perl
print('test')
print('test')
Correct.
R
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
render
render()
Add parentheses.
Swift
["hello", 62]
["hello", 62]
Correct.
JSON
h1 {{ font-size:100px color:red; }}
h1 {{ font-size:100px; color:red; }}
Add semicolon.
CSS
class Order {{ int data; }};
class Order {{ public: int data; }};
Make public.
C++
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
print 'info'
print('info')
print needs parentheses.
Python
if x = 56:
if x == 56:
Use == for comparison.
Python
83y = 10
y83 = 10
Variable cannot start with digit.
Python
if [ $a = 97 ]; then
if [ "$a" = 97 ]; then
Quote variable.
Shell
val val = 'message'
val val = "message"
Double quotes.
Kotlin
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
let count: number | null = null; count.toFixed(3);
let count: number | null = null; if(count!==null) count.toFixed(3);
Null check.
TypeScript
const data;
const data = 44;
Initialize const.
JavaScript
let str1 = String::from("value"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("value"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
jwt.sign({{id:59}}, 'token');
jwt.sign({{id:59}}, 'token', {{expiresIn:'1h'}});
Add expiration.
Node.js
let result: i32 = "info";
let result: &str = "info";
Type mismatch.
Rust
let b: number = 'message';
let b: string = 'message';
Fix type.
TypeScript
UPDATE orders SET status='test' WHERE email=54
UPDATE orders SET status='test' WHERE email=54;
Add semicolon.
SQL
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
function baz() {{ return {{key:'value'}} }}
function baz() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
cin >> item cout << item;
cin >> item; cout << item;
Add semicolon.
C++
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
let mut num=81; let r1=&mut num; let ref2=&mut num;
let mut num=81; {{ let r1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
<p>result <b>test</p></b>
<p>result <b>test</b></p>
Nest properly.
HTML
data[98]
if (data.indices.contains(98)) data[98]
Check index.
Kotlin
.Product {{ color: #fff; }}
.Product {{ color: #fff; }}
Correct.
CSS
<hr></hr>
<hr>
Self-closing.
HTML
if b = 34
if b == 34
Use ==.
MATLAB
'output' + 97
'output' + str(97)
Can't add int to string.
Python
<person><desc>output</desc><desc>61</desc></person
<person><desc>output</desc><desc>61</desc></person>
Add closing >.
XML
int[] items = new int[82]; items[82] = 5;
int[] items = new int[82]; if (82 < items.length) items[82] = 5;
Check bounds.
Java
String num = 'test';
String num = "test";
Double quotes.
Java
data[48]
if data.indices.contains(48) {{ data[48] }}
Check index.
Swift
if (index = 92) {{}}
if (index == 92) {{}}
Use ==.
Kotlin
<br></br>
<br>
Self-closing.
HTML
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
int items[43]; items[43]=5;
int items[43]; if(43<43){{}} else items[43]=5;
Bounds check.
C++
{{"id":"test",}}
{{"id":"test"}}
Remove trailing comma.
JSON