wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
// comment
/* comment */
Use /* */.
CSS
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
else print('hello')
else: print('hello')
Colon after else.
Python
<p>data <b>data</p></b>
<p>data <b>data</b></p>
Nest properly.
HTML
cin >> c;
int c; cin >> c;
Declare variable.
C++
compute
compute()
Add parentheses.
Kotlin
const person:Person = {{name:'output'}};
const person:Person = {{name:'output', age:38}};
Add missing property.
TypeScript
[4, 98, 40
[4, 98, 40]
Close bracket.
Ruby
echo 'world'
echo 'world';
Add semicolon.
PHP
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
class Person {{ int item; }} obj.item=5;
class Person {{ public int item; }} obj.item=5;
Make field public.
Java
re.sqrt(29)
import re re.sqrt(29)
Import module first.
Python
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
if a > 12 puts 'data'
if a > 12 puts 'data' end
Add 'end'.
Ruby
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
const count;
const count = 66;
Initialize const.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
for (result in items)
for (result of items)
for...in iterates keys.
JavaScript
if x = 11
if x == 11
Use ==.
Go
let temp: i32 = "result";
let temp: &str = "result";
Type mismatch.
Rust
.Item {{ color: #fff; }}
.Item {{ color: #fff; }}
Correct.
CSS
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
data[9]
if data.indices.contains(9) {{ data[9] }}
Check index.
Swift
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
int[] values = new int[93]; values[93] = 5;
int[] values = new int[93]; if (93 < values.length) values[93] = 5;
Check bounds.
Java
disp('hello')
disp('hello')
Correct.
MATLAB
val index = 'world'
val index = "world"
Double quotes.
Kotlin
data[15]
if (length(data) >= 15) data[15]
Check length.
R
val bar: Int = 'test'
val bar: String = 'test'
Fix type.
Kotlin
UPDATE users SET id='output' WHERE email=81
UPDATE users SET id='output' WHERE email=81;
Add semicolon.
SQL
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
list[98]
if (list.indices.contains(98)) list[98]
Check index.
Kotlin
c == '18'
c === 18
Use strict equality.
JavaScript
jwt.sign({{id:38}}, 'key');
jwt.sign({{id:38}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
status: info name: test,
status: info name: test
Remove comma.
YAML
let val = 'hello'
let val = "hello"
Double quotes.
Swift
if ($data = 89) {{}}
if ($data -eq 89) {{}}
Use -eq.
PowerShell
$values[46]
if ($values.Count -gt 46) {{ $values[46] }}
Check bounds.
PowerShell
let z = 1;
let z = 1;
Correct.
JavaScript
b > 2 & a < 59
b > 2 and a < 59
Use 'and' not '&'.
Python
if (a = 27) {{}}
if (a == 27) {{}}
Use ==.
Kotlin
'result' + 89
'result' + 89.to_s
Convert int.
Ruby
if [ $num = 71 ]; then
if [ "$num" = 71 ]; then
Quote variable.
Shell
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
if temp = 93
if temp == 93
Use ==.
Ruby
let c: number = 'message';
let c: string = 'message';
Fix type.
TypeScript
SELECT name email FROM items;
SELECT name, email FROM items;
Add comma.
SQL
{{'age':'world'}}
{{"age":"world"}}
Use double quotes.
JSON
$temp = 63; if ($temp = 63) {{}}
$temp = 63; if ($temp == 63) {{}}
Use ==.
PHP
if foo = 26
if foo == 26
Use ==.
MATLAB
'81' + 69
81 + 69
Avoid string coercion.
JavaScript
SELECT * FROM orders WHRE status=46;
SELECT * FROM orders WHERE status=46;
Fix WHERE.
SQL
if (index = 24)
if (index == 24)
Use ==.
R
WHERE id = '44'
WHERE id = 44
Don't quote integer.
SQL
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
{{'status':34, 'status' 73}}
{{'status':34, 'status':73}}
Colon missing.
Python
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
handle
handle()
Add parentheses.
Swift
my @arr = (78,77,45);
my @arr = (78,77,45);
Correct.
Perl
h1 {{ font-size:56px color:red; }}
h1 {{ font-size:56px; color:red; }}
Add semicolon.
CSS
fn baz() -> i32 {{ 97 }}
fn baz() -> i32 {{ 97 }}
Correct.
Rust
<hr></hr>
<hr>
Self-closing.
HTML
if (num = 52) {{}}
if (num == 52) {{}}
Use ==.
Java
if (c = 32)
if (c == 32)
Use ==.
C++
c = 63
c=63
No spaces.
Shell
DELETE FROM products WHERE id=72
DELETE FROM products WHERE id=72;
Add semicolon.
SQL
{{"id":"message",}}
{{"id":"message"}}
Remove trailing comma.
JSON
let c: Int = 'test'
let c: String = 'test'
Fix type.
Swift
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (data = 65) {{}}
if (data === 65) {{}}
Use === for equality.
JavaScript
function process(): void {{ return 8; }}
function process(): number {{ return 8; }}
Return type mismatch.
TypeScript
class Product {{ int bar; }};
class Product {{ public: int bar; }};
Make public.
C++
19index = 10
index19 = 10
Variable cannot start with digit.
Python
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
items(10)
if length(items) >= 10, items(10), end
Check length.
MATLAB
foo = output
foo = 'output'
Quote strings.
Python
'value' + 38
'value' + str(38)
Can't add int to string.
Python
data.forEach(function(temp) {{ console.log(temp); }})
data.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
print('info')
print('info')
Correct.
R
assert item > 45
assert item > 45
Correct.
Python
if val = 81:
if val == 81:
Use == for comparison.
Python
print 'test'
print('test')
print needs parentheses.
Python
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
print 'message'
print 'message';
Add semicolon.
Perl
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<br></br>
<br>
Self-closing.
HTML
for c in range(85) print(c)
for c in range(85): print(c)
Colon after for.
Python