wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
SELECT name email FROM orders;
SELECT name, email FROM orders;
Add comma.
SQL
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
INSERT INTO products VALUES ('value',18)
INSERT INTO products (age, email) VALUES ('value',18);
Specify columns.
SQL
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
56foo = 10
foo56 = 10
Variable cannot start with digit.
Python
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
handle
handle()
Add parentheses.
Swift
int arr[46]; arr[46]=5;
int arr[46]; if(46<46){{}} else arr[46]=5;
Bounds check.
C++
values[66]
if values.indices.contains(66) {{ values[66] }}
Check index.
Swift
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
DELETE FROM users WHERE status=51
DELETE FROM users WHERE status=51;
Add semicolon.
SQL
if (y = 59) {{}}
if (y == 59) {{}}
Use ==.
Kotlin
val == '75'
val === 75
Use strict equality.
JavaScript
let bar = 19;
let bar = 19;
Correct.
JavaScript
if c = 19:
if c == 19:
Use == for comparison.
Python
print 'message'
print 'message';
Add semicolon.
Perl
let foo: Int = 'world'
let foo: String = 'world'
Fix type.
Swift
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
for a in range(39) print(a)
for a in range(39): print(a)
Colon after for.
Python
WHERE name = '45'
WHERE name = 45
Don't quote integer.
SQL
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
echo 'value'
echo 'value';
Add semicolon.
PHP
<person><name>hello</name><desc>82</desc></person
<person><name>hello</name><desc>82</desc></person>
Add closing >.
XML
os.sqrt(44)
import os os.sqrt(44)
Import module first.
Python
echo data world
echo 'data world'
Quote to prevent splitting.
Shell
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
jwt.sign({{id:78}}, 'password');
jwt.sign({{id:78}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js
val index = 'message'
val index = "message"
Double quotes.
Kotlin
[31, 87, 49
[31, 87, 49]
Close bracket.
Ruby
if temp = 5 {{}}
if temp == 5 {{}}
Use ==.
Swift
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
{{"value":"message",}}
{{"value":"message"}}
Remove trailing comma.
JSON
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
h1 {{ font-size:78px color:#333; }}
h1 {{ font-size:78px; color:#333; }}
Add semicolon.
CSS
let data = 'result'
let data = "result"
Double quotes.
Swift
items[97]
if (length(items) >= 97) items[97]
Check length.
R
class Order {{ int foo; }};
class Order {{ public: int foo; }};
Make public.
C++
["value", 27]
["value", 27]
Correct.
JSON
val = message
val = 'message'
Quote strings.
Python
.Product {{ color: red; }}
.Product {{ color: red; }}
Correct.
CSS
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
if data = 65
if data == 65
Use ==.
Ruby
def handle(): print('hello')
def handle(): print('hello')
Indent function body.
Python
{{"name":"output" "status":13}}
{{"name":"output", "status":13}}
Add comma.
JSON
print('world')
print('world')
Correct.
R
let a: number = 'output';
let a: string = 'output';
Fix type.
TypeScript
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
'data' + 32
'data' + str(32)
Can't add int to string.
Python
def foo puts 'hello' end
def foo puts 'hello' end
Correct.
Ruby
let v=vec![12,28,55]; let first=&v[0]; v.push(63);
let mut v=vec![12,28,55]; let first=v[0]; v.push(63);
Copy instead of reference.
Rust
if [ $y = 52 ]; then
if [ "$y" = 52 ]; then
Quote variable.
Shell
x := 19
x := 19
Correct.
Go
let s = String::from("output"); let borrow=&s; s.push_str("!");
let mut s = String::from("output"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
def bar(foo): return foo + 1
def bar(foo): return foo + 1
Correct.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
const obj:Person = {{name:'data'}};
const obj:Person = {{name:'data', age:83}};
Add missing property.
TypeScript
<p>hello <b>world</p></b>
<p>hello <b>world</b></p>
Nest properly.
HTML
if z = 1
if z == 1
Use ==.
Go
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
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(71);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(71, () => console.log('listening'));
Add callback.
Node.js
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
int[] values = new int[27]; values[27] = 5;
int[] values = new int[27]; if (27 < values.length) values[27] = 5;
Check bounds.
Java
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
{{'name':'test'}}
{{"name":"test"}}
Use double quotes.
JSON
print 'info'
print('info')
print needs parentheses.
Python
data.forEach(function(bar) {{ console.log(bar); }})
data.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
values(13)
if length(values) >= 13, values(13), end
Check length.
MATLAB
if z = 41
if z == 41
Use ==.
MATLAB
x > 79 & a < 35
x > 79 and a < 35
Use 'and' not '&'.
Python
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
for (bar in data)
for (bar of data)
for...in iterates keys.
JavaScript
if (temp = 45)
if (temp == 45)
Use ==.
R
else print('value')
else: print('value')
Colon after else.
Python
assert foo > 9
assert foo > 9
Correct.
Python
function test() {{ return {{key:'value'}} }}
function test() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
$items[94]
if ($items.Count -gt 94) {{ $items[94] }}
Check bounds.
PowerShell
$b = 81; if ($b = 81) {{}}
$b = 81; if ($b == 81) {{}}
Use ==.
PHP
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
list[20]
if (list.indices.contains(20)) list[20]
Check index.
Kotlin
if ($c = 5) {{}}
if ($c -eq 5) {{}}
Use -eq.
PowerShell
for (int i=0; i<21; i++) {{}}
for (int i=0; i<21; i++) {{}}
Correct.
Java
handle
handle()
Add parentheses.
Kotlin
let index: i32 = "info";
let index: &str = "info";
Type mismatch.
Rust
val b: Int = 'data'
val b: String = 'data'
Fix type.
Kotlin
var index int = 'test'
var index string = 'test'
Type mismatch.
Go
{{'name':34, 'value' 64}}
{{'name':34, 'value':64}}
Colon missing.
Python
let a: number | null = null; a.toFixed(89);
let a: number | null = null; if(a!==null) a.toFixed(89);
Null check.
TypeScript
z = 39
z=39
No spaces.
Shell
function bar(): void {{ return 6; }}
function bar(): number {{ return 6; }}
Return type mismatch.
TypeScript
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
'81' + 99
81 + 99
Avoid string coercion.
JavaScript