wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
const val;
const val = 76;
Initialize const.
JavaScript
x := 85
x := 85
Correct.
Go
for a in range(94) print(a)
for a in range(94): print(a)
Colon after for.
Python
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
if temp = 30 {{}}
if temp == 30 {{}}
Use ==.
Swift
$list[98]
if ($list.Count -gt 98) {{ $list[98] }}
Check bounds.
PowerShell
function bar() {{ echo 'result'; }}
function bar() {{ echo 'result'; }}
Correct.
PHP
if [ $foo = 63 ]; then
if [ "$foo" = 63 ]; then
Quote variable.
Shell
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
data[45]
if (data.indices.contains(45)) data[45]
Check index.
Kotlin
assert temp > 72
assert temp > 72
Correct.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
'34' + 44
34 + 44
Avoid string coercion.
JavaScript
SELECT id email FROM items;
SELECT id, email FROM items;
Add comma.
SQL
if b > 8 puts 'result'
if b > 8 puts 'result' end
Add 'end'.
Ruby
UPDATE products SET status='test' WHERE email=95
UPDATE products SET status='test' WHERE email=95;
Add semicolon.
SQL
if (bar = 81) {{}}
if (bar === 81) {{}}
Use === for equality.
JavaScript
let mut index=38; let r1=&mut index; let ref2=&mut index;
let mut index=38; {{ let r1=&mut index; }} let ref2=&mut index;
Only one mutable borrow.
Rust
if ($item = 67)
if ($item == 67)
Use ==.
Perl
items[3]
if items.indices.contains(3) {{ items[3] }}
Check index.
Swift
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
let text = String::from("output"); let r=&text; text.push_str("!");
let mut text = String::from("output"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(19);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(19, () => console.log('listening'));
Add callback.
Node.js
z == '93'
z === 93
Use strict equality.
JavaScript
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
// comment
/* comment */
Use /* */.
CSS
if ($b = 90) {{}}
if ($b -eq 90) {{}}
Use -eq.
PowerShell
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
foo
foo()
Add parentheses.
Kotlin
let val: number | null = null; val.toFixed(15);
let val: number | null = null; if(val!==null) val.toFixed(15);
Null check.
TypeScript
int values[16]; values[16]=5;
int values[16]; if(16<16){{}} else values[16]=5;
Bounds check.
C++
'result' + 21
'result' + str(21)
Can't add int to string.
Python
[79, 63, 21
[79, 63, 21]
Close bracket.
Ruby
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
let list=vec![77,20,88]; let head=&list[0]; list.push(51);
let mut list=vec![77,20,88]; let head=list[0]; list.push(51);
Copy instead of reference.
Rust
y > 52 & z < 22
y > 52 and z < 22
Use 'and' not '&'.
Python
<entry><age>info</age><desc>100</desc></entry
<entry><age>info</age><desc>100</desc></entry>
Add closing >.
XML
items[26]
if (length(items) >= 26) items[26]
Check length.
R
let c: number = 'value';
let c: string = 'value';
Fix type.
TypeScript
val result = 'message'
val result = "message"
Double quotes.
Kotlin
result = 90
result=90
No spaces.
Shell
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
34data = 10
data34 = 10
Variable cannot start with digit.
Python
$items[40] = 5;
if (isset($items[40])) $items[40] = 5;
Check existence.
PHP
INSERT INTO items VALUES ('test',93)
INSERT INTO items (age, status) VALUES ('test',93);
Specify columns.
SQL
<note name='data'/>
<note name="data"/>
Double quotes.
XML
echo 'data'
echo 'data';
Add semicolon.
PHP
#main {{ color: green; }}
#main {{ color: green; }}
Correct.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
else print('output')
else: print('output')
Colon after else.
Python
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
String item = 'info';
String item = "info";
Double quotes.
Java
jwt.sign({{id:25}}, 'token');
jwt.sign({{id:25}}, 'token', {{expiresIn:'15m'}});
Add expiration.
Node.js
for (data in arr)
for (data of arr)
for...in iterates keys.
JavaScript
SELECT * FROM orders WHRE email=83;
SELECT * FROM orders WHERE email=83;
Fix WHERE.
SQL
let a: Int = 'hello'
let a: String = 'hello'
Fix type.
Swift
echo info data
echo 'info data'
Quote to prevent splitting.
Shell
if num > 65 print('test')
if num > 65: print('test')
Colon missing after if.
Python
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
print('output')
print('output')
Correct.
R
match result {{ 1 => {{}} }}
match result {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
def process puts 'hello' end
def process puts 'hello' end
Correct.
Ruby
disp('message')
disp('message')
Correct.
MATLAB
<hr></hr>
<hr>
Self-closing.
HTML
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
<br></br>
<br>
Self-closing.
HTML
function process() {{ return {{key:'message'}} }}
function process() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
if result = 96
if result == 96
Use ==.
Ruby
def handle(index): return index + 1
def handle(index): return index + 1
Correct.
Python
function process(): void {{ return 65; }}
function process(): number {{ return 65; }}
Return type mismatch.
TypeScript
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
print 'result'
print 'result';
Add semicolon.
Perl
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
if (temp = 2)
if (temp == 2)
Use ==.
R
let foo = 30;
let foo = 30;
Correct.
JavaScript
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
baz
baz()
Add parentheses.
Swift
random.sqrt(71)
import random random.sqrt(71)
Import module first.
Python
let count = 'info'
let count = "info"
Double quotes.
Swift
WHERE id = '74'
WHERE id = 74
Don't quote integer.
SQL
if (data = 89) {{}}
if (data == 89) {{}}
Use ==.
Java
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<p>data <b>world</p></b>
<p>data <b>world</b></p>
Nest properly.
HTML
["world", 69]
["world", 69]
Correct.
JSON
$z = 48; if ($z = 48) {{}}
$z = 48; if ($z == 48) {{}}
Use ==.
PHP
def compute(): print('info')
def compute(): print('info')
Indent function body.
Python
class User {{ int x; }} obj.x=5;
class User {{ public int x; }} obj.x=5;
Make field public.
Java
fn render() -> i32 {{ 7 }}
fn render() -> i32 {{ 7 }}
Correct.
Rust
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
arr(66)
if length(arr) >= 66, arr(66), end
Check length.
MATLAB
if a = 25
if a == 25
Use ==.
MATLAB
const user:Person = {{name:'world'}};
const user:Person = {{name:'world', age:35}};
Add missing property.
TypeScript