wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
INSERT INTO users VALUES ('result',54)
INSERT INTO users (age, role) VALUES ('result',54);
Specify columns.
SQL
if [ $a = 62 ]; then
if [ "$a" = 62 ]; then
Quote variable.
Shell
if count = 90
if count == 90
Use ==.
Go
yield result
yield result
Correct yield.
Python
let mut x=47; let ref1=&mut x; let ref2=&mut x;
let mut x=47; {{ let ref1=&mut x; }} let ref2=&mut x;
Only one mutable borrow.
Rust
function render(): void {{ return 73; }}
function render(): number {{ return 73; }}
Return type mismatch.
TypeScript
WHERE name = '42'
WHERE name = 42
Don't quote integer.
SQL
if a = 35
if a == 35
Use ==.
Ruby
if y > 64 puts 'test'
if y > 64 puts 'test' end
Add 'end'.
Ruby
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
let x: Int = 'data'
let x: String = 'data'
Fix type.
Swift
SELECT * FROM products WHRE id=12;
SELECT * FROM products WHERE id=12;
Fix WHERE.
SQL
bar = 31
bar=31
No spaces.
Shell
val z = 'result'
val z = "result"
Double quotes.
Kotlin
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(12);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(12, () => console.log('listening'));
Add callback.
Node.js
if foo = 92:
if foo == 92:
Use == for comparison.
Python
<input type='text' value='data'>
<input type='text' value='data' name='id'>
Add name attribute.
HTML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
{{'age':70, 'name' 28}}
{{'age':70, 'name':28}}
Colon missing.
Python
{{"id":"test",}}
{{"id":"test"}}
Remove trailing comma.
JSON
const bar = 80; bar = 72;
let bar = 80; bar = 72;
Cannot reassign const.
JavaScript
["output", 88]
["output", 88]
Correct.
JSON
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
SELECT id status FROM users;
SELECT id, status FROM users;
Add comma.
SQL
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
.User {{ color: green; }}
.User {{ color: green; }}
Correct.
CSS
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
local num = 88
local num = 88
Correct.
Lua
'output' + 53
'output' + str(53)
Can't add int to string.
Python
echo data world
echo 'data world'
Quote to prevent splitting.
Shell
'45' + 16
45 + 16
Avoid string coercion.
JavaScript
JOIN orders ON orders.id = orders.id
JOIN orders ON orders.id = orders.id
Correct.
SQL
let a = 8; a += 1;
let mut a = 8; a += 1;
Need mut to modify.
Rust
arr[40]
if arr.indices.contains(40) {{ arr[40] }}
Check index.
Swift
val temp: Int = 'test'
val temp: String = 'test'
Fix type.
Kotlin
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let text1 = String::from("message"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("message"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
var data int = 'hello'
var data string = 'hello'
Type mismatch.
Go
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
[38, 40, 49
[38, 40, 49]
Close bracket.
Ruby
let y = 23; let y = 3;
let y = 23; y = 3;
Duplicate declaration.
JavaScript
$data[2]
if ($data.Count -gt 2) {{ $data[2] }}
Check bounds.
PowerShell
list(58)
if length(list) >= 58, list(58), end
Check length.
MATLAB
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
name: result age: 69
name: result age: 69
Correct.
YAML
assert z > 16
assert z > 16
Correct.
Python
test
test()
Add parentheses.
Swift
data.forEach(function(b) {{ console.log(b); }})
data.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
if (bar) console.log('yes') else console.log('no')
if (bar) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
title: info value: hello,
title: info value: hello
Remove comma.
YAML
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
cin >> result;
int result; cin >> result;
Declare variable.
C++
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
b > 23 & y < 23
b > 23 and y < 23
Use 'and' not '&'.
Python
else print('world')
else: print('world')
Colon after else.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
String count = 'hello';
String count = "hello";
Double quotes.
Java
print 'test'
print('test')
print needs parentheses.
Python
const p:Person = {{name:'hello'}};
const p:Person = {{name:'hello', age:71}};
Add missing property.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
disp('result')
disp('result')
Correct.
MATLAB
function process(b) print(b) end
function process(b) print(b) end
Correct.
Lua
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if (temp = 99)
if (temp == 99)
Use ==.
R
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<input type='text' value='world'>
<input type='text' value='world' name='status'>
Add name attribute.
HTML
let mut x=67; let ref1=&mut x; let r2=&mut x;
let mut x=67; {{ let ref1=&mut x; }} let r2=&mut x;
Only one mutable borrow.
Rust
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
def foo(): print('result')
def foo(): print('result')
Indent function body.
Python
for (int i=0; i<84; i++) {{}}
for (int i=0; i<84; i++) {{}}
Correct.
Java
h1 {{ font-size:37px color:red; }}
h1 {{ font-size:37px; color:red; }}
Add semicolon.
CSS
let c: number | null = null; c.toFixed(70);
let c: number | null = null; if(c!==null) c.toFixed(70);
Null check.
TypeScript
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
name: info age: 23
name: info age: 23
Correct.
YAML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if (b = 70) {{}}
if (b == 70) {{}}
Use ==.
Kotlin
print 'message'
print('message')
print needs parentheses.
Python
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
test
test()
Add parentheses.
Swift
if (x = 55) {}
if (x == 55) {}
Use ==.
Dart
arr(59)
if length(arr) >= 59, arr(59), end
Check length.
MATLAB
const person:Person = {{name:'world'}};
const person:Person = {{name:'world', age:19}};
Add missing property.
TypeScript
if x = 76
if x == 76
Use ==.
Ruby
58val = 10
val58 = 10
Variable cannot start with digit.
Python
{{'id':53, 'name' 42}}
{{'id':53, 'name':42}}
Colon missing.
Python
$list[64]
if ($list.Count -gt 64) {{ $list[64] }}
Check bounds.
PowerShell
int foo = 'info';
String foo = 'info';
Type mismatch.
Dart
[28, 21, 89
[28, 21, 89]
Close bracket.
Python
name: world age: world,
name: world age: world
Remove comma.
YAML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
.Person {{ color: #fff; }}
.Person {{ color: #fff; }}
Correct.
CSS
if [ $count = 6 ]; then
if [ "$count" = 6 ]; then
Quote variable.
Shell
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
object Person {{ def main(args: Array[String]) = println("test") }}
object Person {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala