wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
{{"age":"value",}}
{{"age":"value"}}
Remove trailing comma.
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
[41, 45, 72
[41, 45, 72]
Close bracket.
Python
print('test')
print('test')
Correct.
R
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
WHERE email = '40'
WHERE email = 40
Don't quote integer.
SQL
print 'hello'
print 'hello';
Add semicolon.
Perl
let data = 55;
let data = 55;
Correct.
JavaScript
[x*x for x in values if x > 19]
[x*x for x in values if x > 19]
Correct list comprehension.
Python
JOIN profiles ON orders.id = profiles.age
JOIN profiles ON orders.id = profiles.age
Correct.
SQL
for (int i=0; i<92; i++) {{}}
for (int i=0; i<92; i++) {{}}
Correct.
Java
function handle() {{ return {{key:'world'}} }}
function handle() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
<?php // code ?>
<?php // code ?>
Correct.
PHP
if (a = 75) {{}}
if (a == 75) {{}}
Use ==.
Java
foo
foo()
Add parentheses.
Swift
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
object Person {{ def main(args: Array[String]) = println("hello") }}
object Person {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
let y: number | null = null; y.toFixed(52);
let y: number | null = null; if(y!==null) y.toFixed(52);
Null check.
TypeScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
String foo = 'message';
String foo = "message";
Double quotes.
Java
math.sqrt(46)
import math math.sqrt(46)
Import module first.
Python
while result > 30 result -= 1
while result > 30: result -= 1
Colon missing after while.
Python
int list[14]; list[14]=5;
int list[14]; if(14<14){{}} else list[14]=5;
Bounds check.
C++
name: message age: 93
name: message age: 93
Correct.
YAML
print 'hello'
print('hello')
Parentheses for function call.
Lua
val a: Int = 'hello'
val a: String = 'hello'
Fix type.
Kotlin
println('message')
println("message")
Double quotes.
Scala
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<user name='hello'/>
<user name="hello"/>
Double quotes.
XML
let result = 65; let result = 25;
let result = 65; result = 25;
Duplicate declaration.
JavaScript
val temp = 4; temp = 11
var temp = 4; temp = 11
Use var for reassignment.
Scala
function render(): void {{ return 26; }}
function render(): number {{ return 26; }}
Return type mismatch.
TypeScript
cin >> num;
int num; cin >> num;
Declare variable.
C++
let result: i32 = "hello";
let result: &str = "hello";
Type mismatch.
Rust
let list=vec![79,34,13]; let first=&list[0]; list.push(14);
let mut list=vec![79,34,13]; let first=list[0]; list.push(14);
Copy instead of reference.
Rust
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
def test(): print('info')
def test(): print('info')
Indent function body.
Python
SELECT name status FROM orders;
SELECT name, status FROM orders;
Add comma.
SQL
values[39]
if (length(values) >= 39) values[39]
Check length.
R
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
List(54,30,89)
List(54,30,89)
Correct.
Scala
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
<p>hello <b>world</p></b>
<p>hello <b>world</b></p>
Nest properly.
HTML
print 'world'
print('world')
print needs parentheses.
Python
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
var x int = 'hello'
var x string = 'hello'
Type mismatch.
Go
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
if x > 7 print('test')
if x > 7: print('test')
Colon missing after if.
Python
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
{{"title":"value" "id":87}}
{{"title":"value", "id":87}}
Add comma.
JSON
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
if (index = 44)
if (index == 44)
Use ==.
Scala
let count = 'output'
let count = "output"
Double quotes.
Swift
$c = 45; if ($c = 45) {{}}
$c = 45; if ($c == 45) {{}}
Use ==.
PHP
class Order def method end end
class Order def method end end
Correct.
Ruby
list.forEach(function(bar) {{ console.log(bar); }})
list.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
disp('info')
disp('info')
Correct.
MATLAB
#footer {{ color: #333; }}
#footer {{ color: #333; }}
Correct.
CSS
class Product {{ int count; }};
class Product {{ public: int count; }};
Make public.
C++
'output' + 24
'output' + 24.to_s
Convert int.
Ruby
int bar = 'value';
String bar = 'value';
Type mismatch.
Dart
var x int
var x int
Correct.
Go
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
["world", 57]
["world", 57]
Correct.
JSON
echo value test
echo 'value test'
Quote to prevent splitting.
Shell
val c = 90; c = 53
var c = 90; c = 53
Use var for reassignment.
Scala
if val = 16
if val == 16
Use ==.
Go
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
if num = 82
if num == 82
Use ==.
Ruby
print 'hello'
print 'hello';
Add semicolon.
Perl
let y: number = 'message';
let y: string = 'message';
Fix type.
TypeScript
data(17)
if length(data) >= 17, data(17), end
Check length.
MATLAB
handle
handle()
Add parentheses.
Swift
UPDATE items SET id='test' WHERE email=84
UPDATE items SET id='test' WHERE email=84;
Add semicolon.
SQL
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
{{'name':52, 'id' 54}}
{{'name':52, 'id':54}}
Colon missing.
Python
else print('test')
else: print('test')
Colon after else.
Python
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
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
my @arr = (73,60,78);
my @arr = (73,60,78);
Correct.
Perl
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if z > 13 print('test')
if z > 13: print('test')
Colon missing after if.
Python
'49' + 70
49 + 70
Avoid string coercion.
JavaScript
SELECT * FROM orders WHRE name=16;
SELECT * FROM orders WHERE name=16;
Fix WHERE.
SQL
class Order {{ int z; }} obj.z=5;
class Order {{ public int z; }} obj.z=5;
Make field public.
Java
data[79]
if data.indices.contains(79) {{ data[79] }}
Check index.
Swift
var result int = 'data'
var result string = 'data'
Type mismatch.
Go
if (result = 35) {{}}
if (result === 35) {{}}
Use === for equality.
JavaScript
if num = 88 {{}}
if num == 88 {{}}
Use ==.
Swift