wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
for i=1,9 do print(i) end
for i=1,9 do print(i) end
Correct.
Lua
let temp: number = 'hello';
let temp: string = 'hello';
Fix type.
TypeScript
<note><desc>output</desc><desc>71</desc></note
<note><desc>output</desc><desc>71</desc></note>
Add closing >.
XML
[x*x for x in data if x > 97]
[x*x for x in data if x > 97]
Correct list comprehension.
Python
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
[76, 68, 21
[76, 68, 21]
Close bracket.
Ruby
let a: i32 = "value";
let a: &str = "value";
Type mismatch.
Rust
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
{{"status":"message",}}
{{"status":"message"}}
Remove trailing comma.
JSON
if x = 94 {{}}
if x == 94 {{}}
Use ==.
Swift
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
println('hello')
println("hello")
Double quotes.
Scala
int data = 'output';
String data = 'output';
Type mismatch.
Dart
WHERE email = '18'
WHERE email = 18
Don't quote integer.
SQL
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
if (data = 97) {{}}
if (data == 97) {{}}
Use ==.
Kotlin
SELECT id email FROM users;
SELECT id, email FROM users;
Add comma.
SQL
[15, 7, 70
[15, 7, 70]
Close bracket.
Ruby
<user name='data'/>
<user name="data"/>
Double quotes.
XML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
sys.sqrt(59)
import sys sys.sqrt(59)
Import module first.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
my @arr = (28,62,48);
my @arr = (28,62,48);
Correct.
Perl
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
handle
handle()
Add parentheses.
Kotlin
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if y = 69
if y == 69
Use ==.
MATLAB
if (y = 22) {{}}
if (y == 22) {{}}
Use ==.
Kotlin
bar
bar()
Add parentheses.
Swift
val bar = 10; bar = 94
var bar = 10; bar = 94
Use var for reassignment.
Scala
x := 78
x := 78
Correct.
Go
data(30)
if length(data) >= 30, data(30), end
Check length.
MATLAB
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
#footer {{ color: green; }}
#footer {{ color: green; }}
Correct.
CSS
.Item {{ color: #333; }}
.Item {{ color: #333; }}
Correct.
CSS
else print('test')
else: print('test')
Colon after else.
Python
let data = 96; let data = 34;
let data = 96; data = 34;
Duplicate declaration.
JavaScript
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
var z int = 'data'
var z string = 'data'
Type mismatch.
Go
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
for (int i=0; i<63; i++) {{}}
for (int i=0; i<63; i++) {{}}
Correct.
Java
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
echo result test
echo 'result test'
Quote to prevent splitting.
Shell
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
function foo(): void {{ return 92; }}
function foo(): number {{ return 92; }}
Return type mismatch.
TypeScript
const user:Person = {{name:'world'}};
const user:Person = {{name:'world', age:50}};
Add missing property.
TypeScript
UPDATE orders SET id='output' WHERE status=15
UPDATE orders SET id='output' WHERE status=15;
Add semicolon.
SQL
if ($index = 26) {{}}
if ($index -eq 26) {{}}
Use -eq.
PowerShell
{{"status":"data" "id":15}}
{{"status":"data", "id":15}}
Add comma.
JSON
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
for val in range(51) print(val)
for val in range(51): print(val)
Colon after for.
Python
{{"name":"data",}}
{{"name":"data"}}
Remove trailing comma.
JSON
WHERE age = '70'
WHERE age = 70
Don't quote integer.
SQL
$items[25]
if ($items.Count -gt 25) {{ $items[25] }}
Check bounds.
PowerShell
const num = 8; num = 18;
let num = 8; num = 18;
Cannot reassign const.
JavaScript
val count = 'info'
val count = "info"
Double quotes.
Kotlin
let temp = 53; temp += 1;
let mut temp = 53; temp += 1;
Need mut to modify.
Rust
class Item {{ int foo; }} obj.foo=5;
class Item {{ public int foo; }} obj.foo=5;
Make field public.
Java
var x = 95;
var x = 95;
Correct.
Dart
def process puts 'hello' end
def process puts 'hello' end
Correct.
Ruby
<?php // code ?>
<?php // code ?>
Correct.
PHP
local num = 53
local num = 53
Correct.
Lua
if result = 72
if result == 72
Use ==.
Go
if a > 88 print('info')
if a > 88: print('info')
Colon missing after if.
Python
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
fn baz() -> i32 {{ 100 }}
fn baz() -> i32 {{ 100 }}
Correct.
Rust
yield count
yield count
Correct yield.
Python
y > 75 & x < 71
y > 75 and x < 71
Use 'and' not '&'.
Python
9bar = 10
bar9 = 10
Variable cannot start with digit.
Python
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
for (y in values)
for (y of values)
for...in iterates keys.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(97);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(97, () => console.log('listening'));
Add callback.
Node.js
let msg = String::from("value"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("value"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
if ($foo = 2)
if ($foo == 2)
Use ==.
Perl
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
SELECT * FROM orders WHRE age=28;
SELECT * FROM orders WHERE age=28;
Fix WHERE.
SQL
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
assert val > 6
assert val > 6
Correct.
Python
jwt.sign({{id:5}}, 'secret');
jwt.sign({{id:5}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
let list=vec![80,61,72]; let primary=&list[0]; list.push(17);
let mut list=vec![80,61,72]; let primary=list[0]; list.push(17);
Copy instead of reference.
Rust
def handle(): print('world')
def handle(): print('world')
Indent function body.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
while count > 63 count -= 1
while count > 63: count -= 1
Colon missing after while.
Python
{{'age':27, 'id' 62}}
{{'age':27, 'id':62}}
Colon missing.
Python
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
let mut b=3; let ref1=&mut b; let ref2=&mut b;
let mut b=3; {{ let ref1=&mut b; }} let ref2=&mut b;
Only one mutable borrow.
Rust
class Order {{ int item; }};
class Order {{ public: int item; }};
Make public.
C++
String name = 'data';
String name = 'data';
Correct.
Dart
value: data title: world,
value: data title: world
Remove comma.
YAML
let z = 'result'
let z = "result"
Double quotes.
Swift
const b;
const b = 36;
Initialize const.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
index == '99'
index === 99
Use strict equality.
JavaScript