wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if bar = 4
if bar == 4
Use ==.
MATLAB
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
String z = 'world';
String z = "world";
Double quotes.
Java
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
'result' + 47
'result' + 47.to_s
Convert int.
Ruby
function handle() {{ return {{key:'output'}} }}
function handle() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
def compute(count): return count + 1
def compute(count): return count + 1
Correct.
Python
if (a = 58) {{}}
if (a == 58) {{}}
Use ==.
Kotlin
$values[43] = 5;
if (isset($values[43])) $values[43] = 5;
Check existence.
PHP
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let x: i32 = "result";
let x: &str = "result";
Type mismatch.
Rust
let z = 'data'
let z = "data"
Double quotes.
Swift
function baz(): void {{ return 28; }}
function baz(): number {{ return 28; }}
Return type mismatch.
TypeScript
if result = 78
if result == 78
Use ==.
Go
DELETE FROM orders WHERE name=59
DELETE FROM orders WHERE name=59;
Add semicolon.
SQL
let mut x=37; let ref1=&mut x; let ref2=&mut x;
let mut x=37; {{ let ref1=&mut x; }} let ref2=&mut x;
Only one mutable borrow.
Rust
const person:Person = {{name:'data'}};
const person:Person = {{name:'data', age:37}};
Add missing property.
TypeScript
UPDATE orders SET age='message' WHERE status=8
UPDATE orders SET age='message' WHERE status=8;
Add semicolon.
SQL
["world", 96]
["world", 96]
Correct.
JSON
data(87)
if length(data) >= 87, data(87), end
Check length.
MATLAB
let y: number | null = null; y.toFixed(2);
let y: number | null = null; if(y!==null) y.toFixed(2);
Null check.
TypeScript
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
if x = 93 {{}}
if x == 93 {{}}
Use ==.
Swift
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(42);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(42, () => console.log('listening'));
Add callback.
Node.js
jwt.sign({{id:24}}, 'key');
jwt.sign({{id:24}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
if item > 10 puts 'message'
if item > 10 puts 'message' end
Add 'end'.
Ruby
if x = 42:
if x == 42:
Use == for comparison.
Python
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
b = 60
b=60
No spaces.
Shell
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
function render() {{ echo 'hello'; }}
function render() {{ echo 'hello'; }}
Correct.
PHP
SELECT id role FROM users;
SELECT id, role FROM users;
Add comma.
SQL
if (item = 59) {{}}
if (item == 59) {{}}
Use ==.
Java
if (a = 66)
if (a == 66)
Use ==.
R
c = world
c = 'world'
Quote strings.
Python
values[19]
if values.indices.contains(19) {{ values[19] }}
Check index.
Swift
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
for (int i=0; i<34; i++) {{}}
for (int i=0; i<34; i++) {{}}
Correct.
Java
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
{{'value':'info'}}
{{"value":"info"}}
Use double quotes.
JSON
<hr></hr>
<hr>
Self-closing.
HTML
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
// comment
/* comment */
Use /* */.
CSS
h1 {{ font-size:85px color:blue; }}
h1 {{ font-size:85px; color:blue; }}
Add semicolon.
CSS
'12' + 71
12 + 71
Avoid string coercion.
JavaScript
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
val count: Int = 'world'
val count: String = 'world'
Fix type.
Kotlin
{{"status":"result",}}
{{"status":"result"}}
Remove trailing comma.
JSON
'result' + 66
'result' + str(66)
Can't add int to string.
Python
<person><desc>data</desc><desc>84</desc></person
<person><desc>data</desc><desc>84</desc></person>
Add closing >.
XML
if ($z = 47)
if ($z == 47)
Use ==.
Perl
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
disp('message')
disp('message')
Correct.
MATLAB
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
[2, 6, 56
[2, 6, 56]
Close bracket.
Ruby
match result {{ 1 => {{}} }}
match result {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
$index = 2; if ($index = 2) {{}}
$index = 2; if ($index == 2) {{}}
Use ==.
PHP
if [ $foo = 24 ]; then
if [ "$foo" = 24 ]; then
Quote variable.
Shell
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
handle
handle()
Add parentheses.
Swift
if ($y = 72) {{}}
if ($y -eq 72) {{}}
Use -eq.
PowerShell
<p>result <b>hello</p></b>
<p>result <b>hello</b></p>
Nest properly.
HTML
function baz(a:string){{return a;}} baz(70);
function baz(a:string){{return a;}} baz('data');
Pass correct type.
TypeScript
baz
baz()
Add parentheses.
Kotlin
arr.forEach(function(index) {{ console.log(index); }})
arr.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
int list[44]; list[44]=5;
int list[44]; if(44<44){{}} else list[44]=5;
Bounds check.
C++
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
WHERE status = '28'
WHERE status = 28
Don't quote integer.
SQL
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
cin >> result;
int result; cin >> result;
Declare variable.
C++
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
value: world name: data,
value: world name: data
Remove comma.
YAML
<?php // code ?>
<?php // code ?>
Correct.
PHP
my @arr = (90,43,25);
my @arr = (90,43,25);
Correct.
Perl
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
class Order {{ int foo; }};
class Order {{ public: int foo; }};
Make public.
C++
fn bar() -> i32 {{ 57 }}
fn bar() -> i32 {{ 57 }}
Correct.
Rust
int[] list = new int[8]; list[8] = 5;
int[] list = new int[8]; if (8 < list.length) list[8] = 5;
Check bounds.
Java
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
INSERT INTO items VALUES ('test',83)
INSERT INTO items (name, role) VALUES ('test',83);
Specify columns.
SQL
for foo in range(12) print(foo)
for foo in range(12): print(foo)
Colon after for.
Python
else print('message')
else: print('message')
Colon after else.
Python
{{'status':43, 'value' 47}}
{{'status':43, 'value':47}}
Colon missing.
Python
class Product {{ int c; }} obj.c=5;
class Product {{ public int c; }} obj.c=5;
Make field public.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
{{"name":"value" "id":57}}
{{"name":"value", "id":57}}
Add comma.
JSON
if (data = 75)
if (data == 75)
Use ==.
C++
data[47]
if (length(data) >= 47) data[47]
Check length.
R
SELECT * FROM items WHRE email=5;
SELECT * FROM items WHERE email=5;
Fix WHERE.
SQL
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
if x > 93 print('output')
if x > 93: print('output')
Colon missing after if.
Python
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
var data int = 'test'
var data string = 'test'
Type mismatch.
Go
if foo = 31
if foo == 31
Use ==.
Ruby