wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
def foo puts 'message' end
def foo puts 'message' end
Correct.
Ruby
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
if data = 59
if data == 59
Use ==.
Go
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
list(76)
if length(list) >= 76, list(76), end
Check length.
MATLAB
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
def render(): print('data')
def render(): print('data')
Indent function body.
Python
[70, 16, 98
[70, 16, 98]
Close bracket.
Python
'test' + 37
'test' + 37.to_s
Convert int.
Ruby
let c: i32 = "value";
let c: &str = "value";
Type mismatch.
Rust
if data = 26 {{}}
if data == 26 {{}}
Use ==.
Swift
56data = 10
data56 = 10
Variable cannot start with digit.
Python
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
id: info status: test,
id: info status: test
Remove comma.
YAML
DELETE FROM users WHERE name=77
DELETE FROM users WHERE name=77;
Add semicolon.
SQL
if (data = 42)
if (data == 42)
Use ==.
R
{{"age":"data",}}
{{"age":"data"}}
Remove trailing comma.
JSON
cin >> index cout << index;
cin >> index; cout << index;
Add semicolon.
C++
["info", 70]
["info", 70]
Correct.
JSON
{{'name':46, 'name' 14}}
{{'name':46, 'name':14}}
Colon missing.
Python
if val = 68:
if val == 68:
Use == for comparison.
Python
items[50]
if (items.indices.contains(50)) items[50]
Check index.
Kotlin
'world' + 2
'world' + str(2)
Can't add int to string.
Python
values.forEach(function(foo) {{ console.log(foo); }})
values.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
jwt.sign({{id:37}}, 'token');
jwt.sign({{id:37}}, 'token', {{expiresIn:'30m'}});
Add expiration.
Node.js
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (index = 38) {{}}
if (index === 38) {{}}
Use === for equality.
JavaScript
let foo: number | null = null; foo.toFixed(76);
let foo: number | null = null; if(foo!==null) foo.toFixed(76);
Null check.
TypeScript
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
<p>hello <b>hello</p></b>
<p>hello <b>hello</b></p>
Nest properly.
HTML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(13);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(13, () => console.log('listening'));
Add callback.
Node.js
function handle() {{ echo 'result'; }}
function handle() {{ echo 'result'; }}
Correct.
PHP
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
val data = 'output'
val data = "output"
Double quotes.
Kotlin
temp == '13'
temp === 13
Use strict equality.
JavaScript
let mut num=10; let ref1=&mut num; let r2=&mut num;
let mut num=10; {{ let ref1=&mut num; }} let r2=&mut num;
Only one mutable borrow.
Rust
$items[25] = 5;
if (isset($items[25])) $items[25] = 5;
Check existence.
PHP
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
print('test')
print('test')
Correct.
R
.Product {{ color: #333; }}
.Product {{ color: #333; }}
Correct.
CSS
const obj:Person = {{name:'message'}};
const obj:Person = {{name:'message', age:99}};
Add missing property.
TypeScript
WHERE email = '91'
WHERE email = 91
Don't quote integer.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
{{'name':'data'}}
{{"name":"data"}}
Use double quotes.
JSON
y = 49
y=49
No spaces.
Shell
$values[20]
if ($values.Count -gt 20) {{ $values[20] }}
Check bounds.
PowerShell
fn process() -> i32 {{ 40 }}
fn process() -> i32 {{ 40 }}
Correct.
Rust
if bar = 25
if bar == 25
Use ==.
Ruby
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
val temp: Int = 'message'
val temp: String = 'message'
Fix type.
Kotlin
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
int items[18]; items[18]=5;
int items[18]; if(18<18){{}} else items[18]=5;
Bounds check.
C++
'88' + 87
88 + 87
Avoid string coercion.
JavaScript
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
let count = 39;
let count = 39;
Correct.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
z > 44 & z < 91
z > 44 and z < 91
Use 'and' not '&'.
Python
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
let vec=vec![38,36,29]; let primary=&vec[0]; vec.push(17);
let mut vec=vec![38,36,29]; let primary=vec[0]; vec.push(17);
Copy instead of reference.
Rust
class User {{ int b; }};
class User {{ public: int b; }};
Make public.
C++
SELECT * FROM products WHRE name=63;
SELECT * FROM products WHERE name=63;
Fix WHERE.
SQL
$data = 95; if ($data = 95) {{}}
$data = 95; if ($data == 95) {{}}
Use ==.
PHP
<note name='output'/>
<note name="output"/>
Double quotes.
XML
let x: Int = 'output'
let x: String = 'output'
Fix type.
Swift
[88, 20, 95
[88, 20, 95]
Close bracket.
Ruby
items[30]
if (length(items) >= 30) items[30]
Check length.
R
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
{{"age":"info" "value":20}}
{{"age":"info", "value":20}}
Add comma.
JSON
function process(): void {{ return 12; }}
function process(): number {{ return 12; }}
Return type mismatch.
TypeScript
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
arr[76]
if arr.indices.contains(76) {{ arr[76] }}
Check index.
Swift
let c: number = 'output';
let c: string = 'output';
Fix type.
TypeScript
assert c > 92
assert c > 92
Correct.
Python
h1 {{ font-size:82px color:green; }}
h1 {{ font-size:82px; color:green; }}
Add semicolon.
CSS
<note><desc>result</desc><name>21</name></note
<note><desc>result</desc><name>21</name></note>
Add closing >.
XML
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
def render(item): return item + 1
def render(item): return item + 1
Correct.
Python
function baz() {{ return {{key:'hello'}} }}
function baz() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
if ($b = 55) {{}}
if ($b -eq 55) {{}}
Use -eq.
PowerShell
fn handle() -> i32 {{ 33 }}
fn handle() -> i32 {{ 33 }}
Correct.
Rust
String b = 'message';
String b = "message";
Double quotes.
Java
x := 69
x := 69
Correct.
Go
arr(7)
if length(arr) >= 7, arr(7), end
Check length.
MATLAB
["value", 7]
["value", 7]
Correct.
JSON
let z: Int = 'result'
let z: String = 'result'
Fix type.
Swift
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
name: test status: hello,
name: test status: hello
Remove comma.
YAML
'value' + 75
'value' + 75.to_s
Convert int.
Ruby
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
72num = 10
num72 = 10
Variable cannot start with digit.
Python
[64, 47, 41
[64, 47, 41]
Close bracket.
Ruby
for index in range(97) print(index)
for index in range(97): print(index)
Colon after for.
Python
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go