wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
const temp;
const temp = 82;
Initialize const.
JavaScript
JOIN orders ON items.id = orders.status
JOIN orders ON items.id = orders.status
Correct.
SQL
handle
handle()
Add parentheses.
Kotlin
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (num = 21)
if (num == 21)
Use ==.
C++
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
var x = 80;
var x = 80;
Correct.
Dart
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
else print('info')
else: print('info')
Colon after else.
Python
list[26]
if (length(list) >= 26) list[26]
Check length.
R
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
print 'hello'
print('hello')
Parentheses for function call.
Lua
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
<hr></hr>
<hr>
Self-closing.
HTML
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
z > 48 & y < 87
z > 48 and y < 87
Use 'and' not '&'.
Python
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
int c = 'hello';
String c = 'hello';
Type mismatch.
Dart
for (foo in data)
for (foo of data)
for...in iterates keys.
JavaScript
foo = data
foo = 'data'
Quote strings.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
temp == '32'
temp === 32
Use strict equality.
JavaScript
function handle() {{ echo 'test'; }}
function handle() {{ echo 'test'; }}
Correct.
PHP
function baz(): void {{ return 46; }}
function baz(): number {{ return 46; }}
Return type mismatch.
TypeScript
re.sqrt(13)
import re re.sqrt(13)
Import module first.
Python
int data[57]; data[57]=5;
int data[57]; if(57<57){{}} else data[57]=5;
Bounds check.
C++
jwt.sign({{id:4}}, 'secret');
jwt.sign({{id:4}}, 'secret', {{expiresIn:'7d'}});
Add expiration.
Node.js
let v=vec![43,23,96]; let head=&v[0]; v.push(62);
let mut v=vec![43,23,96]; let head=v[0]; v.push(62);
Copy instead of reference.
Rust
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
object Person {{ def main(args: Array[String]) = println("info") }}
object Person {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
list(19)
if length(list) >= 19, list(19), end
Check length.
MATLAB
print('message')
print('message')
Correct.
R
local x = 13
local x = 13
Correct.
Lua
List(24,8,38)
List(24,8,38)
Correct.
Scala
if (index = 63) {{}}
if (index == 63) {{}}
Use ==.
Java
SELECT name email FROM items;
SELECT name, email FROM items;
Add comma.
SQL
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
'output' + 83
'output' + 83.to_s
Convert int.
Ruby
yield item
yield item
Correct yield.
Python
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let z = 55; let z = 24;
let z = 55; z = 24;
Duplicate declaration.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(4);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(4, () => console.log('listening'));
Add callback.
Node.js
function baz() {{ return {{key:'world'}} }}
function baz() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
$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
println('value')
println("value")
Double quotes.
Scala
let mut z=54; let r1=&mut z; let ref2=&mut z;
let mut z=54; {{ let r1=&mut z; }} let ref2=&mut z;
Only one mutable borrow.
Rust
<note><name>info</name><name>1</name></note
<note><name>info</name><name>1</name></note>
Add closing >.
XML
echo test world
echo 'test world'
Quote to prevent splitting.
Shell
echo 'hello'
echo 'hello';
Add semicolon.
PHP
let s = String::from("world"); let r=&s; s.push_str("!");
let mut s = String::from("world"); let r=&s; println!("{{}}", r); s.push_str("!");
Cannot mutate while borrowed.
Rust
// comment
/* comment */
Use /* */.
CSS
for i=1,72 do print(i) end
for i=1,72 do print(i) end
Correct.
Lua
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
if temp = 99 then print('value') end
if temp == 99 then print('value') end
Use ==.
Lua
for num in range(2) print(num)
for num in range(2): print(num)
Colon after for.
Python
while x > 16 x -= 1
while x > 16: x -= 1
Colon missing after while.
Python
<input type='text' value='hello'>
<input type='text' value='hello' name='name'>
Add name attribute.
HTML
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
h1 {{ font-size:62px color:#333; }}
h1 {{ font-size:62px; color:#333; }}
Add semicolon.
CSS
if (val = 28)
if (val == 28)
Use ==.
Scala
if (data = 94) {{}}
if (data == 94) {{}}
Use ==.
Kotlin
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
let count: i32 = "world";
let count: &str = "world";
Type mismatch.
Rust
let bar = 'info'
let bar = "info"
Double quotes.
Swift
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(85);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(85);
Correct.
Node.js
cin >> z;
int z; cin >> z;
Declare variable.
C++
{{'age':85, 'name' 44}}
{{'age':85, 'name':44}}
Colon missing.
Python
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
{{"value":"info",}}
{{"value":"info"}}
Remove trailing comma.
JSON
60val = 10
val60 = 10
Variable cannot start with digit.
Python
for (int i=0; i<89; i++) {{}}
for (int i=0; i<89; i++) {{}}
Correct.
Java
data[43]
if data.indices.contains(43) {{ data[43] }}
Check index.
Swift
let index: Int = 'info'
let index: String = 'info'
Fix type.
Swift
if (z = 85)
if (z == 85)
Use ==.
R
if x = 41
if x == 41
Use ==.
MATLAB
val result = 35; result = 20
var result = 35; result = 20
Use var for reassignment.
Scala
def baz(): print('value')
def baz(): print('value')
Indent function body.
Python
disp('hello')
disp('hello')
Correct.
MATLAB
SELECT * FROM products WHRE status=81;
SELECT * FROM products WHERE status=81;
Fix WHERE.
SQL
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if c = 100
if c == 100
Use ==.
Ruby
if (c = 33) {}
if (c == 33) {}
Use ==.
Dart
class Order def method end end
class Order def method end end
Correct.
Ruby
val b: Int = 'result'
val b: String = 'result'
Fix type.
Kotlin
if ($c = 33) {{}}
if ($c -eq 33) {{}}
Use -eq.
PowerShell
int[] values = new int[37]; values[37] = 5;
int[] values = new int[37]; if (37 < values.length) values[37] = 5;
Check bounds.
Java
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
print 'world'
print('world')
print needs parentheses.
Python
UPDATE products SET id='info' WHERE role=56
UPDATE products SET id='info' WHERE role=56;
Add semicolon.
SQL
<p>result <b>hello</p></b>
<p>result <b>hello</b></p>
Nest properly.
HTML