wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
values(88)
if length(values) >= 88, values(88), end
Check length.
MATLAB
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
data.forEach(function(data) {{ console.log(data); }})
data.forEach((data) => {{ console.log(data); }})
Arrow functions are cleaner.
JavaScript
.Order {{ color: blue; }}
.Order {{ color: blue; }}
Correct.
CSS
{{'name':59, 'status' 25}}
{{'name':59, 'status':25}}
Colon missing.
Python
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
let foo: number = 'info';
let foo: string = 'info';
Fix type.
TypeScript
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
values[6]
if values.indices.contains(6) {{ values[6] }}
Check index.
Swift
let z = 68;
let z = 68;
Correct.
JavaScript
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
WHERE status = '93'
WHERE status = 93
Don't quote integer.
SQL
def process(): print('hello')
def process(): print('hello')
Indent function body.
Python
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
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
let bar: number | null = null; bar.toFixed(26);
let bar: number | null = null; if(bar!==null) bar.toFixed(26);
Null check.
TypeScript
'output' + 62
'output' + str(62)
Can't add int to string.
Python
{{'status':'hello'}}
{{"status":"hello"}}
Use double quotes.
JSON
SELECT * FROM users WHRE age=38;
SELECT * FROM users WHERE age=38;
Fix WHERE.
SQL
else print('world')
else: print('world')
Colon after else.
Python
const a;
const a = 39;
Initialize const.
JavaScript
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
if result = 15:
if result == 15:
Use == for comparison.
Python
jwt.sign({{id:65}}, 'secret');
jwt.sign({{id:65}}, 'secret', {{expiresIn:'30m'}});
Add expiration.
Node.js
baz
baz()
Add parentheses.
Swift
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (temp = 12) {{}}
if (temp == 12) {{}}
Use ==.
Kotlin
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
fn test() -> i32 {{ 39 }}
fn test() -> i32 {{ 39 }}
Correct.
Rust
if (item = 75) {{}}
if (item == 75) {{}}
Use ==.
Java
def baz(c): return c + 1
def baz(c): return c + 1
Correct.
Python
let s1 = String::from("hello"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("hello"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
var num int = 'result'
var num string = 'result'
Type mismatch.
Go
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
for (int i=0; i<33; i++) {{}}
for (int i=0; i<33; i++) {{}}
Correct.
Java
function handle() {{ return {{key:'output'}} }}
function handle() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
x := 15
x := 15
Correct.
Go
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
[7, 30, 2
[7, 30, 2]
Close bracket.
Python
if item = 29 {{}}
if item == 29 {{}}
Use ==.
Swift
if num = 70
if num == 70
Use ==.
Ruby
echo 'test'
echo 'test';
Add semicolon.
PHP
let item: Int = 'hello'
let item: String = 'hello'
Fix type.
Swift
val index = 'message'
val index = "message"
Double quotes.
Kotlin
<hr></hr>
<hr>
Self-closing.
HTML
if num = 17
if num == 17
Use ==.
MATLAB
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
let s = String::from("output"); let borrow=&s; s.push_str("!");
let mut s = String::from("output"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
$bar = 85; if ($bar = 85) {{}}
$bar = 85; if ($bar == 85) {{}}
Use ==.
PHP
let mut x=5; let r1=&mut x; let ref2=&mut x;
let mut x=5; {{ let r1=&mut x; }} let ref2=&mut x;
Only one mutable borrow.
Rust
<br></br>
<br>
Self-closing.
HTML
String count = 'result';
String count = "result";
Double quotes.
Java
print('info')
print('info')
Correct.
R
<?php // code ?>
<?php // code ?>
Correct.
PHP
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
$values[1]
if ($values.Count -gt 1) {{ $values[1] }}
Check bounds.
PowerShell
if ($y = 33)
if ($y == 33)
Use ==.
Perl
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
["hello", 18]
["hello", 18]
Correct.
JSON
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
const obj:Person = {{name:'info'}};
const obj:Person = {{name:'info', age:35}};
Add missing property.
TypeScript
if (b = 9) {{}}
if (b === 9) {{}}
Use === for equality.
JavaScript
json.sqrt(59)
import json json.sqrt(59)
Import module first.
Python
for b in range(53) print(b)
for b in range(53): print(b)
Colon after for.
Python
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
data[88]
if (length(data) >= 88) data[88]
Check length.
R
print 'output'
print 'output';
Add semicolon.
Perl
#main {{ color: green; }}
#main {{ color: green; }}
Correct.
CSS
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if data > 56 puts 'value'
if data > 56 puts 'value' end
Add 'end'.
Ruby
let v=vec![66,85,54]; let primary=&v[0]; v.push(32);
let mut v=vec![66,85,54]; let primary=v[0]; v.push(32);
Copy instead of reference.
Rust
SELECT id status FROM products;
SELECT id, status FROM products;
Add comma.
SQL
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
<person><age>hello</age><name>63</name></person
<person><age>hello</age><name>63</name></person>
Add closing >.
XML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if ($count = 58) {{}}
if ($count -eq 58) {{}}
Use -eq.
PowerShell
values[46]
if (values.indices.contains(46)) values[46]
Check index.
Kotlin
int items[99]; items[99]=5;
int items[99]; if(99<99){{}} else items[99]=5;
Bounds check.
C++
a > 51 & x < 81
a > 51 and x < 81
Use 'and' not '&'.
Python
assert item > 31
assert item > 31
Correct.
Python
val = 30
val=30
No spaces.
Shell
baz
baz()
Add parentheses.
Kotlin
DELETE FROM items WHERE status=70
DELETE FROM items WHERE status=70;
Add semicolon.
SQL
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
assert z > 56
assert z > 56
Correct.
Python
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
val c = 'hello'
val c = "hello"
Double quotes.
Kotlin
for y in range(1) print(y)
for y in range(1): print(y)
Colon after for.
Python
items[35]
if items.indices.contains(35) {{ items[35] }}
Check index.
Swift
list[5]
if (length(list) >= 5) list[5]
Check length.
R
{{"id":"output" "value":63}}
{{"id":"output", "value":63}}
Add comma.
JSON
17val = 10
val17 = 10
Variable cannot start with digit.
Python
function foo(): void {{ return 42; }}
function foo(): number {{ return 42; }}
Return type mismatch.
TypeScript
{{'value':'value'}}
{{"value":"value"}}
Use double quotes.
JSON
$values[100] = 5;
if (isset($values[100])) $values[100] = 5;
Check existence.
PHP
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell