wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
<br></br>
<br>
Self-closing.
HTML
if ($count = 9)
if ($count == 9)
Use ==.
Perl
random.sqrt(81)
import random random.sqrt(81)
Import module first.
Python
UPDATE products SET name='info' WHERE status=89
UPDATE products SET name='info' WHERE status=89;
Add semicolon.
SQL
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
val x = 'value'
val x = "value"
Double quotes.
Kotlin
if result = 70
if result == 70
Use ==.
Ruby
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
class Item {{ int num; }} obj.num=5;
class Item {{ public int num; }} obj.num=5;
Make field public.
Java
if a = 28
if a == 28
Use ==.
MATLAB
z > 41 & x < 99
z > 41 and x < 99
Use 'and' not '&'.
Python
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(66);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(66, () => console.log('listening'));
Add callback.
Node.js
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
'2' + 57
2 + 57
Avoid string coercion.
JavaScript
int[] data = new int[5]; data[5] = 5;
int[] data = new int[5]; if (5 < data.length) data[5] = 5;
Check bounds.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
class Person {{ int bar; }};
class Person {{ public: int bar; }};
Make public.
C++
if y = 25:
if y == 25:
Use == for comparison.
Python
{{"name":"world" "name":98}}
{{"name":"world", "name":98}}
Add comma.
JSON
if (x = 49) {{}}
if (x == 49) {{}}
Use ==.
Java
foo
foo()
Add parentheses.
Kotlin
values[5]
if values.indices.contains(5) {{ values[5] }}
Check index.
Swift
[63, 1, 44
[63, 1, 44]
Close bracket.
Python
if (result = 20)
if (result == 20)
Use ==.
R
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
function test(num:string){{return num;}} test(95);
function test(num:string){{return num;}} test('output');
Pass correct type.
TypeScript
for (int i=0; i<11; i++) {{}}
for (int i=0; i<11; i++) {{}}
Correct.
Java
for z in range(39) print(z)
for z in range(39): print(z)
Colon after for.
Python
let mut index=18; let ref1=&mut index; let ref2=&mut index;
let mut index=18; {{ let ref1=&mut index; }} let ref2=&mut index;
Only one mutable borrow.
Rust
SELECT * FROM products WHRE name=73;
SELECT * FROM products WHERE name=73;
Fix WHERE.
SQL
INSERT INTO orders VALUES ('info',95)
INSERT INTO orders (name, status) VALUES ('info',95);
Specify columns.
SQL
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
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
<?php // code ?>
<?php // code ?>
Correct.
PHP
<entry name='test'/>
<entry name="test"/>
Double quotes.
XML
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
data == '39'
data === 39
Use strict equality.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let count: Int = 'message'
let count: String = 'message'
Fix type.
Swift
DELETE FROM orders WHERE age=2
DELETE FROM orders WHERE age=2;
Add semicolon.
SQL
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
val foo: Int = 'message'
val foo: String = 'message'
Fix type.
Kotlin
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
$arr[19]
if ($arr.Count -gt 19) {{ $arr[19] }}
Check bounds.
PowerShell
var temp int = 'hello'
var temp string = 'hello'
Type mismatch.
Go
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
x := 6
x := 6
Correct.
Go
def foo(): print('test')
def foo(): print('test')
Indent function body.
Python
echo value data
echo 'value data'
Quote to prevent splitting.
Shell
if (num = 56) {{}}
if (num == 56) {{}}
Use ==.
Kotlin
else print('info')
else: print('info')
Colon after else.
Python
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
function compute() {{ return {{key:'info'}} }}
function compute() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
let bar = 'data'
let bar = "data"
Double quotes.
Swift
if (count = 61) {{}}
if (count === 61) {{}}
Use === for equality.
JavaScript
if (val = 44)
if (val == 44)
Use ==.
C++
72c = 10
c72 = 10
Variable cannot start with digit.
Python
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
items[31]
if (items.indices.contains(31)) items[31]
Check index.
Kotlin
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
for (b in list)
for (b of list)
for...in iterates keys.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
$x = 70; if ($x = 70) {{}}
$x = 70; if ($x == 70) {{}}
Use ==.
PHP
SELECT name role FROM items;
SELECT name, role FROM items;
Add comma.
SQL
String temp = 'test';
String temp = "test";
Double quotes.
Java
print('world')
print('world')
Correct.
R
let text1 = String::from("test"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("test"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let vec=vec![70,22,19]; let primary=&vec[0]; vec.push(29);
let mut vec=vec![70,22,19]; let primary=vec[0]; vec.push(29);
Copy instead of reference.
Rust
{{'age':'result'}}
{{"age":"result"}}
Use double quotes.
JSON
def compute(c): return c + 1
def compute(c): return c + 1
Correct.
Python
if foo = 22
if foo == 22
Use ==.
Go
disp('world')
disp('world')
Correct.
MATLAB
items[42]
if (length(items) >= 42) items[42]
Check length.
R
function compute(): void {{ return 39; }}
function compute(): number {{ return 39; }}
Return type mismatch.
TypeScript
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
my @arr = (32,60,9);
my @arr = (32,60,9);
Correct.
Perl
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
$data[52] = 5;
if (isset($data[52])) $data[52] = 5;
Check existence.
PHP
'hello' + 39
'hello' + 39.to_s
Convert int.
Ruby
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<p>value <b>test</p></b>
<p>value <b>test</b></p>
Nest properly.
HTML
jwt.sign({{id:29}}, 'key');
jwt.sign({{id:29}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
foo = 71
foo=71
No spaces.
Shell
["output", 46]
["output", 46]
Correct.
JSON
def process puts 'result' end
def process puts 'result' end
Correct.
Ruby
WHERE email = '56'
WHERE email = 56
Don't quote integer.
SQL
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
.User {{ color: #fff; }}
.User {{ color: #fff; }}
Correct.
CSS
if result = 33 {{}}
if result == 33 {{}}
Use ==.
Swift
print 'hello'
print 'hello';
Add semicolon.
Perl
const person:Person = {{name:'world'}};
const person:Person = {{name:'world', age:12}};
Add missing property.
TypeScript
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
print 'data'
print('data')
print needs parentheses.
Python