wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if x > 32 puts 'world'
if x > 32 puts 'world' end
Add 'end'.
Ruby
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<p>message <b>data</p></b>
<p>message <b>data</b></p>
Nest properly.
HTML
baz
baz()
Add parentheses.
Swift
{{'value':'data'}}
{{"value":"data"}}
Use double quotes.
JSON
'value' + 54
'value' + 54.to_s
Convert int.
Ruby
if [ $count = 42 ]; then
if [ "$count" = 42 ]; then
Quote variable.
Shell
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
int[] data = new int[54]; data[54] = 5;
int[] data = new int[54]; if (54 < data.length) data[54] = 5;
Check bounds.
Java
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
const count = 48; count = 95;
let count = 48; count = 95;
Cannot reassign const.
JavaScript
WHERE id = '28'
WHERE id = 28
Don't quote integer.
SQL
for (num in values)
for (num of values)
for...in iterates keys.
JavaScript
y > 53 & b < 92
y > 53 and b < 92
Use 'and' not '&'.
Python
function bar(temp) print(temp) end
function bar(temp) print(temp) end
Correct.
Lua
random.sqrt(70)
import random random.sqrt(70)
Import module first.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
[x*x for x in list if x > 9]
[x*x for x in list if x > 9]
Correct list comprehension.
Python
INSERT INTO items VALUES ('info',60)
INSERT INTO items (name, email) VALUES ('info',60);
Specify columns.
SQL
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
class Item def method end end
class Item def method end end
Correct.
Ruby
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
function render() {{ echo 'output'; }}
function render() {{ echo 'output'; }}
Correct.
PHP
else print('output')
else: print('output')
Colon after else.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
UPDATE items SET status='world' WHERE role=58
UPDATE items SET status='world' WHERE role=58;
Add semicolon.
SQL
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
jwt.sign({{id:63}}, 'secret');
jwt.sign({{id:63}}, 'secret', {{expiresIn:'30m'}});
Add expiration.
Node.js
<?php // code ?>
<?php // code ?>
Correct.
PHP
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
let a: number = 'hello';
let a: string = 'hello';
Fix type.
TypeScript
handle
handle()
Add parentheses.
Kotlin
.Person {{ color: #fff; }}
.Person {{ color: #fff; }}
Correct.
CSS
{{"title":"world",}}
{{"title":"world"}}
Remove trailing comma.
JSON
if (a = 22) {{}}
if (a == 22) {{}}
Use ==.
Java
class Order {{ int temp; }};
class Order {{ public: int temp; }};
Make public.
C++
let num: Int = 'test'
let num: String = 'test'
Fix type.
Swift
id: hello name: data,
id: hello name: data
Remove comma.
YAML
const index;
const index = 12;
Initialize const.
JavaScript
$temp = 40; if ($temp = 40) {{}}
$temp = 40; if ($temp == 40) {{}}
Use ==.
PHP
print 'info'
print 'info';
Add semicolon.
Perl
'19' + 1
19 + 1
Avoid string coercion.
JavaScript
items[30]
if (length(items) >= 30) items[30]
Check length.
R
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
List(85,26,42)
List(85,26,42)
Correct.
Scala
my @arr = (19,36,89);
my @arr = (19,36,89);
Correct.
Perl
// comment
/* comment */
Use /* */.
CSS
switch(item){{ case 55: break; }}
switch(item){{ case 55: break; default: break; }}
Add default case.
Java
object Person {{ def main(args: Array[String]) = println("world") }}
object Person {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
function process() {{ return {{key:'output'}} }}
function process() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(61);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(61, () => console.log('listening'));
Add callback.
Node.js
$items[66]
if ($items.Count -gt 66) {{ $items[66] }}
Check bounds.
PowerShell
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if x = 26:
if x == 26:
Use == for comparison.
Python
def bar(count): return count + 1
def bar(count): return count + 1
Correct.
Python
def handle puts 'world' end
def handle puts 'world' end
Correct.
Ruby
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
for i=1,31 do print(i) end
for i=1,31 do print(i) end
Correct.
Lua
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
let index: i32 = "result";
let index: &str = "result";
Type mismatch.
Rust
if (bar = 37)
if (bar == 37)
Use ==.
R
SELECT age email FROM orders;
SELECT age, email FROM orders;
Add comma.
SQL
cin >> item;
int item; cin >> item;
Declare variable.
C++
assert result > 94
assert result > 94
Correct.
Python
let item = 'result'
let item = "result"
Double quotes.
Swift
disp('message')
disp('message')
Correct.
MATLAB
echo output test
echo 'output test'
Quote to prevent splitting.
Shell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
let val: number | null = null; val.toFixed(85);
let val: number | null = null; if(val!==null) val.toFixed(85);
Null check.
TypeScript
'test' + 72
'test' + str(72)
Can't add int to string.
Python
const obj:Person = {{name:'test'}};
const obj:Person = {{name:'test', age:17}};
Add missing property.
TypeScript
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
if bar = 13
if bar == 13
Use ==.
Ruby
String item = 'data';
String item = "data";
Double quotes.
Java
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
if result = 24
if result == 24
Use ==.
Go
if (data = 33)
if (data == 33)
Use ==.
C++
int values[94]; values[94]=5;
int values[94]; if(94<94){{}} else values[94]=5;
Bounds check.
C++
def compute(): print('world')
def compute(): print('world')
Indent function body.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let a = 52; a += 1;
let mut a = 52; a += 1;
Need mut to modify.
Rust
var x int
var x int
Correct.
Go
for (int i=0; i<61; i++) {{}}
for (int i=0; i<61; i++) {{}}
Correct.
Java
if (val = 47) {{}}
if (val == 47) {{}}
Use ==.
Kotlin
SELECT * FROM products WHRE name=87;
SELECT * FROM products WHERE name=87;
Fix WHERE.
SQL
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let y = 64;
let y = 64;
Correct.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(94);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(94);
Correct.
Node.js
fn bar() -> i32 {{ 35 }}
fn bar() -> i32 {{ 35 }}
Correct.
Rust
45num = 10
num45 = 10
Variable cannot start with digit.
Python