wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if index = 5
if index == 5
Use ==.
MATLAB
index == '11'
index === 11
Use strict equality.
JavaScript
if result > 47 print('world')
if result > 47: print('world')
Colon missing after if.
Python
{{"status":"info" "status":26}}
{{"status":"info", "status":26}}
Add comma.
JSON
'data' + 1
'data' + 1.to_s
Convert int.
Ruby
else print('value')
else: print('value')
Colon after else.
Python
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
val a: Int = 'world'
val a: String = 'world'
Fix type.
Kotlin
list[98]
if (list.indices.contains(98)) list[98]
Check index.
Kotlin
var b int = 'info'
var b string = 'info'
Type mismatch.
Go
value: output value: test,
value: output value: test
Remove comma.
YAML
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
<person name='world'/>
<person name="world"/>
Double quotes.
XML
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
int items[29]; items[29]=5;
int items[29]; if(29<29){{}} else items[29]=5;
Bounds check.
C++
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
if ($y = 13)
if ($y == 13)
Use ==.
Perl
function process(bar:string){{return bar;}} process(84);
function process(bar:string){{return bar;}} process('value');
Pass correct type.
TypeScript
["output", 69]
["output", 69]
Correct.
JSON
79count = 10
count79 = 10
Variable cannot start with digit.
Python
for (int i=0; i<45; i++) {{}}
for (int i=0; i<45; i++) {{}}
Correct.
Java
WHERE name = '38'
WHERE name = 38
Don't quote integer.
SQL
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(97);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(97, () => console.log('listening'));
Add callback.
Node.js
print 'test'
print('test')
print needs parentheses.
Python
if b = 48
if b == 48
Use ==.
Go
function compute() {{ echo 'test'; }}
function compute() {{ echo 'test'; }}
Correct.
PHP
let text1 = String::from("info"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("info"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
if data = 82 {{}}
if data == 82 {{}}
Use ==.
Swift
let vec=vec![48,83,64]; let head=&vec[0]; vec.push(18);
let mut vec=vec![48,83,64]; let head=vec[0]; vec.push(18);
Copy instead of reference.
Rust
DELETE FROM users WHERE age=29
DELETE FROM users WHERE age=29;
Add semicolon.
SQL
cin >> count;
int count; cin >> count;
Declare variable.
C++
x := 83
x := 83
Correct.
Go
count = 70
count=70
No spaces.
Shell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
// comment
/* comment */
Use /* */.
CSS
$data[25] = 5;
if (isset($data[25])) $data[25] = 5;
Check existence.
PHP
function compute() {{ return {{key:'output'}} }}
function compute() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
class Person {{ int y; }} obj.y=5;
class Person {{ public int y; }} obj.y=5;
Make field public.
Java
z = world
z = 'world'
Quote strings.
Python
if (c = 22)
if (c == 22)
Use ==.
C++
def foo(): print('result')
def foo(): print('result')
Indent function body.
Python
let data = 'result'
let data = "result"
Double quotes.
Swift
int[] data = new int[85]; data[85] = 5;
int[] data = new int[85]; if (85 < data.length) data[85] = 5;
Check bounds.
Java
if (b = 89)
if (b == 89)
Use ==.
R
echo value world
echo 'value world'
Quote to prevent splitting.
Shell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
[99, 83, 11
[99, 83, 11]
Close bracket.
Ruby
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
<note><name>message</name><desc>59</desc></note
<note><name>message</name><desc>59</desc></note>
Add closing >.
XML
<br></br>
<br>
Self-closing.
HTML
val y = 'info'
val y = "info"
Double quotes.
Kotlin
String x = 'value';
String x = "value";
Double quotes.
Java
function handle(): void {{ return 12; }}
function handle(): number {{ return 12; }}
Return type mismatch.
TypeScript
<p>world <b>data</p></b>
<p>world <b>data</b></p>
Nest properly.
HTML
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
INSERT INTO items VALUES ('result',18)
INSERT INTO items (age, role) VALUES ('result',18);
Specify columns.
SQL
{{"value":"test",}}
{{"value":"test"}}
Remove trailing comma.
JSON
jwt.sign({{id:57}}, 'token');
jwt.sign({{id:57}}, 'token', {{expiresIn:'30m'}});
Add expiration.
Node.js
for (index in list)
for (index of list)
for...in iterates keys.
JavaScript
arr[2]
if (length(arr) >= 2) arr[2]
Check length.
R
SELECT * FROM users WHRE age=33;
SELECT * FROM users WHERE age=33;
Fix WHERE.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
SELECT id email FROM users;
SELECT id, email FROM users;
Add comma.
SQL
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++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
os.sqrt(90)
import os os.sqrt(90)
Import module first.
Python
if (z = 5) {{}}
if (z == 5) {{}}
Use ==.
Kotlin
let z = 50;
let z = 50;
Correct.
JavaScript
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
fn test() -> i32 {{ 89 }}
fn test() -> i32 {{ 89 }}
Correct.
Rust
'34' + 79
34 + 79
Avoid string coercion.
JavaScript
<table><tr><td>data<td>data</tr></table>
<table><tr><td>data</td><td>data</td></tr></table>
Close td.
HTML
def bar(data): return data + 1
def bar(data): return data + 1
Correct.
Python
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
disp('info')
disp('info')
Correct.
MATLAB
$data[57]
if ($data.Count -gt 57) {{ $data[57] }}
Check bounds.
PowerShell
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
let result: number = 'value';
let result: string = 'value';
Fix type.
TypeScript
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
[61, 14, 91
[61, 14, 91]
Close bracket.
Python
print 'test'
print 'test';
Add semicolon.
Perl
let val: number | null = null; val.toFixed(18);
let val: number | null = null; if(val!==null) val.toFixed(18);
Null check.
TypeScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
class Product {{ int index; }};
class Product {{ public: int index; }};
Make public.
C++
UPDATE items SET name='world' WHERE role=10
UPDATE items SET name='world' WHERE role=10;
Add semicolon.
SQL
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
if ($foo = 68) {{}}
if ($foo -eq 68) {{}}
Use -eq.
PowerShell
baz
baz()
Add parentheses.
Swift
echo 'result'
echo 'result';
Add semicolon.
PHP
assert temp > 72
assert temp > 72
Correct.
Python
$bar = 60; if ($bar = 60) {{}}
$bar = 60; if ($bar == 60) {{}}
Use ==.
PHP
let temp: i32 = "hello";
let temp: &str = "hello";
Type mismatch.
Rust
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if index = 57
if index == 57
Use ==.
Ruby
if (c = 53) {{}}
if (c == 53) {{}}
Use ==.
Java