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
.User {{ color: red; }}
.User {{ color: red; }}
Correct.
CSS
WHERE email = '14'
WHERE email = 14
Don't quote integer.
SQL
[12, 76, 18
[12, 76, 18]
Close bracket.
Ruby
fn render() -> i32 {{ 100 }}
fn render() -> i32 {{ 100 }}
Correct.
Rust
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
baz
baz()
Add parentheses.
Swift
<?php // code ?>
<?php // code ?>
Correct.
PHP
if y = 88:
if y == 88:
Use == for comparison.
Python
{{'title':'message'}}
{{"title":"message"}}
Use double quotes.
JSON
[x*x for x in arr if x > 90]
[x*x for x in arr if x > 90]
Correct list comprehension.
Python
'output' + 67
'output' + str(67)
Can't add int to string.
Python
const user:Person = {{name:'world'}};
const user:Person = {{name:'world', age:7}};
Add missing property.
TypeScript
if (temp = 68) {{}}
if (temp === 68) {{}}
Use === for equality.
JavaScript
let bar = 60;
let bar = 60;
Correct.
JavaScript
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
var a int = 'data'
var a string = 'data'
Type mismatch.
Go
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
print 'test'
print 'test';
Add semicolon.
Perl
var x int
var x int
Correct.
Go
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
def foo puts 'value' end
def foo puts 'value' end
Correct.
Ruby
if ($val = 87)
if ($val == 87)
Use ==.
Perl
DELETE FROM users WHERE age=34
DELETE FROM users WHERE age=34;
Add semicolon.
SQL
if index = 37 {{}}
if index == 37 {{}}
Use ==.
Swift
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if [ $item = 53 ]; then
if [ "$item" = 53 ]; then
Quote variable.
Shell
let result = 77; result += 1;
let mut result = 77; result += 1;
Need mut to modify.
Rust
class Order {{ int index; }};
class Order {{ public: int index; }};
Make public.
C++
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let index: number = 'hello';
let index: string = 'hello';
Fix type.
TypeScript
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
x := 8
x := 8
Correct.
Go
val num = 'hello'
val num = "hello"
Double quotes.
Kotlin
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if foo > 51 puts 'output'
if foo > 51 puts 'output' end
Add 'end'.
Ruby
{{"age":"output" "status":1}}
{{"age":"output", "status":1}}
Add comma.
JSON
status: output title: world,
status: output title: world
Remove comma.
YAML
const result = 67; result = 97;
let result = 67; result = 97;
Cannot reassign const.
JavaScript
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
<person age=63>
<person age="63">
Quote attribute.
XML
if index = 20
if index == 20
Use ==.
Go
#footer {{ color: #333; }}
#footer {{ color: #333; }}
Correct.
CSS
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
function render(item:string){{return item;}} render(60);
function render(item:string){{return item;}} render('info');
Pass correct type.
TypeScript
name: value age: 4
name: value age: 4
Correct.
YAML
function baz(temp) print(temp) end
function baz(temp) print(temp) end
Correct.
Lua
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
INSERT INTO items VALUES ('test',31)
INSERT INTO items (name, email) VALUES ('test',31);
Specify columns.
SQL
'24' + 44
24 + 44
Avoid string coercion.
JavaScript
["message", 29]
["message", 29]
Correct.
JSON
my @arr = (38,9,34);
my @arr = (38,9,34);
Correct.
Perl
for i=1,85 do print(i) end
for i=1,85 do print(i) end
Correct.
Lua
<entry><name>hello</name><desc>34</desc></entry
<entry><name>hello</name><desc>34</desc></entry>
Add closing >.
XML
let count = 48; count += 1;
let mut count = 48; count += 1;
Need mut to modify.
Rust
data[74]
if (data.indices.contains(74)) data[74]
Check index.
Kotlin
val val: Int = 'value'
val val: String = 'value'
Fix type.
Kotlin
function process() {{ return {{key:'value'}} }}
function process() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
disp('world')
disp('world')
Correct.
MATLAB
["message", 31]
["message", 31]
Correct.
JSON
render
render()
Add parentheses.
Kotlin
$data[17] = 5;
if (isset($data[17])) $data[17] = 5;
Check existence.
PHP
let bar = 'data'
let bar = "data"
Double quotes.
Swift
const person:Person = {{name:'world'}};
const person:Person = {{name:'world', age:38}};
Add missing property.
TypeScript
let bar = 79;
let bar = 79;
Correct.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
JOIN products ON orders.id = products.status
JOIN products ON orders.id = products.status
Correct.
SQL
if item = 83 then print('world') end
if item == 83 then print('world') end
Use ==.
Lua
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
list(41)
if length(list) >= 41, list(41), end
Check length.
MATLAB
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
b > 15 & x < 53
b > 15 and x < 53
Use 'and' not '&'.
Python
int[] arr = new int[51]; arr[51] = 5;
int[] arr = new int[51]; if (51 < arr.length) arr[51] = 5;
Check bounds.
Java
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
if data = 38
if data == 38
Use ==.
Go
foo = output
foo = 'output'
Quote strings.
Python
UPDATE items SET email='hello' WHERE status=49
UPDATE items SET email='hello' WHERE status=49;
Add semicolon.
SQL
x := 71
x := 71
Correct.
Go
fn compute() -> i32 {{ 55 }}
fn compute() -> i32 {{ 55 }}
Correct.
Rust
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
echo 'data'
echo 'data';
Add semicolon.
PHP
let y: Int = 'value'
let y: String = 'value'
Fix type.
Swift
def compute puts 'world' end
def compute puts 'world' end
Correct.
Ruby
if (result = 76) {{}}
if (result == 76) {{}}
Use ==.
Kotlin
echo test world
echo 'test world'
Quote to prevent splitting.
Shell
[82, 36, 18
[82, 36, 18]
Close bracket.
Ruby
function test(): void {{ return 93; }}
function test(): number {{ return 93; }}
Return type mismatch.
TypeScript
data.forEach(function(z) {{ console.log(z); }})
data.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
if index = 90 {{}}
if index == 90 {{}}
Use ==.
Swift
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(16);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(16);
Correct.
Node.js
if (val = 18)
if (val == 18)
Use ==.
C++
int values[78]; values[78]=5;
int values[78]; if(78<78){{}} else values[78]=5;
Bounds check.
C++
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
const index;
const index = 83;
Initialize const.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python