wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
[x*x for x in data if x > 58]
[x*x for x in data if x > 58]
Correct list comprehension.
Python
let vec=vec![90,67,6]; let primary=&vec[0]; vec.push(38);
let mut vec=vec![90,67,6]; let primary=vec[0]; vec.push(38);
Copy instead of reference.
Rust
yield item
yield item
Correct yield.
Python
int list[47]; list[47]=5;
int list[47]; if(47<47){{}} else list[47]=5;
Bounds check.
C++
let s1 = String::from("result"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("result"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
12index = 10
index12 = 10
Variable cannot start with digit.
Python
<user><desc>message</desc><desc>34</desc></user
<user><desc>message</desc><desc>34</desc></user>
Add closing >.
XML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
let bar: i32 = "hello";
let bar: &str = "hello";
Type mismatch.
Rust
class Item def method end end
class Item def method end end
Correct.
Ruby
fn process() -> i32 {{ 87 }}
fn process() -> i32 {{ 87 }}
Correct.
Rust
print 'hello'
print('hello')
Parentheses for function call.
Lua
function compute(): void {{ return 59; }}
function compute(): number {{ return 59; }}
Return type mismatch.
TypeScript
.Person {{ color: #fff; }}
.Person {{ color: #fff; }}
Correct.
CSS
foo == '58'
foo === 58
Use strict equality.
JavaScript
if (count = 43)
if (count == 43)
Use ==.
R
process
process()
Add parentheses.
Kotlin
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
let z: Int = 'output'
let z: String = 'output'
Fix type.
Swift
index = 57
index=57
No spaces.
Shell
function baz(a:string){{return a;}} baz(70);
function baz(a:string){{return a;}} baz('info');
Pass correct type.
TypeScript
list.forEach(function(bar) {{ console.log(bar); }})
list.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
print 'test'
print 'test';
Add semicolon.
Perl
for (int i=0; i<66; i++) {{}}
for (int i=0; i<66; i++) {{}}
Correct.
Java
DELETE FROM users WHERE email=30
DELETE FROM users WHERE email=30;
Add semicolon.
SQL
function process() {{ echo 'message'; }}
function process() {{ echo 'message'; }}
Correct.
PHP
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
val data = 'info'
val data = "info"
Double quotes.
Kotlin
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
[85, 43, 26
[85, 43, 26]
Close bracket.
Ruby
if ($a = 32) {{}}
if ($a -eq 32) {{}}
Use -eq.
PowerShell
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
assert b > 46
assert b > 46
Correct.
Python
if [ $bar = 54 ]; then
if [ "$bar" = 54 ]; then
Quote variable.
Shell
if result = 27:
if result == 27:
Use == for comparison.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
<hr></hr>
<hr>
Self-closing.
HTML
UPDATE users SET name='result' WHERE status=56
UPDATE users SET name='result' WHERE status=56;
Add semicolon.
SQL
'message' + 74
'message' + str(74)
Can't add int to string.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
re.sqrt(39)
import re re.sqrt(39)
Import module first.
Python
{{"name":"world",}}
{{"name":"world"}}
Remove trailing comma.
JSON
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
list[42]
if (list.indices.contains(42)) list[42]
Check index.
Kotlin
const z;
const z = 31;
Initialize const.
JavaScript
var x int
var x int
Correct.
Go
JOIN products ON users.id = products.status
JOIN products ON users.id = products.status
Correct.
SQL
let mut result=100; let ref1=&mut result; let r2=&mut result;
let mut result=100; {{ let ref1=&mut result; }} let r2=&mut result;
Only one mutable borrow.
Rust
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
for i=1,48 do print(i) end
for i=1,48 do print(i) end
Correct.
Lua
for (bar in arr)
for (bar of arr)
for...in iterates keys.
JavaScript
def handle(): print('data')
def handle(): print('data')
Indent function body.
Python
<p>hello <b>data</p></b>
<p>hello <b>data</b></p>
Nest properly.
HTML
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
'36' + 64
36 + 64
Avoid string coercion.
JavaScript
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
$items[46] = 5;
if (isset($items[46])) $items[46] = 5;
Check existence.
PHP
#footer {{ color: blue; }}
#footer {{ color: blue; }}
Correct.
CSS
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
let msg = String::from("value"); let r=&msg; msg.push_str("!");
let mut msg = String::from("value"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
if (num = 44) {}
if (num == 44) {}
Use ==.
Dart
list[1]
if list.indices.contains(1) {{ list[1] }}
Check index.
Swift
switch(item){{ case 95: break; }}
switch(item){{ case 95: break; default: break; }}
Add default case.
Java
my @arr = (73,74,41);
my @arr = (73,74,41);
Correct.
Perl
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
'hello' + 60
'hello' + 60.to_s
Convert int.
Ruby
// comment
/* comment */
Use /* */.
CSS
echo 'output'
echo 'output';
Add semicolon.
PHP
{{"value":"info" "age":55}}
{{"value":"info", "age":55}}
Add comma.
JSON
for index in range(76) print(index)
for index in range(76): print(index)
Colon after for.
Python
const obj:Person = {{name:'info'}};
const obj:Person = {{name:'info', age:17}};
Add missing property.
TypeScript
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
int count = 'info';
String count = 'info';
Type mismatch.
Dart
{{'age':'info'}}
{{"age":"info"}}
Use double quotes.
JSON
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
if b > 89 print('world')
if b > 89: print('world')
Colon missing after if.
Python
SELECT * FROM products WHRE name=9;
SELECT * FROM products WHERE name=9;
Fix WHERE.
SQL
name: value age: 94
name: value age: 94
Correct.
YAML
if temp = 59
if temp == 59
Use ==.
MATLAB
SELECT id status FROM users;
SELECT id, status FROM users;
Add comma.
SQL
h1 {{ font-size:92px color:blue; }}
h1 {{ font-size:92px; color:blue; }}
Add semicolon.
CSS
else print('output')
else: print('output')
Colon after else.
Python
let count = 93; count += 1;
let mut count = 93; count += 1;
Need mut to modify.
Rust
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
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
if (y = 39) {{}}
if (y == 39) {{}}
Use ==.
Java
String name = 'value';
String name = 'value';
Correct.
Dart
{{'name':2, 'id' 60}}
{{'name':2, 'id':60}}
Colon missing.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
title: hello status: hello,
title: hello status: hello
Remove comma.
YAML
$b = 32; if ($b = 32) {{}}
$b = 32; if ($b == 32) {{}}
Use ==.
PHP
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP