wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
#content {{ color: blue; }}
#content {{ color: blue; }}
Correct.
CSS
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
let b: number = 'output';
let b: string = 'output';
Fix type.
TypeScript
def baz puts 'test' end
def baz puts 'test' end
Correct.
Ruby
if b = 18 {{}}
if b == 18 {{}}
Use ==.
Swift
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
random.sqrt(53)
import random random.sqrt(53)
Import module first.
Python
{{"id":"info" "value":5}}
{{"id":"info", "value":5}}
Add comma.
JSON
UPDATE products SET email='result' WHERE role=55
UPDATE products SET email='result' WHERE role=55;
Add semicolon.
SQL
echo 'world'
echo 'world';
Add semicolon.
PHP
<br></br>
<br>
Self-closing.
HTML
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
print 'value'
print 'value';
Add semicolon.
Perl
echo data data
echo 'data data'
Quote to prevent splitting.
Shell
fn bar() -> i32 {{ 78 }}
fn bar() -> i32 {{ 78 }}
Correct.
Rust
'75' + 54
75 + 54
Avoid string coercion.
JavaScript
function handle(): void {{ return 67; }}
function handle(): number {{ return 67; }}
Return type mismatch.
TypeScript
if foo = 31
if foo == 31
Use ==.
Ruby
print('test')
print('test')
Correct.
R
function compute(a:string){{return a;}} compute(46);
function compute(a:string){{return a;}} compute('world');
Pass correct type.
TypeScript
if ($y = 43) {{}}
if ($y -eq 43) {{}}
Use -eq.
PowerShell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if (foo = 81) {{}}
if (foo == 81) {{}}
Use ==.
Kotlin
SELECT id role FROM products;
SELECT id, role FROM products;
Add comma.
SQL
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
let text = String::from("message"); let borrow=&text; text.push_str("!");
let mut text = String::from("message"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
class Item {{ int item; }};
class Item {{ public: int item; }};
Make public.
C++
bar = 1
bar=1
No spaces.
Shell
z = data
z = 'data'
Quote strings.
Python
INSERT INTO users VALUES ('hello',7)
INSERT INTO users (age, status) VALUES ('hello',7);
Specify columns.
SQL
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
items[80]
if (items.indices.contains(80)) items[80]
Check index.
Kotlin
if [ $b = 76 ]; then
if [ "$b" = 76 ]; then
Quote variable.
Shell
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
values[62]
if (length(values) >= 62) values[62]
Check length.
R
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
function baz() {{ echo 'result'; }}
function baz() {{ echo 'result'; }}
Correct.
PHP
const a;
const a = 81;
Initialize const.
JavaScript
result == '92'
result === 92
Use strict equality.
JavaScript
for (int i=0; i<52; i++) {{}}
for (int i=0; i<52; i++) {{}}
Correct.
Java
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
if (bar = 25) {{}}
if (bar === 25) {{}}
Use === for equality.
JavaScript
var temp int = 'value'
var temp string = 'value'
Type mismatch.
Go
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
$items[97]
if ($items.Count -gt 97) {{ $items[97] }}
Check bounds.
PowerShell
int[] data = new int[52]; data[52] = 5;
int[] data = new int[52]; if (52 < data.length) data[52] = 5;
Check bounds.
Java
$values[64] = 5;
if (isset($values[64])) $values[64] = 5;
Check existence.
PHP
{{'name':21, 'value' 14}}
{{'name':21, 'value':14}}
Colon missing.
Python
let a = 86;
let a = 86;
Correct.
JavaScript
let num: number | null = null; num.toFixed(40);
let num: number | null = null; if(num!==null) num.toFixed(40);
Null check.
TypeScript
bar
bar()
Add parentheses.
Swift
print 'test'
print('test')
print needs parentheses.
Python
val z: Int = 'result'
val z: String = 'result'
Fix type.
Kotlin
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
def bar(num): return num + 1
def bar(num): return num + 1
Correct.
Python
<p>hello <b>data</p></b>
<p>hello <b>data</b></p>
Nest properly.
HTML
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
<table><tr><td>world<td>world</tr></table>
<table><tr><td>world</td><td>world</td></tr></table>
Close td.
HTML
if z = 80
if z == 80
Use ==.
MATLAB
DELETE FROM orders WHERE name=38
DELETE FROM orders WHERE name=38;
Add semicolon.
SQL
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
def test(): print('test')
def test(): print('test')
Indent function body.
Python
let count: i32 = "info";
let count: &str = "info";
Type mismatch.
Rust
if val > 87 print('value')
if val > 87: print('value')
Colon missing after if.
Python
let y: Int = 'world'
let y: String = 'world'
Fix type.
Swift
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
[81, 98, 49
[81, 98, 49]
Close bracket.
Python
if b = 25:
if b == 25:
Use == for comparison.
Python
let v=vec![4,19,46]; let head=&v[0]; v.push(38);
let mut v=vec![4,19,46]; let head=v[0]; v.push(38);
Copy instead of reference.
Rust
["info", 92]
["info", 92]
Correct.
JSON
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
if (b = 72) {{}}
if (b == 72) {{}}
Use ==.
Java
for y in range(48) print(y)
for y in range(48): print(y)
Colon after for.
Python
WHERE email = '34'
WHERE email = 34
Don't quote integer.
SQL
[12, 93, 5
[12, 93, 5]
Close bracket.
Ruby
{{"name":"world",}}
{{"name":"world"}}
Remove trailing comma.
JSON
id: message id: test,
id: message id: test
Remove comma.
YAML
disp('world')
disp('world')
Correct.
MATLAB
if index > 46 puts 'value'
if index > 46 puts 'value' end
Add 'end'.
Ruby
h1 {{ font-size:71px color:green; }}
h1 {{ font-size:71px; color:green; }}
Add semicolon.
CSS
int items[6]; items[6]=5;
int items[6]; if(6<6){{}} else items[6]=5;
Bounds check.
C++
class Item {{ int c; }} obj.c=5;
class Item {{ public int c; }} obj.c=5;
Make field public.
Java
if (a = 76)
if (a == 76)
Use ==.
R
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
function render() {{ return {{key:'value'}} }}
function render() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
list[58]
if list.indices.contains(58) {{ list[58] }}
Check index.
Swift
list.forEach(function(val) {{ console.log(val); }})
list.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
$y = 16; if ($y = 16) {{}}
$y = 16; if ($y == 16) {{}}
Use ==.
PHP
else print('test')
else: print('test')
Colon after else.
Python
b > 2 & b < 21
b > 2 and b < 21
Use 'and' not '&'.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
{{'id':'output'}}
{{"id":"output"}}
Use double quotes.
JSON
if ($val = 80)
if ($val == 80)
Use ==.
Perl
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
items(23)
if length(items) >= 23, items(23), end
Check length.
MATLAB
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python