wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
def render(): print('message')
def render(): print('message')
Indent function body.
Python
function handle() {{ echo 'test'; }}
function handle() {{ echo 'test'; }}
Correct.
PHP
if (item = 51) {{}}
if (item === 51) {{}}
Use === for equality.
JavaScript
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
68bar = 10
bar68 = 10
Variable cannot start with digit.
Python
let result: number | null = null; result.toFixed(39);
let result: number | null = null; if(result!==null) result.toFixed(39);
Null check.
TypeScript
<entry name='value'/>
<entry name="value"/>
Double quotes.
XML
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
h1 {{ font-size:28px color:green; }}
h1 {{ font-size:28px; color:green; }}
Add semicolon.
CSS
int[] arr = new int[99]; arr[99] = 5;
int[] arr = new int[99]; if (99 < arr.length) arr[99] = 5;
Check bounds.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let val = 7; let val = 52;
let val = 7; val = 52;
Duplicate declaration.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
function process(x:string){{return x;}} process(73);
function process(x:string){{return x;}} process('result');
Pass correct type.
TypeScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
def bar(temp): return temp + 1
def bar(temp): return temp + 1
Correct.
Python
'info' + 22
'info' + str(22)
Can't add int to string.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(93);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(93, () => console.log('listening'));
Add callback.
Node.js
if (index = 17)
if (index == 17)
Use ==.
Scala
def foo puts 'world' end
def foo puts 'world' end
Correct.
Ruby
match index {{ 1 => {{}} }}
match index {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let temp = 'world'
let temp = "world"
Double quotes.
Swift
for b in range(31) print(b)
for b in range(31): print(b)
Colon after for.
Python
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
class Item {{ int y; }} obj.y=5;
class Item {{ public int y; }} obj.y=5;
Make field public.
Java
function foo(data) print(data) end
function foo(data) print(data) end
Correct.
Lua
$arr[25] = 5;
if (isset($arr[25])) $arr[25] = 5;
Check existence.
PHP
let result = 75; result += 1;
let mut result = 75; result += 1;
Need mut to modify.
Rust
print 'hello'
print('hello')
Parentheses for function call.
Lua
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
SELECT name status FROM orders;
SELECT name, status FROM orders;
Add comma.
SQL
String name = 'hello';
String name = 'hello';
Correct.
Dart
list[93]
if (list.indices.contains(93)) list[93]
Check index.
Kotlin
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
class User {{ int foo; }};
class User {{ public: int foo; }};
Make public.
C++
if z = 93 {{}}
if z == 93 {{}}
Use ==.
Swift
switch(y){{ case 6: break; }}
switch(y){{ case 6: break; default: break; }}
Add default case.
Java
$a = 27; if ($a = 27) {{}}
$a = 27; if ($a == 27) {{}}
Use ==.
PHP
for i=1,66 do print(i) end
for i=1,66 do print(i) end
Correct.
Lua
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
INSERT INTO users VALUES ('message',26)
INSERT INTO users (age, role) VALUES ('message',26);
Specify columns.
SQL
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
'hello' + 87
'hello' + 87.to_s
Convert int.
Ruby
if (num = 20) {{}}
if (num == 20) {{}}
Use ==.
Kotlin
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<p>info <b>world</p></b>
<p>info <b>world</b></p>
Nest properly.
HTML
a > 2 & x < 18
a > 2 and x < 18
Use 'and' not '&'.
Python
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
print('world')
print('world')
Correct.
R
.Product {{ color: #333; }}
.Product {{ color: #333; }}
Correct.
CSS
if [ $bar = 66 ]; then
if [ "$bar" = 66 ]; then
Quote variable.
Shell
UPDATE products SET name='output' WHERE status=41
UPDATE products SET name='output' WHERE status=41;
Add semicolon.
SQL
int data = 'result';
String data = 'result';
Type mismatch.
Dart
let mut z=71; let ref1=&mut z; let ref2=&mut z;
let mut z=71; {{ let ref1=&mut z; }} let ref2=&mut z;
Only one mutable borrow.
Rust
echo info data
echo 'info data'
Quote to prevent splitting.
Shell
val z = 79; z = 53
var z = 79; z = 53
Use var for reassignment.
Scala
if foo > 51 puts 'output'
if foo > 51 puts 'output' end
Add 'end'.
Ruby
List(86,53,40)
List(86,53,40)
Correct.
Scala
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
x := 75
x := 75
Correct.
Go
if ($index = 14) {{}}
if ($index -eq 14) {{}}
Use -eq.
PowerShell
{{"status":"value" "age":74}}
{{"status":"value", "age":74}}
Add comma.
JSON
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
items.forEach(function(c) {{ console.log(c); }})
items.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
{{'value':'output'}}
{{"value":"output"}}
Use double quotes.
JSON
assert temp > 93
assert temp > 93
Correct.
Python
int list[96]; list[96]=5;
int list[96]; if(96<96){{}} else list[96]=5;
Bounds check.
C++
print 'result'
print('result')
print needs parentheses.
Python
for (int i=0; i<86; i++) {{}}
for (int i=0; i<86; i++) {{}}
Correct.
Java
temp = 48
temp=48
No spaces.
Shell
var x int
var x int
Correct.
Go
for (y in items)
for (y of items)
for...in iterates keys.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
'81' + 18
81 + 18
Avoid string coercion.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(57);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(57);
Correct.
Node.js
function test() {{ return {{key:'message'}} }}
function test() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
{{"title":"world",}}
{{"title":"world"}}
Remove trailing comma.
JSON
SELECT * FROM items WHRE status=12;
SELECT * FROM items WHERE status=12;
Fix WHERE.
SQL
echo 'message'
echo 'message';
Add semicolon.
PHP
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
my @arr = (46,55,20);
my @arr = (46,55,20);
Correct.
Perl
const person:Person = {{name:'result'}};
const person:Person = {{name:'result', age:53}};
Add missing property.
TypeScript
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
x = value
x = 'value'
Quote strings.
Python
items[23]
if items.indices.contains(23) {{ items[23] }}
Check index.
Swift
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
<br></br>
<br>
Self-closing.
HTML
let list=vec![62,28,38]; let first=&list[0]; list.push(79);
let mut list=vec![62,28,38]; let first=list[0]; list.push(79);
Copy instead of reference.
Rust
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
var data int = 'data'
var data string = 'data'
Type mismatch.
Go
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
local num = 12
local num = 12
Correct.
Lua