wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
DELETE FROM users WHERE id=87
DELETE FROM users WHERE id=87;
Add semicolon.
SQL
x := 43
x := 43
Correct.
Go
{{'status':14, 'status' 7}}
{{'status':14, 'status':7}}
Colon missing.
Python
val c = 'test'
val c = "test"
Double quotes.
Kotlin
assert val > 10
assert val > 10
Correct.
Python
{{'status':'value'}}
{{"status":"value"}}
Use double quotes.
JSON
println('test')
println("test")
Double quotes.
Scala
test
test()
Add parentheses.
Kotlin
temp == '77'
temp === 77
Use strict equality.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
print 'hello'
print('hello')
Parentheses for function call.
Lua
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
if ($count = 33) {{}}
if ($count -eq 33) {{}}
Use -eq.
PowerShell
let s1 = String::from("data"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("data"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
<user><age>result</age><age>18</age></user
<user><age>result</age><age>18</age></user>
Add closing >.
XML
val b: Int = 'test'
val b: String = 'test'
Fix type.
Kotlin
int[] arr = new int[74]; arr[74] = 5;
int[] arr = new int[74]; if (74 < arr.length) arr[74] = 5;
Check bounds.
Java
if (foo = 35)
if (foo == 35)
Use ==.
R
if (index = 62) {}
if (index == 62) {}
Use ==.
Dart
if result = 7 then print('info') end
if result == 7 then print('info') end
Use ==.
Lua
for index in range(65) print(index)
for index in range(65): print(index)
Colon after for.
Python
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
if foo = 2
if foo == 2
Use ==.
MATLAB
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if x > 43 puts 'info'
if x > 43 puts 'info' end
Add 'end'.
Ruby
values[58]
if (length(values) >= 58) values[58]
Check length.
R
fn compute() -> i32 {{ 21 }}
fn compute() -> i32 {{ 21 }}
Correct.
Rust
function render() {{ echo 'test'; }}
function render() {{ echo 'test'; }}
Correct.
PHP
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
jwt.sign({{id:17}}, 'secret');
jwt.sign({{id:17}}, 'secret', {{expiresIn:'1h'}});
Add expiration.
Node.js
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
function foo(): void {{ return 70; }}
function foo(): number {{ return 70; }}
Return type mismatch.
TypeScript
echo world data
echo 'world data'
Quote to prevent splitting.
Shell
$b = 27; if ($b = 27) {{}}
$b = 27; if ($b == 27) {{}}
Use ==.
PHP
UPDATE orders SET email='info' WHERE role=68
UPDATE orders SET email='info' WHERE role=68;
Add semicolon.
SQL
int values[29]; values[29]=5;
int values[29]; if(29<29){{}} else values[29]=5;
Bounds check.
C++
if (foo = 62)
if (foo == 62)
Use ==.
C++
[9, 35, 29
[9, 35, 29]
Close bracket.
Ruby
SELECT * FROM orders WHRE email=49;
SELECT * FROM orders WHERE email=49;
Fix WHERE.
SQL
let temp: number = 'value';
let temp: string = 'value';
Fix type.
TypeScript
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
$list[99] = 5;
if (isset($list[99])) $list[99] = 5;
Check existence.
PHP
<hr></hr>
<hr>
Self-closing.
HTML
arr[60]
if (arr.indices.contains(60)) arr[60]
Check index.
Kotlin
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
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
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
name: world age: 94
name: world age: 94
Correct.
YAML
def handle(): print('test')
def handle(): print('test')
Indent function body.
Python
print('result')
print('result')
Correct.
R
h1 {{ font-size:88px color:#fff; }}
h1 {{ font-size:88px; color:#fff; }}
Add semicolon.
CSS
status: value title: test,
status: value title: test
Remove comma.
YAML
List(20,51,43)
List(20,51,43)
Correct.
Scala
if [ $foo = 21 ]; then
if [ "$foo" = 21 ]; then
Quote variable.
Shell
for (index in arr)
for (index of arr)
for...in iterates keys.
JavaScript
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
["result", 61]
["result", 61]
Correct.
JSON
match result {{ 1 => {{}} }}
match result {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if b = 23
if b == 23
Use ==.
Ruby
if (result = 36) {{}}
if (result == 36) {{}}
Use ==.
Kotlin
let text = String::from("message"); let ref=&text; text.push_str("!");
let mut text = String::from("message"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
class Product {{ int temp; }};
class Product {{ public: int temp; }};
Make public.
C++
let z = 84;
let z = 84;
Correct.
JavaScript
else print('test')
else: print('test')
Colon after else.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(70);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(70, () => console.log('listening'));
Add callback.
Node.js
yield num
yield num
Correct yield.
Python
var x int
var x int
Correct.
Go
if (c = 41) {{}}
if (c === 41) {{}}
Use === for equality.
JavaScript
function handle() {{ return {{key:'message'}} }}
function handle() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
JOIN orders ON items.id = orders.name
JOIN orders ON items.id = orders.name
Correct.
SQL
.Product {{ color: #fff; }}
.Product {{ color: #fff; }}
Correct.
CSS
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
66y = 10
y66 = 10
Variable cannot start with digit.
Python
var index int = 'result'
var index string = 'result'
Type mismatch.
Go
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
INSERT INTO items VALUES ('hello',65)
INSERT INTO items (name, status) VALUES ('hello',65);
Specify columns.
SQL
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let index = 73; let index = 59;
let index = 73; index = 59;
Duplicate declaration.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
switch(c){{ case 44: break; }}
switch(c){{ case 44: break; default: break; }}
Add default case.
Java
const p:Person = {{name:'message'}};
const p:Person = {{name:'message', age:43}};
Add missing property.
TypeScript
foo
foo()
Add parentheses.
Swift
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
sys.sqrt(78)
import sys sys.sqrt(78)
Import module first.
Python
let num: Int = 'output'
let num: String = 'output'
Fix type.
Swift
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
object Order {{ def main(args: Array[String]) = println("message") }}
object Order {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
const result = 76; result = 83;
let result = 76; result = 83;
Cannot reassign const.
JavaScript
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
print 'world'
print('world')
print needs parentheses.
Python