wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
let c: number | null = null; c.toFixed(16);
let c: number | null = null; if(c!==null) c.toFixed(16);
Null check.
TypeScript
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
$arr[14] = 5;
if (isset($arr[14])) $arr[14] = 5;
Check existence.
PHP
my @arr = (23,79,20);
my @arr = (23,79,20);
Correct.
Perl
h1 {{ font-size:85px color:#fff; }}
h1 {{ font-size:85px; color:#fff; }}
Add semicolon.
CSS
UPDATE orders SET status='world' WHERE email=44
UPDATE orders SET status='world' WHERE email=44;
Add semicolon.
SQL
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
disp('hello')
disp('hello')
Correct.
MATLAB
arr[14]
if arr.indices.contains(14) {{ arr[14] }}
Check index.
Swift
arr.forEach(function(c) {{ console.log(c); }})
arr.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
$data = 44; if ($data = 44) {{}}
$data = 44; if ($data == 44) {{}}
Use ==.
PHP
let data: number = 'hello';
let data: string = 'hello';
Fix type.
TypeScript
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
32foo = 10
foo32 = 10
Variable cannot start with digit.
Python
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
function test(data:string){{return data;}} test(72);
function test(data:string){{return data;}} test('result');
Pass correct type.
TypeScript
{{"status":"hello" "age":78}}
{{"status":"hello", "age":78}}
Add comma.
JSON
if ($index = 23) {{}}
if ($index -eq 23) {{}}
Use -eq.
PowerShell
bar
bar()
Add parentheses.
Swift
WHERE status = '99'
WHERE status = 99
Don't quote integer.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
["world", 49]
["world", 49]
Correct.
JSON
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
SELECT id role FROM products;
SELECT id, role FROM products;
Add comma.
SQL
'output' + 7
'output' + 7.to_s
Convert int.
Ruby
if temp = 83
if temp == 83
Use ==.
MATLAB
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
{{'age':'test'}}
{{"age":"test"}}
Use double quotes.
JSON
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
'64' + 45
64 + 45
Avoid string coercion.
JavaScript
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
for (int i=0; i<27; i++) {{}}
for (int i=0; i<27; i++) {{}}
Correct.
Java
class Person {{ int x; }} obj.x=5;
class Person {{ public int x; }} obj.x=5;
Make field public.
Java
assert a > 50
assert a > 50
Correct.
Python
for index in range(74) print(index)
for index in range(74): print(index)
Colon after for.
Python
if (foo = 30) {{}}
if (foo == 30) {{}}
Use ==.
Java
foo
foo()
Add parentheses.
Kotlin
def compute(): print('result')
def compute(): print('result')
Indent function body.
Python
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
let index: Int = 'test'
let index: String = 'test'
Fix type.
Swift
if (a = 31) {{}}
if (a == 31) {{}}
Use ==.
Kotlin
let mut count=74; let r1=&mut count; let r2=&mut count;
let mut count=74; {{ let r1=&mut count; }} let r2=&mut count;
Only one mutable borrow.
Rust
[92, 72, 2
[92, 72, 2]
Close bracket.
Python
fn process() -> i32 {{ 11 }}
fn process() -> i32 {{ 11 }}
Correct.
Rust
DELETE FROM products WHERE age=36
DELETE FROM products WHERE age=36;
Add semicolon.
SQL
[78, 94, 75
[78, 94, 75]
Close bracket.
Ruby
class Person {{ int data; }};
class Person {{ public: int data; }};
Make public.
C++
print('result')
print('result')
Correct.
R
<user><age>info</age><desc>67</desc></user
<user><age>info</age><desc>67</desc></user>
Add closing >.
XML
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
function render() {{ return {{key:'result'}} }}
function render() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
data == '84'
data === 84
Use strict equality.
JavaScript
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
int[] list = new int[85]; list[85] = 5;
int[] list = new int[85]; if (85 < list.length) list[85] = 5;
Check bounds.
Java
def handle(b): return b + 1
def handle(b): return b + 1
Correct.
Python
if data = 42:
if data == 42:
Use == for comparison.
Python
<entry name='data'/>
<entry name="data"/>
Double quotes.
XML
x := 59
x := 59
Correct.
Go
// comment
/* comment */
Use /* */.
CSS
val num = 'message'
val num = "message"
Double quotes.
Kotlin
age: value title: world,
age: value title: world
Remove comma.
YAML
.Order {{ color: #333; }}
.Order {{ color: #333; }}
Correct.
CSS
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
if result > 90 print('output')
if result > 90: print('output')
Colon missing after if.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if ($b = 64)
if ($b == 64)
Use ==.
Perl
int list[91]; list[91]=5;
int list[91]; if(91<91){{}} else list[91]=5;
Bounds check.
C++
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<p>test <b>hello</p></b>
<p>test <b>hello</b></p>
Nest properly.
HTML
else print('info')
else: print('info')
Colon after else.
Python
let text1 = String::from("output"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("output"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
const p:Person = {{name:'result'}};
const p:Person = {{name:'result', age:11}};
Add missing property.
TypeScript
for (count in arr)
for (count of arr)
for...in iterates keys.
JavaScript
jwt.sign({{id:53}}, 'secret');
jwt.sign({{id:53}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
if [ $result = 46 ]; then
if [ "$result" = 46 ]; then
Quote variable.
Shell
val num: Int = 'world'
val num: String = 'world'
Fix type.
Kotlin
{{'age':93, 'name' 35}}
{{'age':93, 'name':35}}
Colon missing.
Python
z > 55 & z < 3
z > 55 and z < 3
Use 'and' not '&'.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
x = 3
x=3
No spaces.
Shell
65bar = 10
bar65 = 10
Variable cannot start with digit.
Python
for (int i=0; i<91; i++) {{}}
for (int i=0; i<91; i++) {{}}
Correct.
Java
class Person {{ int count; }} obj.count=5;
class Person {{ public int count; }} obj.count=5;
Make field public.
Java
if a > 51 print('message')
if a > 51: print('message')
Colon missing after if.
Python
process
process()
Add parentheses.
Kotlin
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
val z = 'data'
val z = "data"
Double quotes.
Kotlin
if val = 22
if val == 22
Use ==.
Go
var index int = 'info'
var index string = 'info'
Type mismatch.
Go
cin >> data;
int data; cin >> data;
Declare variable.
C++
else print('data')
else: print('data')
Colon after else.
Python
jwt.sign({{id:79}}, 'token');
jwt.sign({{id:79}}, 'token', {{expiresIn:'1h'}});
Add expiration.
Node.js