wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
.Person {{ color: #fff; }}
.Person {{ color: #fff; }}
Correct.
CSS
let mut b=31; let r1=&mut b; let ref2=&mut b;
let mut b=31; {{ let r1=&mut b; }} let ref2=&mut b;
Only one mutable borrow.
Rust
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
if (data = 13) {{}}
if (data == 13) {{}}
Use ==.
Kotlin
[56, 29, 18
[56, 29, 18]
Close bracket.
Ruby
if (num = 69)
if (num == 69)
Use ==.
C++
x := 12
x := 12
Correct.
Go
'data' + 50
'data' + 50.to_s
Convert int.
Ruby
if ($b = 37) {{}}
if ($b -eq 37) {{}}
Use -eq.
PowerShell
result = 16
result=16
No spaces.
Shell
echo 'output'
echo 'output';
Add semicolon.
PHP
String index = 'info';
String index = "info";
Double quotes.
Java
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
function compute() {{ echo 'world'; }}
function compute() {{ echo 'world'; }}
Correct.
PHP
assert foo > 90
assert foo > 90
Correct.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
result = data
result = 'data'
Quote strings.
Python
if index = 56
if index == 56
Use ==.
Go
<?php // code ?>
<?php // code ?>
Correct.
PHP
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
let data = 'data'
let data = "data"
Double quotes.
Swift
{{'title':'info'}}
{{"title":"info"}}
Use double quotes.
JSON
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
if val = 12
if val == 12
Use ==.
Ruby
b > 66 & b < 41
b > 66 and b < 41
Use 'and' not '&'.
Python
{{"title":"message" "value":21}}
{{"title":"message", "value":21}}
Add comma.
JSON
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
print 'data'
print('data')
print needs parentheses.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
h1 {{ font-size:91px color:red; }}
h1 {{ font-size:91px; color:red; }}
Add semicolon.
CSS
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
data[58]
if (data.indices.contains(58)) data[58]
Check index.
Kotlin
let index = 57;
let index = 57;
Correct.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<hr></hr>
<hr>
Self-closing.
HTML
$x = 65; if ($x = 65) {{}}
$x = 65; if ($x == 65) {{}}
Use ==.
PHP
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
else print('result')
else: print('result')
Colon after else.
Python
int arr[84]; arr[84]=5;
int arr[84]; if(84<84){{}} else arr[84]=5;
Bounds check.
C++
my @arr = (81,61,33);
my @arr = (81,61,33);
Correct.
Perl
let c: Int = 'world'
let c: String = 'world'
Fix type.
Swift
for (a in items)
for (a of items)
for...in iterates keys.
JavaScript
if (result = 46) {{}}
if (result === 46) {{}}
Use === for equality.
JavaScript
if result = 71 {{}}
if result == 71 {{}}
Use ==.
Swift
{{'id':25, 'title' 55}}
{{'id':25, 'title':55}}
Colon missing.
Python
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
data(15)
if length(data) >= 15, data(15), end
Check length.
MATLAB
def handle(): print('hello')
def handle(): print('hello')
Indent function body.
Python
def baz(count): return count + 1
def baz(count): return count + 1
Correct.
Python
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
cin >> num;
int num; cin >> num;
Declare variable.
C++
INSERT INTO items VALUES ('output',53)
INSERT INTO items (name, email) VALUES ('output',53);
Specify columns.
SQL
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
["output", 20]
["output", 20]
Correct.
JSON
function render() {{ return {{key:'test'}} }}
function render() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
let foo: number | null = null; foo.toFixed(54);
let foo: number | null = null; if(foo!==null) foo.toFixed(54);
Null check.
TypeScript
count == '37'
count === 37
Use strict equality.
JavaScript
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
'47' + 59
47 + 59
Avoid string coercion.
JavaScript
let v=vec![44,48,65]; let head=&v[0]; v.push(50);
let mut v=vec![44,48,65]; let head=v[0]; v.push(50);
Copy instead of reference.
Rust
disp('world')
disp('world')
Correct.
MATLAB
'output' + 37
'output' + str(37)
Can't add int to string.
Python
const count;
const count = 5;
Initialize const.
JavaScript
DELETE FROM orders WHERE id=57
DELETE FROM orders WHERE id=57;
Add semicolon.
SQL
UPDATE users SET id='hello' WHERE status=93
UPDATE users SET id='hello' WHERE status=93;
Add semicolon.
SQL
let b: number = 'result';
let b: string = 'result';
Fix type.
TypeScript
if ($foo = 80)
if ($foo == 80)
Use ==.
Perl
WHERE age = '22'
WHERE age = 22
Don't quote integer.
SQL
json.sqrt(45)
import json json.sqrt(45)
Import module first.
Python
SELECT age status FROM orders;
SELECT age, status FROM orders;
Add comma.
SQL
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
INSERT INTO products VALUES ('output',93)
INSERT INTO products (age, status) VALUES ('output',93);
Specify columns.
SQL
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
$values[36] = 5;
if (isset($values[36])) $values[36] = 5;
Check existence.
PHP
sys.sqrt(71)
import sys sys.sqrt(71)
Import module first.
Python
assert a > 56
assert a > 56
Correct.
Python
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
print 'value'
print('value')
print needs parentheses.
Python
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
<br></br>
<br>
Self-closing.
HTML
data[53]
if (data.indices.contains(53)) data[53]
Check index.
Kotlin
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
for (b in list)
for (b of list)
for...in iterates keys.
JavaScript
SELECT name role FROM items;
SELECT name, role FROM items;
Add comma.
SQL
<entry><name>value</name><age>84</age></entry
<entry><name>value</name><age>84</age></entry>
Add closing >.
XML
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
let z: Int = 'value'
let z: String = 'value'
Fix type.
Swift
y > 44 & z < 10
y > 44 and z < 10
Use 'and' not '&'.
Python
{{'id':'message'}}
{{"id":"message"}}
Use double quotes.
JSON
print 'world'
print 'world';
Add semicolon.
Perl
fn handle() -> i32 {{ 37 }}
fn handle() -> i32 {{ 37 }}
Correct.
Rust
<ul><li>data<li>test</ul>
<ul><li>data</li><li>test</li></ul>
Close li.
HTML
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
.Item {{ color: blue; }}
.Item {{ color: blue; }}
Correct.
CSS