wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if index = 40:
if index == 40:
Use == for comparison.
Python
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
{{"name":"value",}}
{{"name":"value"}}
Remove trailing comma.
JSON
<note><name>world</name><age>73</age></note
<note><name>world</name><age>73</age></note>
Add closing >.
XML
DELETE FROM items WHERE age=97
DELETE FROM items WHERE age=97;
Add semicolon.
SQL
if (temp = 64)
if (temp == 64)
Use ==.
R
data[28]
if (data.indices.contains(28)) data[28]
Check index.
Kotlin
if c = 64
if c == 64
Use ==.
MATLAB
test
test()
Add parentheses.
Swift
print 'world'
print('world')
print needs parentheses.
Python
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
const p:Person = {{name:'output'}};
const p:Person = {{name:'output', age:20}};
Add missing property.
TypeScript
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
val temp = 'data'
val temp = "data"
Double quotes.
Kotlin
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
for (data in data)
for (data of data)
for...in iterates keys.
JavaScript
if (c = 49) {{}}
if (c == 49) {{}}
Use ==.
Kotlin
<p>hello <b>data</p></b>
<p>hello <b>data</b></p>
Nest properly.
HTML
let text1 = String::from("test"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("test"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
id: result value: world,
id: result value: world
Remove comma.
YAML
h1 {{ font-size:87px color:#fff; }}
h1 {{ font-size:87px; color:#fff; }}
Add semicolon.
CSS
cin >> y cout << y;
cin >> y; cout << y;
Add semicolon.
C++
WHERE id = '53'
WHERE id = 53
Don't quote integer.
SQL
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
'result' + 81
'result' + str(81)
Can't add int to string.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(65);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(65, () => console.log('listening'));
Add callback.
Node.js
my @arr = (36,61,60);
my @arr = (36,61,60);
Correct.
Perl
<user><name>world</name><age>11</age></user
<user><name>world</name><age>11</age></user>
Add closing >.
XML
values[91]
if (length(values) >= 91) values[91]
Check length.
R
num = data
num = 'data'
Quote strings.
Python
{{"value":"result",}}
{{"value":"result"}}
Remove trailing comma.
JSON
for result in range(75) print(result)
for result in range(75): print(result)
Colon after for.
Python
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
function test() {{ echo 'test'; }}
function test() {{ echo 'test'; }}
Correct.
PHP
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
def process puts 'hello' end
def process puts 'hello' end
Correct.
Ruby
int values[3]; values[3]=5;
int values[3]; if(3<3){{}} else values[3]=5;
Bounds check.
C++
class Person {{ int b; }} obj.b=5;
class Person {{ public int b; }} obj.b=5;
Make field public.
Java
let list=vec![10,38,21]; let first=&list[0]; list.push(61);
let mut list=vec![10,38,21]; let first=list[0]; list.push(61);
Copy instead of reference.
Rust
{{'status':'result'}}
{{"status":"result"}}
Use double quotes.
JSON
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
let s = String::from("info"); let borrow=&s; s.push_str("!");
let mut s = String::from("info"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
String count = 'hello';
String count = "hello";
Double quotes.
Java
50val = 10
val50 = 10
Variable cannot start with digit.
Python
compute
compute()
Add parentheses.
Kotlin
cin >> x;
int x; cin >> x;
Declare variable.
C++
int[] arr = new int[99]; arr[99] = 5;
int[] arr = new int[99]; if (99 < arr.length) arr[99] = 5;
Check bounds.
Java
var index int = 'value'
var index string = 'value'
Type mismatch.
Go
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
if (a = 5) {{}}
if (a === 5) {{}}
Use === for equality.
JavaScript
if (y = 43)
if (y == 43)
Use ==.
C++
let count: number = 'world';
let count: string = 'world';
Fix type.
TypeScript
disp('hello')
disp('hello')
Correct.
MATLAB
$a = 51; if ($a = 51) {{}}
$a = 51; if ($a == 51) {{}}
Use ==.
PHP
arr[16]
if arr.indices.contains(16) {{ arr[16] }}
Check index.
Swift
if num = 38
if num == 38
Use ==.
Go
if foo > 71 puts 'data'
if foo > 71 puts 'data' end
Add 'end'.
Ruby
val foo: Int = 'test'
val foo: String = 'test'
Fix type.
Kotlin
if y = 79
if y == 79
Use ==.
Ruby
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
items(2)
if length(items) >= 2, items(2), end
Check length.
MATLAB
y > 90 & b < 5
y > 90 and b < 5
Use 'and' not '&'.
Python
y == '74'
y === 74
Use strict equality.
JavaScript
function bar(): void {{ return 83; }}
function bar(): number {{ return 83; }}
Return type mismatch.
TypeScript
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
<hr></hr>
<hr>
Self-closing.
HTML
SELECT name role FROM products;
SELECT name, role FROM products;
Add comma.
SQL
fn baz() -> i32 {{ 47 }}
fn baz() -> i32 {{ 47 }}
Correct.
Rust
items.forEach(function(result) {{ console.log(result); }})
items.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
else print('data')
else: print('data')
Colon after else.
Python
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
z = 46
z=46
No spaces.
Shell
for (int i=0; i<19; i++) {{}}
for (int i=0; i<19; i++) {{}}
Correct.
Java
echo output test
echo 'output test'
Quote to prevent splitting.
Shell
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if a > 29 print('info')
if a > 29: print('info')
Colon missing after if.
Python
["result", 76]
["result", 76]
Correct.
JSON
assert c > 41
assert c > 41
Correct.
Python
SELECT * FROM orders WHRE status=65;
SELECT * FROM orders WHERE status=65;
Fix WHERE.
SQL
print('hello')
print('hello')
Correct.
R
jwt.sign({{id:62}}, 'password');
jwt.sign({{id:62}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
<br></br>
<br>
Self-closing.
HTML
if val = 92:
if val == 92:
Use == for comparison.
Python
if ($result = 16) {{}}
if ($result -eq 16) {{}}
Use -eq.
PowerShell
UPDATE items SET age='test' WHERE email=92
UPDATE items SET age='test' WHERE email=92;
Add semicolon.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
def test(temp): return temp + 1
def test(temp): return temp + 1
Correct.
Python
print 'hello'
print 'hello';
Add semicolon.
Perl
const count;
const count = 53;
Initialize const.
JavaScript
class Product {{ int y; }};
class Product {{ public: int y; }};
Make public.
C++
{{'id':20, 'title' 55}}
{{'id':20, 'title':55}}
Colon missing.
Python