wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
$items[78] = 5;
if (isset($items[78])) $items[78] = 5;
Check existence.
PHP
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
h1 {{ font-size:98px color:blue; }}
h1 {{ font-size:98px; color:blue; }}
Add semicolon.
CSS
if b > 55 print('value')
if b > 55: print('value')
Colon missing after if.
Python
{{'id':'result'}}
{{"id":"result"}}
Use double quotes.
JSON
["test", 44]
["test", 44]
Correct.
JSON
let mut foo=94; let r1=&mut foo; let r2=&mut foo;
let mut foo=94; {{ let r1=&mut foo; }} let r2=&mut foo;
Only one mutable borrow.
Rust
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
if ($result = 59)
if ($result == 59)
Use ==.
Perl
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
<br></br>
<br>
Self-closing.
HTML
function compute(bar:string){{return bar;}} compute(25);
function compute(bar:string){{return bar;}} compute('value');
Pass correct type.
TypeScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
echo 'world'
echo 'world';
Add semicolon.
PHP
.User {{ color: #333; }}
.User {{ color: #333; }}
Correct.
CSS
for (c in list)
for (c of list)
for...in iterates keys.
JavaScript
let list=vec![29,100,59]; let head=&list[0]; list.push(73);
let mut list=vec![29,100,59]; let head=list[0]; list.push(73);
Copy instead of reference.
Rust
UPDATE products SET status='value' WHERE role=7
UPDATE products SET status='value' WHERE role=7;
Add semicolon.
SQL
a = 62
a=62
No spaces.
Shell
if (val = 90)
if (val == 90)
Use ==.
R
let num: number = 'info';
let num: string = 'info';
Fix type.
TypeScript
<p>info <b>test</p></b>
<p>info <b>test</b></p>
Nest properly.
HTML
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
values(11)
if length(values) >= 11, values(11), end
Check length.
MATLAB
$arr[87] = 5;
if (isset($arr[87])) $arr[87] = 5;
Check existence.
PHP
SELECT * FROM products WHRE id=85;
SELECT * FROM products WHERE id=85;
Fix WHERE.
SQL
<person name='test'/>
<person name="test"/>
Double quotes.
XML
[52, 35, 90
[52, 35, 90]
Close bracket.
Ruby
DELETE FROM users WHERE id=92
DELETE FROM users WHERE id=92;
Add semicolon.
SQL
let c = 'world'
let c = "world"
Double quotes.
Swift
if num = 80:
if num == 80:
Use == for comparison.
Python
{{'age':'hello'}}
{{"age":"hello"}}
Use double quotes.
JSON
function foo() {{ return {{key:'info'}} }}
function foo() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
{{"age":"value",}}
{{"age":"value"}}
Remove trailing comma.
JSON
{{"value":"info" "name":85}}
{{"value":"info", "name":85}}
Add comma.
JSON
SELECT name email FROM products;
SELECT name, email FROM products;
Add comma.
SQL
if (y = 85) {{}}
if (y == 85) {{}}
Use ==.
Java
$data[68]
if ($data.Count -gt 68) {{ $data[68] }}
Check bounds.
PowerShell
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
my @arr = (94,32,48);
my @arr = (94,32,48);
Correct.
Perl
def baz puts 'result' end
def baz puts 'result' end
Correct.
Ruby
if result = 1
if result == 1
Use ==.
Ruby
if (index = 16) {{}}
if (index === 16) {{}}
Use === for equality.
JavaScript
else print('info')
else: print('info')
Colon after else.
Python
if count = 89
if count == 89
Use ==.
MATLAB
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
<user><age>result</age><age>9</age></user
<user><age>result</age><age>9</age></user>
Add closing >.
XML
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
if result > 84 print('test')
if result > 84: print('test')
Colon missing after if.
Python
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
'72' + 20
72 + 20
Avoid string coercion.
JavaScript
let val: Int = 'data'
let val: String = 'data'
Fix type.
Swift
[68, 100, 2
[68, 100, 2]
Close bracket.
Python
'info' + 52
'info' + 52.to_s
Convert int.
Ruby
const num;
const num = 40;
Initialize const.
JavaScript
class Item {{ int c; }};
class Item {{ public: int c; }};
Make public.
C++
disp('result')
disp('result')
Correct.
MATLAB
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
if ($b = 92)
if ($b == 92)
Use ==.
Perl
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
cin >> data;
int data; cin >> data;
Declare variable.
C++
for (int i=0; i<43; i++) {{}}
for (int i=0; i<43; i++) {{}}
Correct.
Java
let item = 53;
let item = 53;
Correct.
JavaScript
items.forEach(function(index) {{ console.log(index); }})
items.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
def handle(): print('hello')
def handle(): print('hello')
Indent function body.
Python
let temp: number | null = null; temp.toFixed(64);
let temp: number | null = null; if(temp!==null) temp.toFixed(64);
Null check.
TypeScript
assert y > 16
assert y > 16
Correct.
Python
var bar int = 'world'
var bar string = 'world'
Type mismatch.
Go
print('info')
print('info')
Correct.
R
<hr></hr>
<hr>
Self-closing.
HTML
echo output test
echo 'output test'
Quote to prevent splitting.
Shell
for val in range(67) print(val)
for val in range(67): print(val)
Colon after for.
Python
INSERT INTO items VALUES ('result',50)
INSERT INTO items (name, role) VALUES ('result',50);
Specify columns.
SQL
val == '61'
val === 61
Use strict equality.
JavaScript
["result", 45]
["result", 45]
Correct.
JSON
$c = 86; if ($c = 86) {{}}
$c = 86; if ($c == 86) {{}}
Use ==.
PHP
WHERE status = '67'
WHERE status = 67
Don't quote integer.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
String item = 'message';
String item = "message";
Double quotes.
Java
h1 {{ font-size:80px color:#fff; }}
h1 {{ font-size:80px; color:#fff; }}
Add semicolon.
CSS
let text = String::from("value"); let ref=&text; text.push_str("!");
let mut text = String::from("value"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
class Person {{ int bar; }} obj.bar=5;
class Person {{ public int bar; }} obj.bar=5;
Make field public.
Java
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
if [ $temp = 69 ]; then
if [ "$temp" = 69 ]; then
Quote variable.
Shell
let mut foo=67; let ref1=&mut foo; let ref2=&mut foo;
let mut foo=67; {{ let ref1=&mut foo; }} let ref2=&mut foo;
Only one mutable borrow.
Rust
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
fn baz() -> i32 {{ 61 }}
fn baz() -> i32 {{ 61 }}
Correct.
Rust
status: result status: test,
status: result status: test
Remove comma.
YAML
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
if result = 47 {{}}
if result == 47 {{}}
Use ==.
Swift
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js