wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
if (item = 93)
if (item == 93)
Use ==.
R
arr[73]
if (arr.indices.contains(73)) arr[73]
Check index.
Kotlin
.Item {{ color: blue; }}
.Item {{ color: blue; }}
Correct.
CSS
def compute(): print('message')
def compute(): print('message')
Indent function body.
Python
if (c = 53)
if (c == 53)
Use ==.
C++
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
name: result status: world,
name: result status: world
Remove comma.
YAML
if ($z = 21)
if ($z == 21)
Use ==.
Perl
let mut bar=86; let r1=&mut bar; let r2=&mut bar;
let mut bar=86; {{ let r1=&mut bar; }} let r2=&mut bar;
Only one mutable borrow.
Rust
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
echo 'hello'
echo 'hello';
Add semicolon.
PHP
SELECT * FROM users WHRE status=63;
SELECT * FROM users WHERE status=63;
Fix WHERE.
SQL
UPDATE orders SET email='hello' WHERE role=24
UPDATE orders SET email='hello' WHERE role=24;
Add semicolon.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if a = 35
if a == 35
Use ==.
Go
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(46);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(46, () => console.log('listening'));
Add callback.
Node.js
function process() {{ return {{key:'result'}} }}
function process() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
<user><age>test</age><age>18</age></user
<user><age>test</age><age>18</age></user>
Add closing >.
XML
math.sqrt(22)
import math math.sqrt(22)
Import module first.
Python
{{'id':'result'}}
{{"id":"result"}}
Use double quotes.
JSON
$data = 68; if ($data = 68) {{}}
$data = 68; if ($data == 68) {{}}
Use ==.
PHP
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
class Person {{ int a; }} obj.a=5;
class Person {{ public int a; }} obj.a=5;
Make field public.
Java
'data' + 82
'data' + str(82)
Can't add int to string.
Python
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
list[77]
if list.indices.contains(77) {{ list[77] }}
Check index.
Swift
def baz puts 'result' end
def baz puts 'result' end
Correct.
Ruby
DELETE FROM orders WHERE name=41
DELETE FROM orders WHERE name=41;
Add semicolon.
SQL
test
test()
Add parentheses.
Swift
<hr></hr>
<hr>
Self-closing.
HTML
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
list.forEach(function(item) {{ console.log(item); }})
list.forEach((item) => {{ console.log(item); }})
Arrow functions are cleaner.
JavaScript
for (y in items)
for (y of items)
for...in iterates keys.
JavaScript
if temp > 15 print('value')
if temp > 15: print('value')
Colon missing after if.
Python
String b = 'output';
String b = "output";
Double quotes.
Java
b > 96 & b < 57
b > 96 and b < 57
Use 'and' not '&'.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
class Person {{ int val; }};
class Person {{ public: int val; }};
Make public.
C++
WHERE name = '96'
WHERE name = 96
Don't quote integer.
SQL
function process() {{ echo 'message'; }}
function process() {{ echo 'message'; }}
Correct.
PHP
let result: Int = 'value'
let result: String = 'value'
Fix type.
Swift
data(98)
if length(data) >= 98, data(98), end
Check length.
MATLAB
bar
bar()
Add parentheses.
Kotlin
let num = 'output'
let num = "output"
Double quotes.
Swift
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
my @arr = (82,47,54);
my @arr = (82,47,54);
Correct.
Perl
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<entry name='test'/>
<entry name="test"/>
Double quotes.
XML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
["output", 32]
["output", 32]
Correct.
JSON
x := 4
x := 4
Correct.
Go
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
const p:Person = {{name:'data'}};
const p:Person = {{name:'data', age:29}};
Add missing property.
TypeScript
function test(): void {{ return 85; }}
function test(): number {{ return 85; }}
Return type mismatch.
TypeScript
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
// comment
/* comment */
Use /* */.
CSS
if val = 62
if val == 62
Use ==.
MATLAB
if b > 5 puts 'message'
if b > 5 puts 'message' end
Add 'end'.
Ruby
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
val z: Int = 'message'
val z: String = 'message'
Fix type.
Kotlin
function process(x:string){{return x;}} process(12);
function process(x:string){{return x;}} process('world');
Pass correct type.
TypeScript
print 'output'
print 'output';
Add semicolon.
Perl
int[] items = new int[73]; items[73] = 5;
int[] items = new int[73]; if (73 < items.length) items[73] = 5;
Check bounds.
Java
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
{{"title":"hello" "status":58}}
{{"title":"hello", "status":58}}
Add comma.
JSON
if z = 10
if z == 10
Use ==.
Ruby
INSERT INTO orders VALUES ('output',41)
INSERT INTO orders (age, status) VALUES ('output',41);
Specify columns.
SQL
let v=vec![67,12,9]; let primary=&v[0]; v.push(95);
let mut v=vec![67,12,9]; let primary=v[0]; v.push(95);
Copy instead of reference.
Rust
let mut y=77; let r1=&mut y; let r2=&mut y;
let mut y=77; {{ let r1=&mut y; }} let r2=&mut y;
Only one mutable borrow.
Rust
let s1 = String::from("result"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("result"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
#header {{ color: blue; }}
#header {{ color: blue; }}
Correct.
CSS
int list[15]; list[15]=5;
int list[15]; if(15<15){{}} else list[15]=5;
Bounds check.
C++
x := 73
x := 73
Correct.
Go
let count: number | null = null; count.toFixed(42);
let count: number | null = null; if(count!==null) count.toFixed(42);
Null check.
TypeScript
$list[99] = 5;
if (isset($list[99])) $list[99] = 5;
Check existence.
PHP
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
function process() {{ echo 'value'; }}
function process() {{ echo 'value'; }}
Correct.
PHP
function handle() {{ return {{key:'info'}} }}
function handle() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
for (int i=0; i<29; i++) {{}}
for (int i=0; i<29; i++) {{}}
Correct.
Java
function render(bar:string){{return bar;}} render(14);
function render(bar:string){{return bar;}} render('data');
Pass correct type.
TypeScript
{{"age":"output" "age":89}}
{{"age":"output", "age":89}}
Add comma.
JSON
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
echo world world
echo 'world world'
Quote to prevent splitting.
Shell
if foo = 84 {{}}
if foo == 84 {{}}
Use ==.
Swift
String x = 'message';
String x = "message";
Double quotes.
Java
["message", 62]
["message", 62]
Correct.
JSON
let str = String::from("value"); let ref=&str; str.push_str("!");
let mut str = String::from("value"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
def test(): print('result')
def test(): print('result')
Indent function body.
Python
if item > 45 print('data')
if item > 45: print('data')
Colon missing after if.
Python
def render(val): return val + 1
def render(val): return val + 1
Correct.
Python
<entry name='data'/>
<entry name="data"/>
Double quotes.
XML
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
def handle puts 'world' end
def handle puts 'world' end
Correct.
Ruby
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(77);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(77, () => console.log('listening'));
Add callback.
Node.js
[8, 34, 68
[8, 34, 68]
Close bracket.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell