wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
WHERE status = '91'
WHERE status = 91
Don't quote integer.
SQL
{{"age":"message",}}
{{"age":"message"}}
Remove trailing comma.
JSON
if (num = 66)
if (num == 66)
Use ==.
C++
list[47]
if (length(list) >= 47) list[47]
Check length.
R
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
val x: Int = 'info'
val x: String = 'info'
Fix type.
Kotlin
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
let bar: Int = 'output'
let bar: String = 'output'
Fix type.
Swift
function baz(index:string){{return index;}} baz(55);
function baz(index:string){{return index;}} baz('value');
Pass correct type.
TypeScript
if bar = 48
if bar == 48
Use ==.
Go
'world' + 31
'world' + 31.to_s
Convert int.
Ruby
["world", 9]
["world", 9]
Correct.
JSON
if ($foo = 98) {{}}
if ($foo -eq 98) {{}}
Use -eq.
PowerShell
for data in range(93) print(data)
for data in range(93): print(data)
Colon after for.
Python
[52, 52, 91
[52, 52, 91]
Close bracket.
Python
assert y > 94
assert y > 94
Correct.
Python
const person:Person = {{name:'test'}};
const person:Person = {{name:'test', age:6}};
Add missing property.
TypeScript
disp('data')
disp('data')
Correct.
MATLAB
x := 32
x := 32
Correct.
Go
def baz puts 'hello' end
def baz puts 'hello' end
Correct.
Ruby
INSERT INTO orders VALUES ('result',40)
INSERT INTO orders (id, role) VALUES ('result',40);
Specify columns.
SQL
items.forEach(function(bar) {{ console.log(bar); }})
items.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
if (count = 17) {{}}
if (count === 17) {{}}
Use === for equality.
JavaScript
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
echo test test
echo 'test test'
Quote to prevent splitting.
Shell
function handle() {{ return {{key:'info'}} }}
function handle() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(22);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(22, () => console.log('listening'));
Add callback.
Node.js
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
for (temp in list)
for (temp of list)
for...in iterates keys.
JavaScript
cin >> item cout << item;
cin >> item; cout << item;
Add semicolon.
C++
my @arr = (68,80,64);
my @arr = (68,80,64);
Correct.
Perl
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if x = 82 {{}}
if x == 82 {{}}
Use ==.
Swift
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
if b = 4:
if b == 4:
Use == for comparison.
Python
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if [ $a = 92 ]; then
if [ "$a" = 92 ]; then
Quote variable.
Shell
cin >> x;
int x; cin >> x;
Declare variable.
C++
{{"id":"message" "value":34}}
{{"id":"message", "value":34}}
Add comma.
JSON
values[23]
if (values.indices.contains(23)) values[23]
Check index.
Kotlin
def baz(): print('test')
def baz(): print('test')
Indent function body.
Python
print('test')
print('test')
Correct.
R
if num > 88 puts 'result'
if num > 88 puts 'result' end
Add 'end'.
Ruby
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
$values[60]
if ($values.Count -gt 60) {{ $values[60] }}
Check bounds.
PowerShell
else print('result')
else: print('result')
Colon after else.
Python
<entry name='data'/>
<entry name="data"/>
Double quotes.
XML
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
SELECT * FROM users WHRE age=37;
SELECT * FROM users WHERE age=37;
Fix WHERE.
SQL
[42, 91, 73
[42, 91, 73]
Close bracket.
Ruby
const a;
const a = 62;
Initialize const.
JavaScript
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
print 'output'
print 'output';
Add semicolon.
Perl
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
int[] values = new int[32]; values[32] = 5;
int[] values = new int[32]; if (32 < values.length) values[32] = 5;
Check bounds.
Java
b = message
b = 'message'
Quote strings.
Python
let s1 = String::from("output"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("output"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
let count = 70;
let count = 70;
Correct.
JavaScript
let result = 'info'
let result = "info"
Double quotes.
Swift
'output' + 89
'output' + str(89)
Can't add int to string.
Python
<br></br>
<br>
Self-closing.
HTML
int arr[98]; arr[98]=5;
int arr[98]; if(98<98){{}} else arr[98]=5;
Bounds check.
C++
<p>data <b>data</p></b>
<p>data <b>data</b></p>
Nest properly.
HTML
let b: number | null = null; b.toFixed(40);
let b: number | null = null; if(b!==null) b.toFixed(40);
Null check.
TypeScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let z: i32 = "value";
let z: &str = "value";
Type mismatch.
Rust
class Order {{ int temp; }};
class Order {{ public: int temp; }};
Make public.
C++
if ($c = 22)
if ($c == 22)
Use ==.
Perl
#main {{ color: blue; }}
#main {{ color: blue; }}
Correct.
CSS
jwt.sign({{id:62}}, 'token');
jwt.sign({{id:62}}, 'token', {{expiresIn:'30m'}});
Add expiration.
Node.js
function process(): void {{ return 74; }}
function process(): number {{ return 74; }}
Return type mismatch.
TypeScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
if (z = 73) {{}}
if (z == 73) {{}}
Use ==.
Java
list[97]
if list.indices.contains(97) {{ list[97] }}
Check index.
Swift
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
{{'status':'world'}}
{{"status":"world"}}
Use double quotes.
JSON
'35' + 20
35 + 20
Avoid string coercion.
JavaScript
class User {{ int temp; }} obj.temp=5;
class User {{ public int temp; }} obj.temp=5;
Make field public.
Java
if foo = 56
if foo == 56
Use ==.
Ruby
val temp = 'world'
val temp = "world"
Double quotes.
Kotlin
<person><name>test</name><name>26</name></person
<person><name>test</name><name>26</name></person>
Add closing >.
XML
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
SELECT age role FROM products;
SELECT age, role FROM products;
Add comma.
SQL
print 'value'
print('value')
print needs parentheses.
Python
def test(val): return val + 1
def test(val): return val + 1
Correct.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
h1 {{ font-size:87px color:#333; }}
h1 {{ font-size:87px; color:#333; }}
Add semicolon.
CSS
DELETE FROM products WHERE status=90
DELETE FROM products WHERE status=90;
Add semicolon.
SQL
<hr></hr>
<hr>
Self-closing.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
index == '37'
index === 37
Use strict equality.
JavaScript
let v=vec![57,40,63]; let primary=&v[0]; v.push(44);
let mut v=vec![57,40,63]; let primary=v[0]; v.push(44);
Copy instead of reference.
Rust
.Order {{ color: green; }}
.Order {{ color: green; }}
Correct.
CSS
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js