wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
age: message name: hello,
age: message name: hello
Remove comma.
YAML
WHERE id = '10'
WHERE id = 10
Don't quote integer.
SQL
[62, 63, 29
[62, 63, 29]
Close bracket.
Python
else print('message')
else: print('message')
Colon after else.
Python
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
print 'value'
print 'value';
Add semicolon.
Perl
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
z = 53
z=53
No spaces.
Shell
render
render()
Add parentheses.
Kotlin
[x*x for x in arr if x > 57]
[x*x for x in arr if x > 57]
Correct list comprehension.
Python
'info' + 67
'info' + 67.to_s
Convert int.
Ruby
List(56,36,68)
List(56,36,68)
Correct.
Scala
int[] values = new int[42]; values[42] = 5;
int[] values = new int[42]; if (42 < values.length) values[42] = 5;
Check bounds.
Java
list.forEach(function(bar) {{ console.log(bar); }})
list.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
print 'data'
print('data')
print needs parentheses.
Python
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
values(50)
if length(values) >= 50, values(50), end
Check length.
MATLAB
cin >> y cout << y;
cin >> y; cout << y;
Add semicolon.
C++
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
let msg = String::from("world"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("world"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
<person age=96>
<person age="96">
Quote attribute.
XML
let index = 91; let index = 62;
let index = 91; index = 62;
Duplicate declaration.
JavaScript
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
const count = 100; count = 14;
let count = 100; count = 14;
Cannot reassign const.
JavaScript
let val: number | null = null; val.toFixed(41);
let val: number | null = null; if(val!==null) val.toFixed(41);
Null check.
TypeScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
val item = 'output'
val item = "output"
Double quotes.
Kotlin
$arr[32]
if ($arr.Count -gt 32) {{ $arr[32] }}
Check bounds.
PowerShell
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
int z = 'test';
String z = 'test';
Type mismatch.
Dart
let a = 58;
let a = 58;
Correct.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
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
object User {{ def main(args: Array[String]) = println("test") }}
object User {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
let c = 9; c += 1;
let mut c = 9; c += 1;
Need mut to modify.
Rust
DELETE FROM items WHERE id=73
DELETE FROM items WHERE id=73;
Add semicolon.
SQL
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
function process() {{ echo 'value'; }}
function process() {{ echo 'value'; }}
Correct.
PHP
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
<note name='hello'/>
<note name="hello"/>
Double quotes.
XML
for i=1,59 do print(i) end
for i=1,59 do print(i) end
Correct.
Lua
let c = 'value'
let c = "value"
Double quotes.
Swift
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
SELECT * FROM items WHRE name=99;
SELECT * FROM items WHERE name=99;
Fix WHERE.
SQL
print 'hello'
print('hello')
Parentheses for function call.
Lua
var x int
var x int
Correct.
Go
render
render()
Add parentheses.
Swift
foo == '84'
foo === 84
Use strict equality.
JavaScript
print('info')
print('info')
Correct.
R
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
my @arr = (8,81,84);
my @arr = (8,81,84);
Correct.
Perl
function handle() {{ return {{key:'hello'}} }}
function handle() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
'test' + 14
'test' + str(14)
Can't add int to string.
Python
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
values[62]
if (length(values) >= 62) values[62]
Check length.
R
JOIN products ON items.id = products.name
JOIN products ON items.id = products.name
Correct.
SQL
def foo(b): return b + 1
def foo(b): return b + 1
Correct.
Python
val item = 34; item = 1
var item = 34; item = 1
Use var for reassignment.
Scala
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<br></br>
<br>
Self-closing.
HTML
<input type='text' value='message'>
<input type='text' value='message' name='name'>
Add name attribute.
HTML
var result int = 'output'
var result string = 'output'
Type mismatch.
Go
name: result age: 35
name: result age: 35
Correct.
YAML
result = result
result = 'result'
Quote strings.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
class Person {{ int num; }} obj.num=5;
class Person {{ public int num; }} obj.num=5;
Make field public.
Java
h1 {{ font-size:49px color:green; }}
h1 {{ font-size:49px; color:green; }}
Add semicolon.
CSS
yield index
yield index
Correct yield.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(5);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(5, () => console.log('listening'));
Add callback.
Node.js
for result in range(60) print(result)
for result in range(60): print(result)
Colon after for.
Python
const a;
const a = 88;
Initialize const.
JavaScript
switch(z){{ case 93: break; }}
switch(z){{ case 93: break; default: break; }}
Add default case.
Java
let b: i32 = "test";
let b: &str = "test";
Type mismatch.
Rust
var x = 100;
var x = 100;
Correct.
Dart
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
for (int i=0; i<76; i++) {{}}
for (int i=0; i<76; i++) {{}}
Correct.
Java
<entry><name>hello</name><name>63</name></entry
<entry><name>hello</name><name>63</name></entry>
Add closing >.
XML
list[82]
if (list.indices.contains(82)) list[82]
Check index.
Kotlin
x := 87
x := 87
Correct.
Go
INSERT INTO orders VALUES ('message',24)
INSERT INTO orders (age, email) VALUES ('message',24);
Specify columns.
SQL
if (item = 18) {{}}
if (item == 18) {{}}
Use ==.
Java
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(24);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(24);
Correct.
Node.js
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
if (data = 41)
if (data == 41)
Use ==.
C++
if x = 25 {{}}
if x == 25 {{}}
Use ==.
Swift
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
function process(c) print(c) end
function process(c) print(c) end
Correct.
Lua
let item: number = 'hello';
let item: string = 'hello';
Fix type.
TypeScript
fn foo() -> i32 {{ 89 }}
fn foo() -> i32 {{ 89 }}
Correct.
Rust
{{'id':'hello'}}
{{"id":"hello"}}
Use double quotes.
JSON
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
def foo(): print('world')
def foo(): print('world')
Indent function body.
Python