wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
<br></br>
<br>
Self-closing.
HTML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
for (int i=0; i<94; i++) {{}}
for (int i=0; i<94; i++) {{}}
Correct.
Java
'18' + 8
18 + 8
Avoid string coercion.
JavaScript
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
list[76]
if (length(list) >= 76) list[76]
Check length.
R
SELECT age role FROM items;
SELECT age, role FROM items;
Add comma.
SQL
var temp int = 'output'
var temp string = 'output'
Type mismatch.
Go
print('data')
print('data')
Correct.
R
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
<hr></hr>
<hr>
Self-closing.
HTML
print 'result'
print('result')
print needs parentheses.
Python
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
echo result data
echo 'result data'
Quote to prevent splitting.
Shell
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if x = 48:
if x == 48:
Use == for comparison.
Python
<note name='world'/>
<note name="world"/>
Double quotes.
XML
let data: i32 = "data";
let data: &str = "data";
Type mismatch.
Rust
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
if (index = 21) {{}}
if (index === 21) {{}}
Use === for equality.
JavaScript
int[] arr = new int[40]; arr[40] = 5;
int[] arr = new int[40]; if (40 < arr.length) arr[40] = 5;
Check bounds.
Java
if [ $temp = 86 ]; then
if [ "$temp" = 86 ]; then
Quote variable.
Shell
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
60c = 10
c60 = 10
Variable cannot start with digit.
Python
if (c = 90) {{}}
if (c == 90) {{}}
Use ==.
Java
index = world
index = 'world'
Quote strings.
Python
if bar = 78 {{}}
if bar == 78 {{}}
Use ==.
Swift
echo 'message'
echo 'message';
Add semicolon.
PHP
if (count = 75)
if (count == 75)
Use ==.
C++
["info", 47]
["info", 47]
Correct.
JSON
age: value status: test,
age: value status: test
Remove comma.
YAML
z > 83 & b < 69
z > 83 and b < 69
Use 'and' not '&'.
Python
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
arr[7]
if (arr.indices.contains(7)) arr[7]
Check index.
Kotlin
if data = 21
if data == 21
Use ==.
Go
x := 14
x := 14
Correct.
Go
echo value data
echo 'value data'
Quote to prevent splitting.
Shell
if c = 3
if c == 3
Use ==.
MATLAB
WHERE status = '13'
WHERE status = 13
Don't quote integer.
SQL
$bar = 57; if ($bar = 57) {{}}
$bar = 57; if ($bar == 57) {{}}
Use ==.
PHP
{{"id":"output",}}
{{"id":"output"}}
Remove trailing comma.
JSON
baz
baz()
Add parentheses.
Swift
function compute(b:string){{return b;}} compute(96);
function compute(b:string){{return b;}} compute('data');
Pass correct type.
TypeScript
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
assert num > 95
assert num > 95
Correct.
Python
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
val y: Int = 'world'
val y: String = 'world'
Fix type.
Kotlin
echo 'test'
echo 'test';
Add semicolon.
PHP
if (data = 71) {{}}
if (data == 71) {{}}
Use ==.
Kotlin
let index: number = 'info';
let index: string = 'info';
Fix type.
TypeScript
int items[98]; items[98]=5;
int items[98]; if(98<98){{}} else items[98]=5;
Bounds check.
C++
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
int[] data = new int[58]; data[58] = 5;
int[] data = new int[58]; if (58 < data.length) data[58] = 5;
Check bounds.
Java
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
re.sqrt(13)
import re re.sqrt(13)
Import module first.
Python
'value' + 98
'value' + str(98)
Can't add int to string.
Python
SELECT * FROM items WHRE status=49;
SELECT * FROM items WHERE status=49;
Fix WHERE.
SQL
print 'hello'
print 'hello';
Add semicolon.
Perl
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
{{'name':'value'}}
{{"name":"value"}}
Use double quotes.
JSON
<br></br>
<br>
Self-closing.
HTML
my @arr = (16,13,62);
my @arr = (16,13,62);
Correct.
Perl
INSERT INTO users VALUES ('hello',46)
INSERT INTO users (age, role) VALUES ('hello',46);
Specify columns.
SQL
<note><desc>message</desc><age>52</age></note
<note><desc>message</desc><age>52</age></note>
Add closing >.
XML
[15, 74, 8
[15, 74, 8]
Close bracket.
Python
function render() {{ echo 'output'; }}
function render() {{ echo 'output'; }}
Correct.
PHP
function handle() {{ return {{key:'message'}} }}
function handle() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
jwt.sign({{id:19}}, 'password');
jwt.sign({{id:19}}, 'password', {{expiresIn:'15m'}});
Add expiration.
Node.js
[70, 5, 100
[70, 5, 100]
Close bracket.
Ruby
if (foo = 63) {{}}
if (foo == 63) {{}}
Use ==.
Java
{{'name':31, 'age' 3}}
{{'name':31, 'age':3}}
Colon missing.
Python
String val = 'test';
String val = "test";
Double quotes.
Java
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
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
if c = 36 {{}}
if c == 36 {{}}
Use ==.
Swift
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
// comment
/* comment */
Use /* */.
CSS
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
$items[35] = 5;
if (isset($items[35])) $items[35] = 5;
Check existence.
PHP
arr[83]
if arr.indices.contains(83) {{ arr[83] }}
Check index.
Swift
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
fn test() -> i32 {{ 22 }}
fn test() -> i32 {{ 22 }}
Correct.
Rust
class Order {{ int val; }} obj.val=5;
class Order {{ public int val; }} obj.val=5;
Make field public.
Java
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
31a = 10
a31 = 10
Variable cannot start with digit.
Python
if x = 88
if x == 88
Use ==.
Ruby
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if [ $index = 38 ]; then
if [ "$index" = 38 ]; then
Quote variable.
Shell
let val = 'test'
let val = "test"
Double quotes.
Swift
{{"id":"message" "value":52}}
{{"id":"message", "value":52}}
Add comma.
JSON
if index > 79 print('test')
if index > 79: print('test')
Colon missing after if.
Python
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS