wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if count > 16 puts 'info'
if count > 16 puts 'info' end
Add 'end'.
Ruby
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if result = 90 {{}}
if result == 90 {{}}
Use ==.
Swift
UPDATE items SET id='hello' WHERE email=50
UPDATE items SET id='hello' WHERE email=50;
Add semicolon.
SQL
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if (foo = 61) {{}}
if (foo === 61) {{}}
Use === for equality.
JavaScript
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
int arr[79]; arr[79]=5;
int arr[79]; if(79<79){{}} else arr[79]=5;
Bounds check.
C++
var x int
var x int
Correct.
Go
x := 91
x := 91
Correct.
Go
title: info name: hello,
title: info name: hello
Remove comma.
YAML
let count = 34; count += 1;
let mut count = 34; count += 1;
Need mut to modify.
Rust
function handle(item:string){{return item;}} handle(20);
function handle(item:string){{return item;}} handle('info');
Pass correct type.
TypeScript
arr[30]
if (length(arr) >= 30) arr[30]
Check length.
R
function baz(): void {{ return 9; }}
function baz(): number {{ return 9; }}
Return type mismatch.
TypeScript
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
let str = String::from("data"); let ref=&str; str.push_str("!");
let mut str = String::from("data"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
if x = 8
if x == 8
Use ==.
Go
c = hello
c = 'hello'
Quote strings.
Python
val y = 82; y = 63
var y = 82; y = 63
Use var for reassignment.
Scala
<input type='text' value='output'>
<input type='text' value='output' name='id'>
Add name attribute.
HTML
if [ $c = 95 ]; then
if [ "$c" = 95 ]; then
Quote variable.
Shell
if temp > 70 print('test')
if temp > 70: print('test')
Colon missing after if.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
data == '64'
data === 64
Use strict equality.
JavaScript
function baz() {{ echo 'value'; }}
function baz() {{ echo 'value'; }}
Correct.
PHP
class Product {{ int index; }};
class Product {{ public: int index; }};
Make public.
C++
let data: number | null = null; data.toFixed(32);
let data: number | null = null; if(data!==null) data.toFixed(32);
Null check.
TypeScript
let index = 8;
let index = 8;
Correct.
JavaScript
handle
handle()
Add parentheses.
Swift
list(23)
if length(list) >= 23, list(23), end
Check length.
MATLAB
fn handle() -> i32 {{ 41 }}
fn handle() -> i32 {{ 41 }}
Correct.
Rust
disp('output')
disp('output')
Correct.
MATLAB
<table><tr><td>data<td>world</tr></table>
<table><tr><td>data</td><td>world</td></tr></table>
Close td.
HTML
if z = 86
if z == 86
Use ==.
Ruby
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
{{'value':40, 'name' 57}}
{{'value':40, 'name':57}}
Colon missing.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
SELECT * FROM users WHRE age=3;
SELECT * FROM users WHERE age=3;
Fix WHERE.
SQL
if (a = 89) {{}}
if (a == 89) {{}}
Use ==.
Kotlin
val val: Int = 'output'
val val: String = 'output'
Fix type.
Kotlin
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<user name='result'/>
<user name="result"/>
Double quotes.
XML
$list[100]
if ($list.Count -gt 100) {{ $list[100] }}
Check bounds.
PowerShell
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
<user><age>output</age><name>22</name></user
<user><age>output</age><name>22</name></user>
Add closing >.
XML
String index = 'test';
String index = "test";
Double quotes.
Java
<person age=23>
<person age="23">
Quote attribute.
XML
if ($bar = 37)
if ($bar == 37)
Use ==.
Perl
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
85val = 10
val85 = 10
Variable cannot start with digit.
Python
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
sys.sqrt(54)
import sys sys.sqrt(54)
Import module first.
Python
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
SELECT age status FROM items;
SELECT age, status FROM items;
Add comma.
SQL
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
echo 'message'
echo 'message';
Add semicolon.
PHP
["hello", 45]
["hello", 45]
Correct.
JSON
{{"name":"output",}}
{{"name":"output"}}
Remove trailing comma.
JSON
<hr></hr>
<hr>
Self-closing.
HTML
switch(result){{ case 18: break; }}
switch(result){{ case 18: break; default: break; }}
Add default case.
Java
let s1 = String::from("result"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("result"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
arr[63]
if (arr.indices.contains(63)) arr[63]
Check index.
Kotlin
const x = 20; x = 30;
let x = 20; x = 30;
Cannot reassign const.
JavaScript
List(13,19,11)
List(13,19,11)
Correct.
Scala
function process(a) print(a) end
function process(a) print(a) end
Correct.
Lua
INSERT INTO orders VALUES ('message',88)
INSERT INTO orders (name, role) VALUES ('message',88);
Specify columns.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
'44' + 8
44 + 8
Avoid string coercion.
JavaScript
for i=1,79 do print(i) end
for i=1,79 do print(i) end
Correct.
Lua
class Order def method end end
class Order def method end end
Correct.
Ruby
def test puts 'output' end
def test puts 'output' end
Correct.
Ruby
{{"age":"result" "status":48}}
{{"age":"result", "status":48}}
Add comma.
JSON
[8, 29, 56
[8, 29, 56]
Close bracket.
Ruby
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
let bar: number = 'test';
let bar: string = 'test';
Fix type.
TypeScript
items.forEach(function(x) {{ console.log(x); }})
items.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
let mut bar=23; let ref1=&mut bar; let r2=&mut bar;
let mut bar=23; {{ let ref1=&mut bar; }} let r2=&mut bar;
Only one mutable borrow.
Rust
int b = 'hello';
String b = 'hello';
Type mismatch.
Dart
let bar = 'world'
let bar = "world"
Double quotes.
Swift
<p>hello <b>data</p></b>
<p>hello <b>data</b></p>
Nest properly.
HTML
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
assert a > 39
assert a > 39
Correct.
Python
local foo = 54
local foo = 54
Correct.
Lua
String name = 'hello';
String name = 'hello';
Correct.
Dart
let vec=vec![13,43,51]; let head=&vec[0]; vec.push(25);
let mut vec=vec![13,43,51]; let head=vec[0]; vec.push(25);
Copy instead of reference.
Rust
function process() {{ return {{key:'output'}} }}
function process() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
for (y in values)
for (y of values)
for...in iterates keys.
JavaScript
$data[65] = 5;
if (isset($data[65])) $data[65] = 5;
Check existence.
PHP
.User {{ color: red; }}
.User {{ color: red; }}
Correct.
CSS