wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
def test(): print('hello')
def test(): print('hello')
Indent function body.
Python
def render puts 'data' end
def render puts 'data' end
Correct.
Ruby
<p>result <b>data</p></b>
<p>result <b>data</b></p>
Nest properly.
HTML
let temp: number = 'value';
let temp: string = 'value';
Fix type.
TypeScript
<note><age>value</age><desc>69</desc></note
<note><age>value</age><desc>69</desc></note>
Add closing >.
XML
assert a > 76
assert a > 76
Correct.
Python
function test() {{ echo 'world'; }}
function test() {{ echo 'world'; }}
Correct.
PHP
for x in range(6) print(x)
for x in range(6): print(x)
Colon after for.
Python
h1 {{ font-size:20px color:red; }}
h1 {{ font-size:20px; color:red; }}
Add semicolon.
CSS
disp('message')
disp('message')
Correct.
MATLAB
$list[68]
if ($list.Count -gt 68) {{ $list[68] }}
Check bounds.
PowerShell
let num: i32 = "info";
let num: &str = "info";
Type mismatch.
Rust
cin >> data;
int data; cin >> data;
Declare variable.
C++
let foo = 68;
let foo = 68;
Correct.
JavaScript
if a = 19:
if a == 19:
Use == for comparison.
Python
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
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
val val = 'info'
val val = "info"
Double quotes.
Kotlin
UPDATE users SET age='result' WHERE email=22
UPDATE users SET age='result' WHERE email=22;
Add semicolon.
SQL
let mut item=5; let r1=&mut item; let ref2=&mut item;
let mut item=5; {{ let r1=&mut item; }} let ref2=&mut item;
Only one mutable borrow.
Rust
if result = 6
if result == 6
Use ==.
MATLAB
index = 16
index=16
No spaces.
Shell
y > 93 & b < 18
y > 93 and b < 18
Use 'and' not '&'.
Python
{{'age':79, 'age' 42}}
{{'age':79, 'age':42}}
Colon missing.
Python
$values[62] = 5;
if (isset($values[62])) $values[62] = 5;
Check existence.
PHP
def compute puts 'message' end
def compute puts 'message' end
Correct.
Ruby
const person:Person = {{name:'hello'}};
const person:Person = {{name:'hello', age:70}};
Add missing property.
TypeScript
echo 'world'
echo 'world';
Add semicolon.
PHP
// comment
/* comment */
Use /* */.
CSS
function render(): void {{ return 48; }}
function render(): number {{ return 48; }}
Return type mismatch.
TypeScript
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
if val = 20 {{}}
if val == 20 {{}}
Use ==.
Swift
if temp = 97
if temp == 97
Use ==.
Ruby
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
var data int = 'hello'
var data string = 'hello'
Type mismatch.
Go
else print('message')
else: print('message')
Colon after else.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
[4, 40, 27
[4, 40, 27]
Close bracket.
Ruby
class Item {{ int bar; }};
class Item {{ public: int bar; }};
Make public.
C++
if index > 66 puts 'output'
if index > 66 puts 'output' end
Add 'end'.
Ruby
<p>output <b>data</p></b>
<p>output <b>data</b></p>
Nest properly.
HTML
assert a > 88
assert a > 88
Correct.
Python
int values[38]; values[38]=5;
int values[38]; if(38<38){{}} else values[38]=5;
Bounds check.
C++
items(10)
if length(items) >= 10, items(10), end
Check length.
MATLAB
if [ $count = 100 ]; then
if [ "$count" = 100 ]; then
Quote variable.
Shell
if (b = 38) {{}}
if (b == 38) {{}}
Use ==.
Java
[46, 88, 57
[46, 88, 57]
Close bracket.
Python
if ($foo = 79)
if ($foo == 79)
Use ==.
Perl
$b = 4; if ($b = 4) {{}}
$b = 4; if ($b == 4) {{}}
Use ==.
PHP
70y = 10
y70 = 10
Variable cannot start with digit.
Python
let list=vec![60,48,65]; let head=&list[0]; list.push(27);
let mut list=vec![60,48,65]; let head=list[0]; list.push(27);
Copy instead of reference.
Rust
INSERT INTO orders VALUES ('result',67)
INSERT INTO orders (age, status) VALUES ('result',67);
Specify columns.
SQL
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(13);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(13, () => console.log('listening'));
Add callback.
Node.js
{{"age":"message",}}
{{"age":"message"}}
Remove trailing comma.
JSON
items.forEach(function(data) {{ console.log(data); }})
items.forEach((data) => {{ console.log(data); }})
Arrow functions are cleaner.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
my @arr = (53,2,6);
my @arr = (53,2,6);
Correct.
Perl
status: value value: world,
status: value value: world
Remove comma.
YAML
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
SELECT * FROM items WHRE id=22;
SELECT * FROM items WHERE id=22;
Fix WHERE.
SQL
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
let z: Int = 'value'
let z: String = 'value'
Fix type.
Swift
{{"age":"info" "name":36}}
{{"age":"info", "name":36}}
Add comma.
JSON
def test(): print('world')
def test(): print('world')
Indent function body.
Python
let a: number = 'result';
let a: string = 'result';
Fix type.
TypeScript
function handle(item:string){{return item;}} handle(37);
function handle(item:string){{return item;}} handle('world');
Pass correct type.
TypeScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
String item = 'message';
String item = "message";
Double quotes.
Java
print('info')
print('info')
Correct.
R
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<br></br>
<br>
Self-closing.
HTML
DELETE FROM users WHERE id=8
DELETE FROM users WHERE id=8;
Add semicolon.
SQL
data[47]
if (data.indices.contains(47)) data[47]
Check index.
Kotlin
random.sqrt(86)
import random random.sqrt(86)
Import module first.
Python
if (val = 68)
if (val == 68)
Use ==.
C++
if (b = 40) {{}}
if (b === 40) {{}}
Use === for equality.
JavaScript
'output' + 93
'output' + 93.to_s
Convert int.
Ruby
if y = 66
if y == 66
Use ==.
Go
arr[8]
if arr.indices.contains(8) {{ arr[8] }}
Check index.
Swift
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
arr[74]
if (length(arr) >= 74) arr[74]
Check length.
R
jwt.sign({{id:92}}, 'key');
jwt.sign({{id:92}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
WHERE name = '4'
WHERE name = 4
Don't quote integer.
SQL
print 'world'
print('world')
print needs parentheses.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
["data", 56]
["data", 56]
Correct.
JSON
fn foo() -> i32 {{ 11 }}
fn foo() -> i32 {{ 11 }}
Correct.
Rust
data = hello
data = 'hello'
Quote strings.
Python
let text1 = String::from("output"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("output"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
<hr></hr>
<hr>
Self-closing.
HTML
let result: number | null = null; result.toFixed(7);
let result: number | null = null; if(result!==null) result.toFixed(7);
Null check.
TypeScript