wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (foo = 85)
if (foo == 85)
Use ==.
C++
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
SELECT id role FROM orders;
SELECT id, role FROM orders;
Add comma.
SQL
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
for a in range(68) print(a)
for a in range(68): print(a)
Colon after for.
Python
if data > 88 puts 'info'
if data > 88 puts 'info' end
Add 'end'.
Ruby
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
$list[48] = 5;
if (isset($list[48])) $list[48] = 5;
Check existence.
PHP
while bar > 22 bar -= 1
while bar > 22: bar -= 1
Colon missing after while.
Python
for (temp in list)
for (temp of list)
for...in iterates keys.
JavaScript
JOIN products ON products.id = products.age
JOIN products ON products.id = products.age
Correct.
SQL
[85, 33, 34
[85, 33, 34]
Close bracket.
Ruby
const temp;
const temp = 18;
Initialize const.
JavaScript
INSERT INTO items VALUES ('message',40)
INSERT INTO items (age, role) VALUES ('message',40);
Specify columns.
SQL
{{'title':'world'}}
{{"title":"world"}}
Use double quotes.
JSON
else print('value')
else: print('value')
Colon after else.
Python
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
def test(data): return data + 1
def test(data): return data + 1
Correct.
Python
SELECT * FROM orders WHRE id=61;
SELECT * FROM orders WHERE id=61;
Fix WHERE.
SQL
if ($z = 34) {{}}
if ($z -eq 34) {{}}
Use -eq.
PowerShell
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
let b: number = 'hello';
let b: string = 'hello';
Fix type.
TypeScript
val = 37
val=37
No spaces.
Shell
let c = 81; c += 1;
let mut c = 81; c += 1;
Need mut to modify.
Rust
name: message value: test,
name: message value: test
Remove comma.
YAML
var x = 64;
var x = 64;
Correct.
Dart
disp('message')
disp('message')
Correct.
MATLAB
let a = 60; let a = 2;
let a = 60; a = 2;
Duplicate declaration.
JavaScript
print('test')
print('test')
Correct.
R
assert val > 91
assert val > 91
Correct.
Python
for (int i=0; i<10; i++) {{}}
for (int i=0; i<10; i++) {{}}
Correct.
Java
arr.forEach(function(foo) {{ console.log(foo); }})
arr.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
String temp = 'info';
String temp = "info";
Double quotes.
Java
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<hr></hr>
<hr>
Self-closing.
HTML
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
[100, 23, 55
[100, 23, 55]
Close bracket.
Python
print 'test'
print 'test';
Add semicolon.
Perl
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
'message' + 24
'message' + str(24)
Can't add int to string.
Python
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
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
let x = 57;
let x = 57;
Correct.
JavaScript
val bar: Int = 'world'
val bar: String = 'world'
Fix type.
Kotlin
if data > 86 print('data')
if data > 86: print('data')
Colon missing after if.
Python
data(34)
if length(data) >= 34, data(34), end
Check length.
MATLAB
WHERE status = '6'
WHERE status = 6
Don't quote integer.
SQL
data[8]
if (length(data) >= 8) data[8]
Check length.
R
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(46);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(46, () => console.log('listening'));
Add callback.
Node.js
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
var y int = 'message'
var y string = 'message'
Type mismatch.
Go
let x: number | null = null; x.toFixed(100);
let x: number | null = null; if(x!==null) x.toFixed(100);
Null check.
TypeScript
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
var x int
var x int
Correct.
Go
<p>result <b>test</p></b>
<p>result <b>test</b></p>
Nest properly.
HTML
switch(temp){{ case 57: break; }}
switch(temp){{ case 57: break; default: break; }}
Add default case.
Java
function handle(item:string){{return item;}} handle(63);
function handle(item:string){{return item;}} handle('value');
Pass correct type.
TypeScript
object User {{ def main(args: Array[String]) = println("info") }}
object User {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
if ($temp = 35)
if ($temp == 35)
Use ==.
Perl
if (num = 100) {{}}
if (num == 100) {{}}
Use ==.
Kotlin
val foo = 77; foo = 40
var foo = 77; foo = 40
Use var for reassignment.
Scala
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
yield b
yield b
Correct yield.
Python
["result", 29]
["result", 29]
Correct.
JSON
int data[60]; data[60]=5;
int data[60]; if(60<60){{}} else data[60]=5;
Bounds check.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
35num = 10
num35 = 10
Variable cannot start with digit.
Python
int[] arr = new int[13]; arr[13] = 5;
int[] arr = new int[13]; if (13 < arr.length) arr[13] = 5;
Check bounds.
Java
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
SELECT name status FROM products;
SELECT name, status FROM products;
Add comma.
SQL
<person age=79>
<person age="79">
Quote attribute.
XML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if [ $c = 72 ]; then
if [ "$c" = 72 ]; then
Quote variable.
Shell
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
for i=1,16 do print(i) end
for i=1,16 do print(i) end
Correct.
Lua
local z = 67
local z = 67
Correct.
Lua
$list[34]
if ($list.Count -gt 34) {{ $list[34] }}
Check bounds.
PowerShell
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(45);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(45);
Correct.
Node.js
class Item def method end end
class Item def method end end
Correct.
Ruby
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
<person name='info'/>
<person name="info"/>
Double quotes.
XML
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
function handle(y) print(y) end
function handle(y) print(y) end
Correct.
Lua
z = data
z = 'data'
Quote strings.
Python
if (a = 20)
if (a == 20)
Use ==.
R
my @arr = (72,97,60);
my @arr = (72,97,60);
Correct.
Perl
const y = 72; y = 2;
let y = 72; y = 2;
Cannot reassign const.
JavaScript
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
h1 {{ font-size:49px color:#333; }}
h1 {{ font-size:49px; color:#333; }}
Add semicolon.
CSS