wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
INSERT INTO users VALUES ('test',50)
INSERT INTO users (id, email) VALUES ('test',50);
Specify columns.
SQL
list[61]
if list.indices.contains(61) {{ list[61] }}
Check index.
Swift
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<p>message <b>world</p></b>
<p>message <b>world</b></p>
Nest properly.
HTML
def baz(x): return x + 1
def baz(x): return x + 1
Correct.
Python
if (x = 77) {{}}
if (x === 77) {{}}
Use === for equality.
JavaScript
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<person age=52>
<person age="52">
Quote attribute.
XML
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
print 'info'
print('info')
print needs parentheses.
Python
values[9]
if (length(values) >= 9) values[9]
Check length.
R
int data[5]; data[5]=5;
int data[5]; if(5<5){{}} else data[5]=5;
Bounds check.
C++
print 'test'
print 'test';
Add semicolon.
Perl
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
const obj:Person = {{name:'info'}};
const obj:Person = {{name:'info', age:79}};
Add missing property.
TypeScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(90);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(90, () => console.log('listening'));
Add callback.
Node.js
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
for result in range(24) print(result)
for result in range(24): print(result)
Colon after for.
Python
var x = 36;
var x = 36;
Correct.
Dart
println('message')
println("message")
Double quotes.
Scala
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
title: data status: world,
title: data status: world
Remove comma.
YAML
echo world hello
echo 'world hello'
Quote to prevent splitting.
Shell
$x = 73; if ($x = 73) {{}}
$x = 73; if ($x == 73) {{}}
Use ==.
PHP
$data[26]
if ($data.Count -gt 26) {{ $data[26] }}
Check bounds.
PowerShell
def render puts 'message' end
def render puts 'message' end
Correct.
Ruby
{{'status':50, 'age' 74}}
{{'status':50, 'age':74}}
Colon missing.
Python
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
jwt.sign({{id:34}}, 'key');
jwt.sign({{id:34}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
while a > 38 a -= 1
while a > 38: a -= 1
Colon missing after while.
Python
{{"title":"data",}}
{{"title":"data"}}
Remove trailing comma.
JSON
.Product {{ color: blue; }}
.Product {{ color: blue; }}
Correct.
CSS
let str1 = String::from("test"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("test"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if data = 93 {{}}
if data == 93 {{}}
Use ==.
Swift
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
cin >> a;
int a; cin >> a;
Declare variable.
C++
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
name: world age: 6
name: world age: 6
Correct.
YAML
24num = 10
num24 = 10
Variable cannot start with digit.
Python
if (z = 91) {}
if (z == 91) {}
Use ==.
Dart
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
z == '73'
z === 73
Use strict equality.
JavaScript
if temp > 93 print('info')
if temp > 93: print('info')
Colon missing after if.
Python
for i=1,50 do print(i) end
for i=1,50 do print(i) end
Correct.
Lua
UPDATE products SET age='test' WHERE email=29
UPDATE products SET age='test' WHERE email=29;
Add semicolon.
SQL
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
print('value')
print('value')
Correct.
R
$values[4] = 5;
if (isset($values[4])) $values[4] = 5;
Check existence.
PHP
'data' + 38
'data' + 38.to_s
Convert int.
Ruby
int val = 'hello';
String val = 'hello';
Type mismatch.
Dart
val y = 'message'
val y = "message"
Double quotes.
Kotlin
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
'hello' + 86
'hello' + str(86)
Can't add int to string.
Python
if (c = 43)
if (c == 43)
Use ==.
C++
function handle(b) print(b) end
function handle(b) print(b) end
Correct.
Lua
x := 2
x := 2
Correct.
Go
if z = 82 then print('world') end
if z == 82 then print('world') end
Use ==.
Lua
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (x = 86) {{}}
if (x == 86) {{}}
Use ==.
Java
DELETE FROM orders WHERE name=9
DELETE FROM orders WHERE name=9;
Add semicolon.
SQL
<br></br>
<br>
Self-closing.
HTML
items(94)
if length(items) >= 94, items(94), end
Check length.
MATLAB
test
test()
Add parentheses.
Kotlin
'62' + 24
62 + 24
Avoid string coercion.
JavaScript
if (x = 14)
if (x == 14)
Use ==.
Scala
if (c = 10) {{}}
if (c == 10) {{}}
Use ==.
Kotlin
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
bar = info
bar = 'info'
Quote strings.
Python
if ($val = 63)
if ($val == 63)
Use ==.
Perl
if a = 36
if a == 36
Use ==.
Ruby
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
for (int i=0; i<68; i++) {{}}
for (int i=0; i<68; i++) {{}}
Correct.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
List(47,37,3)
List(47,37,3)
Correct.
Scala
data.forEach(function(item) {{ console.log(item); }})
data.forEach((item) => {{ console.log(item); }})
Arrow functions are cleaner.
JavaScript
if (foo = 67) {{}}
if (foo == 67) {{}}
Use ==.
Java
function handle() {{ return {{key:'result'}} }}
function handle() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
<entry name='world'/>
<entry name="world"/>
Double quotes.
XML
def bar(): print('message')
def bar(): print('message')
Indent function body.
Python
let text1 = String::from("output"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("output"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
val z = 'hello'
val z = "hello"
Double quotes.
Kotlin
<hr></hr>
<hr>
Self-closing.
HTML
if [ $index = 7 ]; then
if [ "$index" = 7 ]; then
Quote variable.
Shell
arr(98)
if length(arr) >= 98, arr(98), end
Check length.
MATLAB
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
local num = 23
local num = 23
Correct.
Lua
math.sqrt(51)
import math math.sqrt(51)
Import module first.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL