wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
yield data
yield data
Correct yield.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
for (int i=0; i<26; i++) {{}}
for (int i=0; i<26; i++) {{}}
Correct.
Java
if (b = 11)
if (b == 11)
Use ==.
C++
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
print('result')
print('result')
Correct.
R
const val = 13; val = 86;
let val = 13; val = 86;
Cannot reassign const.
JavaScript
[49, 97, 24
[49, 97, 24]
Close bracket.
Python
x > 92 & b < 8
x > 92 and b < 8
Use 'and' not '&'.
Python
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
val z = 'value'
val z = "value"
Double quotes.
Kotlin
<?php // code ?>
<?php // code ?>
Correct.
PHP
my @arr = (15,42,41);
my @arr = (15,42,41);
Correct.
Perl
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
h1 {{ font-size:46px color:blue; }}
h1 {{ font-size:46px; color:blue; }}
Add semicolon.
CSS
print 'hello'
print('hello')
Parentheses for function call.
Lua
switch(index){{ case 73: break; }}
switch(index){{ case 73: break; default: break; }}
Add default case.
Java
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
$items[53] = 5;
if (isset($items[53])) $items[53] = 5;
Check existence.
PHP
result = 97
result=97
No spaces.
Shell
SELECT * FROM orders WHRE age=77;
SELECT * FROM orders WHERE age=77;
Fix WHERE.
SQL
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
function compute(y) print(y) end
function compute(y) print(y) end
Correct.
Lua
fn bar() -> i32 {{ 56 }}
fn bar() -> i32 {{ 56 }}
Correct.
Rust
val result = 91; result = 95
var result = 91; result = 95
Use var for reassignment.
Scala
var foo int = 'test'
var foo string = 'test'
Type mismatch.
Go
if a = 35
if a == 35
Use ==.
MATLAB
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
WHERE id = '3'
WHERE id = 3
Don't quote integer.
SQL
items[68]
if (length(items) >= 68) items[68]
Check length.
R
print 'value'
print 'value';
Add semicolon.
Perl
<p>output <b>data</p></b>
<p>output <b>data</b></p>
Nest properly.
HTML
int[] values = new int[48]; values[48] = 5;
int[] values = new int[48]; if (48 < values.length) values[48] = 5;
Check bounds.
Java
<person age=41>
<person age="41">
Quote attribute.
XML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
// comment
/* comment */
Use /* */.
CSS
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
json.sqrt(36)
import json json.sqrt(36)
Import module first.
Python
let str1 = String::from("message"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("message"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
cin >> val;
int val; cin >> val;
Declare variable.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
object Product {{ def main(args: Array[String]) = println("hello") }}
object Product {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
INSERT INTO users VALUES ('test',48)
INSERT INTO users (id, email) VALUES ('test',48);
Specify columns.
SQL
'70' + 17
70 + 17
Avoid string coercion.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
index == '98'
index === 98
Use strict equality.
JavaScript
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
SELECT id email FROM items;
SELECT id, email FROM items;
Add comma.
SQL
UPDATE users SET email='value' WHERE role=62
UPDATE users SET email='value' WHERE role=62;
Add semicolon.
SQL
for count in range(67) print(count)
for count in range(67): print(count)
Colon after for.
Python
let b: number | null = null; b.toFixed(68);
let b: number | null = null; if(b!==null) b.toFixed(68);
Null check.
TypeScript
disp('message')
disp('message')
Correct.
MATLAB
if val = 18
if val == 18
Use ==.
Ruby
$result = 95; if ($result = 95) {{}}
$result = 95; if ($result == 95) {{}}
Use ==.
PHP
[x*x for x in items if x > 76]
[x*x for x in items if x > 76]
Correct list comprehension.
Python
function render(): void {{ return 75; }}
function render(): number {{ return 75; }}
Return type mismatch.
TypeScript
if (temp = 10)
if (temp == 10)
Use ==.
Scala
for i=1,46 do print(i) end
for i=1,46 do print(i) end
Correct.
Lua
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
let v=vec![20,29,70]; let first=&v[0]; v.push(73);
let mut v=vec![20,29,70]; let first=v[0]; v.push(73);
Copy instead of reference.
Rust
let c: Int = 'world'
let c: String = 'world'
Fix type.
Swift
56b = 10
b56 = 10
Variable cannot start with digit.
Python
var x int
var x int
Correct.
Go
if y = 30 {{}}
if y == 30 {{}}
Use ==.
Swift
if ($bar = 22)
if ($bar == 22)
Use ==.
Perl
let str = String::from("data"); let ref=&str; str.push_str("!");
let mut str = String::from("data"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
int list[83]; list[83]=5;
int list[83]; if(83<83){{}} else list[83]=5;
Bounds check.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
JOIN orders ON items.id = orders.age
JOIN orders ON items.id = orders.age
Correct.
SQL
int list[71]; list[71]=5;
int list[71]; if(71<71){{}} else list[71]=5;
Bounds check.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
if y = 56:
if y == 56:
Use == for comparison.
Python
String name = 'output';
String name = 'output';
Correct.
Dart
if num > 23 print('info')
if num > 23: print('info')
Colon missing after if.
Python
let msg = String::from("result"); let r=&msg; msg.push_str("!");
let mut msg = String::from("result"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
int item = 'message';
String item = 'message';
Type mismatch.
Dart
function foo(): void {{ return 50; }}
function foo(): number {{ return 50; }}
Return type mismatch.
TypeScript
my @arr = (7,96,85);
my @arr = (7,96,85);
Correct.
Perl
String a = 'data';
String a = "data";
Double quotes.
Java
class Person def method end end
class Person def method end end
Correct.
Ruby
if item = 69
if item == 69
Use ==.
Go
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
data[42]
if (data.indices.contains(42)) data[42]
Check index.
Kotlin
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
var x int
var x int
Correct.
Go
if [ $y = 85 ]; then
if [ "$y" = 85 ]; then
Quote variable.
Shell
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R