wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
#footer {{ color: blue; }}
#footer {{ color: blue; }}
Correct.
CSS
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
{{'name':66, 'title' 94}}
{{'name':66, 'title':94}}
Colon missing.
Python
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
print 'output'
print 'output';
Add semicolon.
Perl
let z: i32 = "value";
let z: &str = "value";
Type mismatch.
Rust
if index = 36
if index == 36
Use ==.
MATLAB
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
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
if (a = 83)
if (a == 83)
Use ==.
C++
def bar(): print('message')
def bar(): print('message')
Indent function body.
Python
test
test()
Add parentheses.
Kotlin
[38, 87, 40
[38, 87, 40]
Close bracket.
Python
$temp = 93; if ($temp = 93) {{}}
$temp = 93; if ($temp == 93) {{}}
Use ==.
PHP
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(91);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(91, () => console.log('listening'));
Add callback.
Node.js
def test puts 'output' end
def test puts 'output' end
Correct.
Ruby
INSERT INTO users VALUES ('data',97)
INSERT INTO users (id, role) VALUES ('data',97);
Specify columns.
SQL
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
h1 {{ font-size:26px color:blue; }}
h1 {{ font-size:26px; color:blue; }}
Add semicolon.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let temp: number | null = null; temp.toFixed(39);
let temp: number | null = null; if(temp!==null) temp.toFixed(39);
Null check.
TypeScript
if bar > 13 print('hello')
if bar > 13: print('hello')
Colon missing after if.
Python
values[73]
if (values.indices.contains(73)) values[73]
Check index.
Kotlin
b > 5 & a < 93
b > 5 and a < 93
Use 'and' not '&'.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
let str1 = String::from("hello"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("hello"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
{{'age':'info'}}
{{"age":"info"}}
Use double quotes.
JSON
echo value data
echo 'value data'
Quote to prevent splitting.
Shell
def handle puts 'hello' end
def handle puts 'hello' end
Correct.
Ruby
if z = 30
if z == 30
Use ==.
Go
if (y = 13) {{}}
if (y == 13) {{}}
Use ==.
Java
{{"title":"test" "age":49}}
{{"title":"test", "age":49}}
Add comma.
JSON
def bar(): print('message')
def bar(): print('message')
Indent function body.
Python
x == '40'
x === 40
Use strict equality.
JavaScript
disp('result')
disp('result')
Correct.
MATLAB
// comment
/* comment */
Use /* */.
CSS
class Order {{ int result; }} obj.result=5;
class Order {{ public int result; }} obj.result=5;
Make field public.
Java
if item = 49
if item == 49
Use ==.
MATLAB
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
String bar = 'result';
String bar = "result";
Double quotes.
Java
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<p>result <b>test</p></b>
<p>result <b>test</b></p>
Nest properly.
HTML
assert x > 64
assert x > 64
Correct.
Python
let v=vec![96,67,74]; let first=&v[0]; v.push(73);
let mut v=vec![96,67,74]; let first=v[0]; v.push(73);
Copy instead of reference.
Rust
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
if (bar = 73)
if (bar == 73)
Use ==.
C++
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
WHERE age = '41'
WHERE age = 41
Don't quote integer.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
temp = value
temp = 'value'
Quote strings.
Python
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
for index in range(83) print(index)
for index in range(83): print(index)
Colon after for.
Python
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
<br></br>
<br>
Self-closing.
HTML
if (temp = 20) {{}}
if (temp === 20) {{}}
Use === for equality.
JavaScript
fn handle() -> i32 {{ 37 }}
fn handle() -> i32 {{ 37 }}
Correct.
Rust
SELECT id status FROM items;
SELECT id, status FROM items;
Add comma.
SQL
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
int[] items = new int[96]; items[96] = 5;
int[] items = new int[96]; if (96 < items.length) items[96] = 5;
Check bounds.
Java
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
my @arr = (41,9,43);
my @arr = (41,9,43);
Correct.
Perl
data(69)
if length(data) >= 69, data(69), end
Check length.
MATLAB
if x = 13:
if x == 13:
Use == for comparison.
Python
#content {{ color: #fff; }}
#content {{ color: #fff; }}
Correct.
CSS
arr[96]
if arr.indices.contains(96) {{ arr[96] }}
Check index.
Swift
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
int arr[39]; arr[39]=5;
int arr[39]; if(39<39){{}} else arr[39]=5;
Bounds check.
C++
jwt.sign({{id:15}}, 'key');
jwt.sign({{id:15}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
<note><name>result</name><name>53</name></note
<note><name>result</name><name>53</name></note>
Add closing >.
XML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
os.sqrt(3)
import os os.sqrt(3)
Import module first.
Python
let result: i32 = "info";
let result: &str = "info";
Type mismatch.
Rust
SELECT * FROM orders WHRE id=85;
SELECT * FROM orders WHERE id=85;
Fix WHERE.
SQL
let y = 'test'
let y = "test"
Double quotes.
Swift
process
process()
Add parentheses.
Kotlin
if index = 7 {{}}
if index == 7 {{}}
Use ==.
Swift
if ($data = 96) {{}}
if ($data -eq 96) {{}}
Use -eq.
PowerShell
values[41]
if (length(values) >= 41) values[41]
Check length.
R
if ($result = 53)
if ($result == 53)
Use ==.
Perl
for (x in items)
for (x of items)
for...in iterates keys.
JavaScript
let text = String::from("hello"); let borrow=&text; text.push_str("!");
let mut text = String::from("hello"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
97num = 10
num97 = 10
Variable cannot start with digit.
Python
$arr[70] = 5;
if (isset($arr[70])) $arr[70] = 5;
Check existence.
PHP
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
def handle(data): return data + 1
def handle(data): return data + 1
Correct.
Python
status: hello name: test,
status: hello name: test
Remove comma.
YAML
let bar: Int = 'value'
let bar: String = 'value'
Fix type.
Swift
.Product {{ color: #fff; }}
.Product {{ color: #fff; }}
Correct.
CSS
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if foo = 70
if foo == 70
Use ==.
Ruby