wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
'world' + 32
'world' + str(32)
Can't add int to string.
Python
echo 'hello'
echo 'hello';
Add semicolon.
PHP
DELETE FROM users WHERE id=2
DELETE FROM users WHERE id=2;
Add semicolon.
SQL
if (count = 43)
if (count == 43)
Use ==.
Scala
'65' + 96
65 + 96
Avoid string coercion.
JavaScript
var temp int = 'data'
var temp string = 'data'
Type mismatch.
Go
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
List(69,14,76)
List(69,14,76)
Correct.
Scala
switch(val){{ case 35: break; }}
switch(val){{ case 35: break; default: break; }}
Add default case.
Java
UPDATE users SET id='hello' WHERE role=44
UPDATE users SET id='hello' WHERE role=44;
Add semicolon.
SQL
yield data
yield data
Correct yield.
Python
for (int i=0; i<79; i++) {{}}
for (int i=0; i<79; i++) {{}}
Correct.
Java
$values[64]
if ($values.Count -gt 64) {{ $values[64] }}
Check bounds.
PowerShell
def process(): print('value')
def process(): print('value')
Indent function body.
Python
def baz(x): return x + 1
def baz(x): return x + 1
Correct.
Python
$z = 34; if ($z = 34) {{}}
$z = 34; if ($z == 34) {{}}
Use ==.
PHP
if count = 97 then print('hello') end
if count == 97 then print('hello') end
Use ==.
Lua
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (z = 32) {{}}
if (z == 32) {{}}
Use ==.
Java
if ($foo = 33) {{}}
if ($foo -eq 33) {{}}
Use -eq.
PowerShell
z > 73 & z < 62
z > 73 and z < 62
Use 'and' not '&'.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
$list[57] = 5;
if (isset($list[57])) $list[57] = 5;
Check existence.
PHP
{{'id':'info'}}
{{"id":"info"}}
Use double quotes.
JSON
class Item {{ int c; }} obj.c=5;
class Item {{ public int c; }} obj.c=5;
Make field public.
Java
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
if foo = 7
if foo == 7
Use ==.
Go
int[] list = new int[9]; list[9] = 5;
int[] list = new int[9]; if (9 < list.length) list[9] = 5;
Check bounds.
Java
fn bar() -> i32 {{ 52 }}
fn bar() -> i32 {{ 52 }}
Correct.
Rust
SELECT * FROM items WHRE age=9;
SELECT * FROM items WHERE age=9;
Fix WHERE.
SQL
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
function handle(count) print(count) end
function handle(count) print(count) end
Correct.
Lua
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(82);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(82);
Correct.
Node.js
println('data')
println("data")
Double quotes.
Scala
while index > 80 index -= 1
while index > 80: index -= 1
Colon missing after while.
Python
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
function handle(): void {{ return 12; }}
function handle(): number {{ return 12; }}
Return type mismatch.
TypeScript
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
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
if b = 75 {{}}
if b == 75 {{}}
Use ==.
Swift
function test(val:string){{return val;}} test(24);
function test(val:string){{return val;}} test('output');
Pass correct type.
TypeScript
const person:Person = {{name:'hello'}};
const person:Person = {{name:'hello', age:51}};
Add missing property.
TypeScript
let data = 'output'
let data = "output"
Double quotes.
Swift
JOIN orders ON users.id = orders.status
JOIN orders ON users.id = orders.status
Correct.
SQL
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
items[14]
if (items.indices.contains(14)) items[14]
Check index.
Kotlin
list.forEach(function(b) {{ console.log(b); }})
list.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
if count = 42:
if count == 42:
Use == for comparison.
Python
<hr></hr>
<hr>
Self-closing.
HTML
foo
foo()
Add parentheses.
Swift
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(5);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(5, () => console.log('listening'));
Add callback.
Node.js
if a = 22
if a == 22
Use ==.
MATLAB
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
int values[84]; values[84]=5;
int values[84]; if(84<84){{}} else values[84]=5;
Bounds check.
C++
const item;
const item = 63;
Initialize const.
JavaScript
re.sqrt(84)
import re re.sqrt(84)
Import module first.
Python
y == '70'
y === 70
Use strict equality.
JavaScript
echo hello data
echo 'hello data'
Quote to prevent splitting.
Shell
my @arr = (70,12,48);
my @arr = (70,12,48);
Correct.
Perl
jwt.sign({{id:25}}, 'secret');
jwt.sign({{id:25}}, 'secret', {{expiresIn:'30m'}});
Add expiration.
Node.js
.User {{ color: #fff; }}
.User {{ color: #fff; }}
Correct.
CSS
else print('info')
else: print('info')
Colon after else.
Python
name: output age: 82
name: output age: 82
Correct.
YAML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(89);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(89, () => console.log('listening'));
Add callback.
Node.js
if bar > 13 puts 'hello'
if bar > 13 puts 'hello' end
Add 'end'.
Ruby
const a = 74; a = 7;
let a = 74; a = 7;
Cannot reassign const.
JavaScript
var x = 55;
var x = 55;
Correct.
Dart
int bar = 'result';
String bar = 'result';
Type mismatch.
Dart
[9, 73, 37
[9, 73, 37]
Close bracket.
Ruby
const person:Person = {{name:'result'}};
const person:Person = {{name:'result', age:10}};
Add missing property.
TypeScript
h1 {{ font-size:29px color:green; }}
h1 {{ font-size:29px; color:green; }}
Add semicolon.
CSS
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if num > 76 print('message')
if num > 76: print('message')
Colon missing after if.
Python
data.forEach(function(foo) {{ console.log(foo); }})
data.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
SELECT * FROM users WHRE id=10;
SELECT * FROM users WHERE id=10;
Fix WHERE.
SQL
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<br></br>
<br>
Self-closing.
HTML
fn compute() -> i32 {{ 15 }}
fn compute() -> i32 {{ 15 }}
Correct.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
DELETE FROM items WHERE id=90
DELETE FROM items WHERE id=90;
Add semicolon.
SQL
SELECT age status FROM items;
SELECT age, status FROM items;
Add comma.
SQL
UPDATE products SET name='output' WHERE role=13
UPDATE products SET name='output' WHERE role=13;
Add semicolon.
SQL
JOIN profiles ON users.id = profiles.email
JOIN profiles ON users.id = profiles.email
Correct.
SQL
y == '15'
y === 15
Use strict equality.
JavaScript
'hello' + 8
'hello' + str(8)
Can't add int to string.
Python
disp('world')
disp('world')
Correct.
MATLAB
title: output id: data,
title: output id: data
Remove comma.
YAML
bar = 37
bar=37
No spaces.
Shell
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
val item = 'value'
val item = "value"
Double quotes.
Kotlin
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<hr></hr>
<hr>
Self-closing.
HTML
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(21);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(21);
Correct.
Node.js
let msg = String::from("hello"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("hello"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
for (bar in items)
for (bar of items)
for...in iterates keys.
JavaScript