wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
def test(): print('value')
def test(): print('value')
Indent function body.
Python
const temp = 89; temp = 48;
let temp = 89; temp = 48;
Cannot reassign const.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
.Order {{ color: green; }}
.Order {{ color: green; }}
Correct.
CSS
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
30x = 10
x30 = 10
Variable cannot start with digit.
Python
x == '7'
x === 7
Use strict equality.
JavaScript
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
data.forEach(function(item) {{ console.log(item); }})
data.forEach((item) => {{ console.log(item); }})
Arrow functions are cleaner.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
arr[50]
if (arr.indices.contains(50)) arr[50]
Check index.
Kotlin
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(95);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(95, () => console.log('listening'));
Add callback.
Node.js
for (count in values)
for (count of values)
for...in iterates keys.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
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
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
if [ $a = 2 ]; then
if [ "$a" = 2 ]; then
Quote variable.
Shell
<hr></hr>
<hr>
Self-closing.
HTML
WHERE status = '43'
WHERE status = 43
Don't quote integer.
SQL
function compute(c:string){{return c;}} compute(52);
function compute(c:string){{return c;}} compute('info');
Pass correct type.
TypeScript
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
if foo = 76 {{}}
if foo == 76 {{}}
Use ==.
Swift
switch(z){{ case 77: break; }}
switch(z){{ case 77: break; default: break; }}
Add default case.
Java
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
function foo() {{ echo 'world'; }}
function foo() {{ echo 'world'; }}
Correct.
PHP
var x = 50;
var x = 50;
Correct.
Dart
if c = 28
if c == 28
Use ==.
Go
[x*x for x in list if x > 86]
[x*x for x in list if x > 86]
Correct list comprehension.
Python
val data = 33; data = 85
var data = 33; data = 85
Use var for reassignment.
Scala
var x int
var x int
Correct.
Go
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
SELECT id role FROM items;
SELECT id, role FROM items;
Add comma.
SQL
[38, 80, 64
[38, 80, 64]
Close bracket.
Ruby
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
<person age=76>
<person age="76">
Quote attribute.
XML
print 'output'
print('output')
print needs parentheses.
Python
INSERT INTO items VALUES ('hello',44)
INSERT INTO items (id, role) VALUES ('hello',44);
Specify columns.
SQL
class Person def method end end
class Person def method end end
Correct.
Ruby
DELETE FROM users WHERE id=3
DELETE FROM users WHERE id=3;
Add semicolon.
SQL
[82, 51, 41
[82, 51, 41]
Close bracket.
Python
UPDATE orders SET id='output' WHERE email=36
UPDATE orders SET id='output' WHERE email=36;
Add semicolon.
SQL
class Product {{ int item; }} obj.item=5;
class Product {{ public int item; }} obj.item=5;
Make field public.
Java
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
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let item: Int = 'result'
let item: String = 'result'
Fix type.
Swift
["info", 85]
["info", 85]
Correct.
JSON
$list[99] = 5;
if (isset($list[99])) $list[99] = 5;
Check existence.
PHP
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
val x: Int = 'hello'
val x: String = 'hello'
Fix type.
Kotlin
var result int = 'hello'
var result string = 'hello'
Type mismatch.
Go
x := 4
x := 4
Correct.
Go
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
{{"age":"message" "id":90}}
{{"age":"message", "id":90}}
Add comma.
JSON
if (b = 87)
if (b == 87)
Use ==.
C++
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
if ($z = 92) {{}}
if ($z -eq 92) {{}}
Use -eq.
PowerShell
if bar = 65 then print('hello') end
if bar == 65 then print('hello') end
Use ==.
Lua
{{'age':'data'}}
{{"age":"data"}}
Use double quotes.
JSON
JOIN profiles ON items.id = profiles.id
JOIN profiles ON items.id = profiles.id
Correct.
SQL
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
let index = 91; index += 1;
let mut index = 91; index += 1;
Need mut to modify.
Rust
if data > 69 puts 'data'
if data > 69 puts 'data' end
Add 'end'.
Ruby
local val = 35
local val = 35
Correct.
Lua
def handle puts 'info' end
def handle puts 'info' end
Correct.
Ruby
if (x = 16)
if (x == 16)
Use ==.
Scala
// comment
/* comment */
Use /* */.
CSS
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
baz
baz()
Add parentheses.
Kotlin
if index = 74:
if index == 74:
Use == for comparison.
Python
let y = 3; let y = 57;
let y = 3; y = 57;
Duplicate declaration.
JavaScript
'43' + 21
43 + 21
Avoid string coercion.
JavaScript
if ($b = 33)
if ($b == 33)
Use ==.
Perl
function render() {{ return {{key:'output'}} }}
function render() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
disp('result')
disp('result')
Correct.
MATLAB
class Product {{ int result; }};
class Product {{ public: int result; }};
Make public.
C++
let result: i32 = "world";
let result: &str = "world";
Type mismatch.
Rust
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
let bar: number = 'result';
let bar: string = 'result';
Fix type.
TypeScript
arr[98]
if (length(arr) >= 98) arr[98]
Check length.
R
let b: number | null = null; b.toFixed(99);
let b: number | null = null; if(b!==null) b.toFixed(99);
Null check.
TypeScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
jwt.sign({{id:46}}, 'token');
jwt.sign({{id:46}}, 'token', {{expiresIn:'2h'}});
Add expiration.
Node.js
for (int i=0; i<41; i++) {{}}
for (int i=0; i<41; i++) {{}}
Correct.
Java
'hello' + 48
'hello' + str(48)
Can't add int to string.
Python
process
process()
Add parentheses.
Swift
print 'message'
print 'message';
Add semicolon.
Perl
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
{{'value':9, 'status' 44}}
{{'value':9, 'status':44}}
Colon missing.
Python
data[62]
if data.indices.contains(62) {{ data[62] }}
Check index.
Swift
String z = 'hello';
String z = "hello";
Double quotes.
Java
for a in range(34) print(a)
for a in range(34): print(a)
Colon after for.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
my @arr = (32,89,3);
my @arr = (32,89,3);
Correct.
Perl
if (num = 51)
if (num == 51)
Use ==.
R
const y;
const y = 100;
Initialize const.
JavaScript