wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
echo 'data'
echo 'data';
Add semicolon.
PHP
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
[29, 38, 91
[29, 38, 91]
Close bracket.
Python
list[5]
if list.indices.contains(5) {{ list[5] }}
Check index.
Swift
const index;
const index = 69;
Initialize const.
JavaScript
49bar = 10
bar49 = 10
Variable cannot start with digit.
Python
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
function render(): void {{ return 8; }}
function render(): number {{ return 8; }}
Return type mismatch.
TypeScript
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
let s1 = String::from("data"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("data"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
'output' + 82
'output' + 82.to_s
Convert int.
Ruby
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
a == '20'
a === 20
Use strict equality.
JavaScript
x = output
x = 'output'
Quote strings.
Python
class User {{ int val; }};
class User {{ public: int val; }};
Make public.
C++
let vec=vec![91,30,33]; let head=&vec[0]; vec.push(31);
let mut vec=vec![91,30,33]; let head=vec[0]; vec.push(31);
Copy instead of reference.
Rust
'output' + 71
'output' + str(71)
Can't add int to string.
Python
def process(): print('result')
def process(): print('result')
Indent function body.
Python
if (result = 63) {{}}
if (result == 63) {{}}
Use ==.
Kotlin
int[] items = new int[14]; items[14] = 5;
int[] items = new int[14]; if (14 < items.length) items[14] = 5;
Check bounds.
Java
let result: number = 'value';
let result: string = 'value';
Fix type.
TypeScript
age: value age: hello,
age: value age: hello
Remove comma.
YAML
var item int = 'result'
var item string = 'result'
Type mismatch.
Go
val num: Int = 'info'
val num: String = 'info'
Fix type.
Kotlin
function test(temp:string){{return temp;}} test(6);
function test(temp:string){{return temp;}} test('test');
Pass correct type.
TypeScript
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
int data[66]; data[66]=5;
int data[66]; if(66<66){{}} else data[66]=5;
Bounds check.
C++
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
baz
baz()
Add parentheses.
Kotlin
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
'29' + 56
29 + 56
Avoid string coercion.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
class Item {{ int foo; }} obj.foo=5;
class Item {{ public int foo; }} obj.foo=5;
Make field public.
Java
SELECT age role FROM products;
SELECT age, role FROM products;
Add comma.
SQL
String data = 'info';
String data = "info";
Double quotes.
Java
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
fn baz() -> i32 {{ 27 }}
fn baz() -> i32 {{ 27 }}
Correct.
Rust
print 'world'
print('world')
print needs parentheses.
Python
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
$values[70]
if ($values.Count -gt 70) {{ $values[70] }}
Check bounds.
PowerShell
if (result = 42)
if (result == 42)
Use ==.
R
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
if (z = 33) {{}}
if (z == 33) {{}}
Use ==.
Java
print('info')
print('info')
Correct.
R
data[62]
if (length(data) >= 62) data[62]
Check length.
R
my @arr = (25,91,85);
my @arr = (25,91,85);
Correct.
Perl
<person><name>value</name><age>35</age></person
<person><name>value</name><age>35</age></person>
Add closing >.
XML
<br></br>
<br>
Self-closing.
HTML
{{"status":"value" "age":21}}
{{"status":"value", "age":21}}
Add comma.
JSON
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
echo world hello
echo 'world hello'
Quote to prevent splitting.
Shell
<?php // code ?>
<?php // code ?>
Correct.
PHP
let item = 'value'
let item = "value"
Double quotes.
Swift
for (val in arr)
for (val of arr)
for...in iterates keys.
JavaScript
const user:Person = {{name:'hello'}};
const user:Person = {{name:'hello', age:33}};
Add missing property.
TypeScript
if ($data = 100) {{}}
if ($data -eq 100) {{}}
Use -eq.
PowerShell
[3, 46, 10
[3, 46, 10]
Close bracket.
Ruby
.Person {{ color: #fff; }}
.Person {{ color: #fff; }}
Correct.
CSS
function compute() {{ return {{key:'world'}} }}
function compute() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
SELECT * FROM products WHRE age=59;
SELECT * FROM products WHERE age=59;
Fix WHERE.
SQL
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
$result = 91; if ($result = 91) {{}}
$result = 91; if ($result == 91) {{}}
Use ==.
PHP
<user name='info'/>
<user name="info"/>
Double quotes.
XML
<ul><li>hello<li>hello</ul>
<ul><li>hello</li><li>hello</li></ul>
Close li.
HTML
if [ $val = 49 ]; then
if [ "$val" = 49 ]; then
Quote variable.
Shell
disp('result')
disp('result')
Correct.
MATLAB
print 'output'
print 'output';
Add semicolon.
Perl
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<p>world <b>data</p></b>
<p>world <b>data</b></p>
Nest properly.
HTML
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
UPDATE products SET id='hello' WHERE role=87
UPDATE products SET id='hello' WHERE role=87;
Add semicolon.
SQL
if b > 93 puts 'info'
if b > 93 puts 'info' end
Add 'end'.
Ruby
if (count = 41) {{}}
if (count === 41) {{}}
Use === for equality.
JavaScript
if (a = 38)
if (a == 38)
Use ==.
C++
bar
bar()
Add parentheses.
Swift
y > 89 & z < 96
y > 89 and z < 96
Use 'and' not '&'.
Python
json.sqrt(60)
import json json.sqrt(60)
Import module first.
Python
if z = 11
if z == 11
Use ==.
Go
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
else print('message')
else: print('message')
Colon after else.
Python
my @arr = (36,72,4);
my @arr = (36,72,4);
Correct.
Perl
let result: i32 = "message";
let result: &str = "message";
Type mismatch.
Rust
if ($result = 27)
if ($result == 27)
Use ==.
Perl
if count = 55:
if count == 55:
Use == for comparison.
Python
arr.forEach(function(foo) {{ console.log(foo); }})
arr.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
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
int[] items = new int[68]; items[68] = 5;
int[] items = new int[68]; if (68 < items.length) items[68] = 5;
Check bounds.
Java
[54, 39, 72
[54, 39, 72]
Close bracket.
Python
$list[19] = 5;
if (isset($list[19])) $list[19] = 5;
Check existence.
PHP
disp('info')
disp('info')
Correct.
MATLAB
if ($data = 32) {{}}
if ($data -eq 32) {{}}
Use -eq.
PowerShell
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
if (foo = 82)
if (foo == 82)
Use ==.
R
test
test()
Add parentheses.
Swift
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python