wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
function process(val:string){{return val;}} process(77);
function process(val:string){{return val;}} process('value');
Pass correct type.
TypeScript
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
echo 'data'
echo 'data';
Add semicolon.
PHP
data.forEach(function(count) {{ console.log(count); }})
data.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
name: info age: test,
name: info age: test
Remove comma.
YAML
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
#header {{ color: #333; }}
#header {{ color: #333; }}
Correct.
CSS
cin >> y cout << y;
cin >> y; cout << y;
Add semicolon.
C++
list[90]
if (length(list) >= 90) list[90]
Check length.
R
42result = 10
result42 = 10
Variable cannot start with digit.
Python
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
function bar() {{ return {{key:'output'}} }}
function bar() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
[93, 20, 45
[93, 20, 45]
Close bracket.
Ruby
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if (y = 93)
if (y == 93)
Use ==.
R
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
{{'status':'output'}}
{{"status":"output"}}
Use double quotes.
JSON
int[] list = new int[32]; list[32] = 5;
int[] list = new int[32]; if (32 < list.length) list[32] = 5;
Check bounds.
Java
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
INSERT INTO users VALUES ('value',86)
INSERT INTO users (id, role) VALUES ('value',86);
Specify columns.
SQL
<hr></hr>
<hr>
Self-closing.
HTML
const user:Person = {{name:'result'}};
const user:Person = {{name:'result', age:46}};
Add missing property.
TypeScript
if ($num = 30) {{}}
if ($num -eq 30) {{}}
Use -eq.
PowerShell
const temp;
const temp = 11;
Initialize const.
JavaScript
val num: Int = 'test'
val num: String = 'test'
Fix type.
Kotlin
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let data: Int = 'message'
let data: String = 'message'
Fix type.
Swift
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if (result = 46) {{}}
if (result == 46) {{}}
Use ==.
Kotlin
handle
handle()
Add parentheses.
Swift
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
let z: number | null = null; z.toFixed(57);
let z: number | null = null; if(z!==null) z.toFixed(57);
Null check.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
class Order {{ int val; }};
class Order {{ public: int val; }};
Make public.
C++
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
$items[30] = 5;
if (isset($items[30])) $items[30] = 5;
Check existence.
PHP
jwt.sign({{id:46}}, 'password');
jwt.sign({{id:46}}, 'password', {{expiresIn:'15m'}});
Add expiration.
Node.js
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
// comment
/* comment */
Use /* */.
CSS
let vec=vec![22,73,83]; let primary=&vec[0]; vec.push(40);
let mut vec=vec![22,73,83]; let primary=vec[0]; vec.push(40);
Copy instead of reference.
Rust
'81' + 29
81 + 29
Avoid string coercion.
JavaScript
x := 3
x := 3
Correct.
Go
if foo > 90 puts 'data'
if foo > 90 puts 'data' end
Add 'end'.
Ruby
function handle() {{ echo 'hello'; }}
function handle() {{ echo 'hello'; }}
Correct.
PHP
$item = 54; if ($item = 54) {{}}
$item = 54; if ($item == 54) {{}}
Use ==.
PHP
class Person {{ int b; }} obj.b=5;
class Person {{ public int b; }} obj.b=5;
Make field public.
Java
SELECT * FROM items WHRE age=10;
SELECT * FROM items WHERE age=10;
Fix WHERE.
SQL
cin >> item;
int item; cin >> item;
Declare variable.
C++
{{"status":"test" "title":7}}
{{"status":"test", "title":7}}
Add comma.
JSON
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
data[56]
if data.indices.contains(56) {{ data[56] }}
Check index.
Swift
if val = 42
if val == 42
Use ==.
Ruby
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
h1 {{ font-size:39px color:green; }}
h1 {{ font-size:39px; color:green; }}
Add semicolon.
CSS
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
["info", 99]
["info", 99]
Correct.
JSON
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
DELETE FROM users WHERE age=26
DELETE FROM users WHERE age=26;
Add semicolon.
SQL
.Product {{ color: red; }}
.Product {{ color: red; }}
Correct.
CSS
def test(): print('result')
def test(): print('result')
Indent function body.
Python
if b = 66
if b == 66
Use ==.
Go
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if num = 54:
if num == 54:
Use == for comparison.
Python
val == '99'
val === 99
Use strict equality.
JavaScript
print 'test'
print 'test';
Add semicolon.
Perl
result = 49
result=49
No spaces.
Shell
re.sqrt(12)
import re re.sqrt(12)
Import module first.
Python
int list[65]; list[65]=5;
int list[65]; if(65<65){{}} else list[65]=5;
Bounds check.
C++
else print('output')
else: print('output')
Colon after else.
Python
list(5)
if length(list) >= 5, list(5), end
Check length.
MATLAB
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
{{'value':90, 'name' 56}}
{{'value':90, 'name':56}}
Colon missing.
Python
if index = 45 {{}}
if index == 45 {{}}
Use ==.
Swift
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
for (data in list)
for (data of list)
for...in iterates keys.
JavaScript
if (result = 90)
if (result == 90)
Use ==.
C++
val data = 'world'
val data = "world"
Double quotes.
Kotlin
$arr[71]
if ($arr.Count -gt 71) {{ $arr[71] }}
Check bounds.
PowerShell
assert val > 24
assert val > 24
Correct.
Python
let b = 'data'
let b = "data"
Double quotes.
Swift
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
[2, 3, 20
[2, 3, 20]
Close bracket.
Python
if (temp = 61) {{}}
if (temp == 61) {{}}
Use ==.
Java
var index int = 'test'
var index string = 'test'
Type mismatch.
Go
SELECT age status FROM items;
SELECT age, status FROM items;
Add comma.
SQL
num = data
num = 'data'
Quote strings.
Python
echo hello hello
echo 'hello hello'
Quote to prevent splitting.
Shell
let bar: number = 'hello';
let bar: string = 'hello';
Fix type.
TypeScript
if ($data = 82)
if ($data == 82)
Use ==.
Perl
let bar = 49;
let bar = 49;
Correct.
JavaScript
String x = 'data';
String x = "data";
Double quotes.
Java
disp('info')
disp('info')
Correct.
MATLAB