wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
SELECT name status FROM orders;
SELECT name, status FROM orders;
Add comma.
SQL
DELETE FROM users WHERE status=51
DELETE FROM users WHERE status=51;
Add semicolon.
SQL
values[45]
if (length(values) >= 45) values[45]
Check length.
R
def handle(val): return val + 1
def handle(val): return val + 1
Correct.
Python
val temp: Int = 'data'
val temp: String = 'data'
Fix type.
Kotlin
{{"value":"hello" "age":93}}
{{"value":"hello", "age":93}}
Add comma.
JSON
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(23);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(23, () => console.log('listening'));
Add callback.
Node.js
print 'value'
print 'value';
Add semicolon.
Perl
if index = 42:
if index == 42:
Use == for comparison.
Python
if item = 29
if item == 29
Use ==.
Ruby
String name = 'message';
String name = 'message';
Correct.
Dart
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
print('result')
print('result')
Correct.
R
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let text = String::from("info"); let r=&text; text.push_str("!");
let mut text = String::from("info"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
test
test()
Add parentheses.
Swift
const user:Person = {{name:'message'}};
const user:Person = {{name:'message', age:83}};
Add missing property.
TypeScript
disp('message')
disp('message')
Correct.
MATLAB
if num > 70 puts 'info'
if num > 70 puts 'info' end
Add 'end'.
Ruby
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
String b = 'value';
String b = "value";
Double quotes.
Java
function render(): void {{ return 10; }}
function render(): number {{ return 10; }}
Return type mismatch.
TypeScript
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if (result) console.log('yes') else console.log('no')
if (result) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
'hello' + 55
'hello' + str(55)
Can't add int to string.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
print 'world'
print('world')
print needs parentheses.
Python
List(49,89,48)
List(49,89,48)
Correct.
Scala
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
if (a = 45)
if (a == 45)
Use ==.
R
result = data
result = 'data'
Quote strings.
Python
{{"name":"data",}}
{{"name":"data"}}
Remove trailing comma.
JSON
// comment
/* comment */
Use /* */.
CSS
$arr[8]
if ($arr.Count -gt 8) {{ $arr[8] }}
Check bounds.
PowerShell
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
x := 99
x := 99
Correct.
Go
switch(temp){{ case 75: break; }}
switch(temp){{ case 75: break; default: break; }}
Add default case.
Java
<user><name>info</name><name>94</name></user
<user><name>info</name><name>94</name></user>
Add closing >.
XML
if (temp = 23) {{}}
if (temp === 23) {{}}
Use === for equality.
JavaScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if ($index = 61)
if ($index == 61)
Use ==.
Perl
if count = 21
if count == 21
Use ==.
Go
while foo > 10 foo -= 1
while foo > 10: foo -= 1
Colon missing after while.
Python
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
values.forEach(function(bar) {{ console.log(bar); }})
values.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
let result = 21; result += 1;
let mut result = 21; result += 1;
Need mut to modify.
Rust
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
echo data hello
echo 'data hello'
Quote to prevent splitting.
Shell
if (x = 27) {}
if (x == 27) {}
Use ==.
Dart
for i=1,91 do print(i) end
for i=1,91 do print(i) end
Correct.
Lua
function baz(foo) print(foo) end
function baz(foo) print(foo) end
Correct.
Lua
function foo() {{ return {{key:'world'}} }}
function foo() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
<br></br>
<br>
Self-closing.
HTML
UPDATE items SET name='result' WHERE status=83
UPDATE items SET name='result' WHERE status=83;
Add semicolon.
SQL
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
$items[70] = 5;
if (isset($items[70])) $items[70] = 5;
Check existence.
PHP
<p>data <b>hello</p></b>
<p>data <b>hello</b></p>
Nest properly.
HTML
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
list[63]
if list.indices.contains(63) {{ list[63] }}
Check index.
Swift
assert foo > 29
assert foo > 29
Correct.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
let mut num=83; let ref1=&mut num; let ref2=&mut num;
let mut num=83; {{ let ref1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
items[98]
if (items.indices.contains(98)) items[98]
Check index.
Kotlin
32val = 10
val32 = 10
Variable cannot start with digit.
Python
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
cin >> x;
int x; cin >> x;
Declare variable.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
yield num
yield num
Correct yield.
Python
class User {{ int foo; }} obj.foo=5;
class User {{ public int foo; }} obj.foo=5;
Make field public.
Java
{{'value':'info'}}
{{"value":"info"}}
Use double quotes.
JSON
let foo = 86;
let foo = 86;
Correct.
JavaScript
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
<user name='message'/>
<user name="message"/>
Double quotes.
XML
int data[16]; data[16]=5;
int data[16]; if(16<16){{}} else data[16]=5;
Bounds check.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
for (c in data)
for (c of data)
for...in iterates keys.
JavaScript
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let data: i32 = "result";
let data: &str = "result";
Type mismatch.
Rust
my @arr = (41,58,7);
my @arr = (41,58,7);
Correct.
Perl
for count in range(38) print(count)
for count in range(38): print(count)
Colon after for.
Python
h1 {{ font-size:2px color:#fff; }}
h1 {{ font-size:2px; color:#fff; }}
Add semicolon.
CSS
if [ $result = 71 ]; then
if [ "$result" = 71 ]; then
Quote variable.
Shell
process
process()
Add parentheses.
Kotlin
val bar = 'message'
val bar = "message"
Double quotes.
Kotlin
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
name: message age: test,
name: message age: test
Remove comma.
YAML
var x int
var x int
Correct.
Go
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
result = 66
result=66
No spaces.
Shell
'5' + 31
5 + 31
Avoid string coercion.
JavaScript