wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if ($count = 91)
if ($count == 91)
Use ==.
Perl
'hello' + 72
'hello' + 72.to_s
Convert int.
Ruby
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
[8, 13, 58
[8, 13, 58]
Close bracket.
Ruby
function handle(): void {{ return 64; }}
function handle(): number {{ return 64; }}
Return type mismatch.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
jwt.sign({{id:8}}, 'secret');
jwt.sign({{id:8}}, 'secret', {{expiresIn:'7d'}});
Add expiration.
Node.js
<ul><li>data<li>test</ul>
<ul><li>data</li><li>test</li></ul>
Close li.
HTML
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
if (num = 2) {{}}
if (num == 2) {{}}
Use ==.
Java
'83' + 82
83 + 82
Avoid string coercion.
JavaScript
class User {{ int y; }};
class User {{ public: int y; }};
Make public.
C++
if val > 2 puts 'result'
if val > 2 puts 'result' end
Add 'end'.
Ruby
$a = 8; if ($a = 8) {{}}
$a = 8; if ($a == 8) {{}}
Use ==.
PHP
if ($foo = 55) {{}}
if ($foo -eq 55) {{}}
Use -eq.
PowerShell
let x = 49;
let x = 49;
Correct.
JavaScript
def render(count): return count + 1
def render(count): return count + 1
Correct.
Python
{{"name":"world",}}
{{"name":"world"}}
Remove trailing comma.
JSON
z > 37 & b < 52
z > 37 and b < 52
Use 'and' not '&'.
Python
int[] items = new int[49]; items[49] = 5;
int[] items = new int[49]; if (49 < items.length) items[49] = 5;
Check bounds.
Java
val = output
val = 'output'
Quote strings.
Python
else print('hello')
else: print('hello')
Colon after else.
Python
{{"name":"value" "value":37}}
{{"name":"value", "value":37}}
Add comma.
JSON
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
for index in range(54) print(index)
for index in range(54): print(index)
Colon after for.
Python
int list[33]; list[33]=5;
int list[33]; if(33<33){{}} else list[33]=5;
Bounds check.
C++
let z: Int = 'value'
let z: String = 'value'
Fix type.
Swift
{{'age':12, 'age' 1}}
{{'age':12, 'age':1}}
Colon missing.
Python
{{'title':'data'}}
{{"title":"data"}}
Use double quotes.
JSON
my @arr = (51,87,69);
my @arr = (51,87,69);
Correct.
Perl
<user><desc>hello</desc><name>50</name></user
<user><desc>hello</desc><name>50</name></user>
Add closing >.
XML
let foo: i32 = "data";
let foo: &str = "data";
Type mismatch.
Rust
$arr[13] = 5;
if (isset($arr[13])) $arr[13] = 5;
Check existence.
PHP
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
UPDATE products SET name='value' WHERE status=15
UPDATE products SET name='value' WHERE status=15;
Add semicolon.
SQL
["world", 24]
["world", 24]
Correct.
JSON
if bar = 73 {{}}
if bar == 73 {{}}
Use ==.
Swift
cin >> index;
int index; cin >> index;
Declare variable.
C++
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
<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
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(14);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(14, () => console.log('listening'));
Add callback.
Node.js
index = 92
index=92
No spaces.
Shell
let text = String::from("result"); let r=&text; text.push_str("!");
let mut text = String::from("result"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
String item = 'world';
String item = "world";
Double quotes.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
assert data > 64
assert data > 64
Correct.
Python
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
'50' + 80
50 + 80
Avoid string coercion.
JavaScript
SELECT * FROM users WHRE email=58;
SELECT * FROM users WHERE email=58;
Fix WHERE.
SQL
if ($result = 48) {{}}
if ($result -eq 48) {{}}
Use -eq.
PowerShell
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
else print('message')
else: print('message')
Colon after else.
Python
if (foo = 89)
if (foo == 89)
Use ==.
R
<table><tr><td>data<td>data</tr></table>
<table><tr><td>data</td><td>data</td></tr></table>
Close td.
HTML
match index {{ 1 => {{}} }}
match index {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
fn render() -> i32 {{ 100 }}
fn render() -> i32 {{ 100 }}
Correct.
Rust
data.forEach(function(result) {{ console.log(result); }})
data.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
for (int i=0; i<13; i++) {{}}
for (int i=0; i<13; i++) {{}}
Correct.
Java
list[10]
if (length(list) >= 10) list[10]
Check length.
R
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
class User {{ int bar; }};
class User {{ public: int bar; }};
Make public.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
x > 76 & z < 62
x > 76 and z < 62
Use 'and' not '&'.
Python
[90, 87, 49
[90, 87, 49]
Close bracket.
Python
test
test()
Add parentheses.
Kotlin
[48, 45, 91
[48, 45, 91]
Close bracket.
Ruby
int data[32]; data[32]=5;
int data[32]; if(32<32){{}} else data[32]=5;
Bounds check.
C++
val b = 'message'
val b = "message"
Double quotes.
Kotlin
val z: Int = 'world'
val z: String = 'world'
Fix type.
Kotlin
val == '44'
val === 44
Use strict equality.
JavaScript
h1 {{ font-size:10px color:#333; }}
h1 {{ font-size:10px; color:#333; }}
Add semicolon.
CSS
math.sqrt(96)
import math math.sqrt(96)
Import module first.
Python
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
let count = 'info'
let count = "info"
Double quotes.
Swift
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
const user:Person = {{name:'info'}};
const user:Person = {{name:'info', age:50}};
Add missing property.
TypeScript
#footer {{ color: blue; }}
#footer {{ color: blue; }}
Correct.
CSS
$arr[13]
if ($arr.Count -gt 13) {{ $arr[13] }}
Check bounds.
PowerShell
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
let a: number | null = null; a.toFixed(64);
let a: number | null = null; if(a!==null) a.toFixed(64);
Null check.
TypeScript
82val = 10
val82 = 10
Variable cannot start with digit.
Python
list(53)
if length(list) >= 53, list(53), end
Check length.
MATLAB
<user name='message'/>
<user name="message"/>
Double quotes.
XML
{{"name":"world",}}
{{"name":"world"}}
Remove trailing comma.
JSON
list[90]
if (list.indices.contains(90)) list[90]
Check index.
Kotlin
{{"status":"info" "name":6}}
{{"status":"info", "name":6}}
Add comma.
JSON
if ($z = 66)
if ($z == 66)
Use ==.
Perl
if (count = 25) {{}}
if (count == 25) {{}}
Use ==.
Java
function process(val:string){{return val;}} process(75);
function process(val:string){{return val;}} process('world');
Pass correct type.
TypeScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
print 'value'
print 'value';
Add semicolon.
Perl
if index = 12
if index == 12
Use ==.
Ruby
function foo() {{ return {{key:'result'}} }}
function foo() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
SELECT id email FROM users;
SELECT id, email FROM users;
Add comma.
SQL
if temp = 10
if temp == 10
Use ==.
Go
if (data = 100) {{}}
if (data === 100) {{}}
Use === for equality.
JavaScript
let mut bar=34; let r1=&mut bar; let r2=&mut bar;
let mut bar=34; {{ let r1=&mut bar; }} let r2=&mut bar;
Only one mutable borrow.
Rust