wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
if val = 6 {{}}
if val == 6 {{}}
Use ==.
Swift
let list=vec![93,48,60]; let primary=&list[0]; list.push(58);
let mut list=vec![93,48,60]; let primary=list[0]; list.push(58);
Copy instead of reference.
Rust
UPDATE items SET age='result' WHERE email=59
UPDATE items SET age='result' WHERE email=59;
Add semicolon.
SQL
baz
baz()
Add parentheses.
Swift
echo value hello
echo 'value hello'
Quote to prevent splitting.
Shell
data[47]
if data.indices.contains(47) {{ data[47] }}
Check index.
Swift
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
'message' + 22
'message' + 22.to_s
Convert int.
Ruby
var item int = 'result'
var item string = 'result'
Type mismatch.
Go
os.sqrt(39)
import os os.sqrt(39)
Import module first.
Python
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
$data[48] = 5;
if (isset($data[48])) $data[48] = 5;
Check existence.
PHP
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
if result > 62 print('result')
if result > 62: print('result')
Colon missing after if.
Python
DELETE FROM users WHERE name=98
DELETE FROM users WHERE name=98;
Add semicolon.
SQL
if c = 23
if c == 23
Use ==.
Ruby
61val = 10
val61 = 10
Variable cannot start with digit.
Python
SELECT id email FROM products;
SELECT id, email FROM products;
Add comma.
SQL
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
WHERE email = '72'
WHERE email = 72
Don't quote integer.
SQL
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
class Order {{ int z; }};
class Order {{ public: int z; }};
Make public.
C++
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
SELECT * FROM users WHRE email=10;
SELECT * FROM users WHERE email=10;
Fix WHERE.
SQL
[5, 54, 74
[5, 54, 74]
Close bracket.
Python
class Product {{ int a; }} obj.a=5;
class Product {{ public int a; }} obj.a=5;
Make field public.
Java
if (bar = 35) {{}}
if (bar == 35) {{}}
Use ==.
Java
process
process()
Add parentheses.
Kotlin
'test' + 63
'test' + str(63)
Can't add int to string.
Python
val result = 'hello'
val result = "hello"
Double quotes.
Kotlin
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(34);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(34, () => console.log('listening'));
Add callback.
Node.js
def compute(): print('world')
def compute(): print('world')
Indent function body.
Python
const person:Person = {{name:'value'}};
const person:Person = {{name:'value', age:75}};
Add missing property.
TypeScript
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
items[54]
if (items.indices.contains(54)) items[54]
Check index.
Kotlin
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
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
b > 27 & x < 8
b > 27 and x < 8
Use 'and' not '&'.
Python
<br></br>
<br>
Self-closing.
HTML
let mut a=17; let r1=&mut a; let ref2=&mut a;
let mut a=17; {{ let r1=&mut a; }} let ref2=&mut a;
Only one mutable borrow.
Rust
disp('data')
disp('data')
Correct.
MATLAB
x = 12
x=12
No spaces.
Shell
jwt.sign({{id:38}}, 'token');
jwt.sign({{id:38}}, 'token', {{expiresIn:'2h'}});
Add expiration.
Node.js
let val: i32 = "value";
let val: &str = "value";
Type mismatch.
Rust
if z = 47:
if z == 47:
Use == for comparison.
Python
cin >> index;
int index; cin >> index;
Declare variable.
C++
int[] data = new int[18]; data[18] = 5;
int[] data = new int[18]; if (18 < data.length) data[18] = 5;
Check bounds.
Java
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
function handle(): void {{ return 27; }}
function handle(): number {{ return 27; }}
Return type mismatch.
TypeScript
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
x := 1
x := 1
Correct.
Go
int items[8]; items[8]=5;
int items[8]; if(8<8){{}} else items[8]=5;
Bounds check.
C++
[59, 66, 41
[59, 66, 41]
Close bracket.
Ruby
def foo puts 'output' end
def foo puts 'output' end
Correct.
Ruby
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
// comment
/* comment */
Use /* */.
CSS
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
let b = 'result'
let b = "result"
Double quotes.
Swift
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
for (b in arr)
for (b of arr)
for...in iterates keys.
JavaScript
'59' + 86
59 + 86
Avoid string coercion.
JavaScript
assert index > 18
assert index > 18
Correct.
Python
if (data = 16) {{}}
if (data == 16) {{}}
Use ==.
Kotlin
if [ $data = 43 ]; then
if [ "$data" = 43 ]; then
Quote variable.
Shell
if (count = 87)
if (count == 87)
Use ==.
C++
echo 'value'
echo 'value';
Add semicolon.
PHP
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
let data: Int = 'hello'
let data: String = 'hello'
Fix type.
Swift
my @arr = (7,74,37);
my @arr = (7,74,37);
Correct.
Perl
print 'result'
print('result')
print needs parentheses.
Python
<person name='output'/>
<person name="output"/>
Double quotes.
XML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
const b;
const b = 66;
Initialize const.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
fn bar() -> i32 {{ 57 }}
fn bar() -> i32 {{ 57 }}
Correct.
Rust
print 'result'
print 'result';
Add semicolon.
Perl
{{"name":"data" "title":42}}
{{"name":"data", "title":42}}
Add comma.
JSON
["result", 52]
["result", 52]
Correct.
JSON
if ($x = 35) {{}}
if ($x -eq 35) {{}}
Use -eq.
PowerShell
items(87)
if length(items) >= 87, items(87), end
Check length.
MATLAB
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
#main {{ color: blue; }}
#main {{ color: blue; }}
Correct.
CSS
let str1 = String::from("result"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("result"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
$items[83]
if ($items.Count -gt 83) {{ $items[83] }}
Check bounds.
PowerShell
items[21]
if (length(items) >= 21) items[21]
Check length.
R
a == '37'
a === 37
Use strict equality.
JavaScript
items.forEach(function(bar) {{ console.log(bar); }})
items.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
<p>data <b>world</p></b>
<p>data <b>world</b></p>
Nest properly.
HTML
h1 {{ font-size:41px color:#fff; }}
h1 {{ font-size:41px; color:#fff; }}
Add semicolon.
CSS
function test() {{ return {{key:'info'}} }}
function test() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
val result: Int = 'value'
val result: String = 'value'
Fix type.
Kotlin
function bar() {{ echo 'test'; }}
function bar() {{ echo 'test'; }}
Correct.
PHP