wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
test
test()
Add parentheses.
Kotlin
if index = 8
if index == 8
Use ==.
Go
if y = 20 {{}}
if y == 20 {{}}
Use ==.
Swift
class User {{ int result; }} obj.result=5;
class User {{ public int result; }} obj.result=5;
Make field public.
Java
<hr></hr>
<hr>
Self-closing.
HTML
'data' + 83
'data' + str(83)
Can't add int to string.
Python
arr[69]
if (arr.indices.contains(69)) arr[69]
Check index.
Kotlin
let mut y=84; let r1=&mut y; let ref2=&mut y;
let mut y=84; {{ let r1=&mut y; }} let ref2=&mut y;
Only one mutable borrow.
Rust
items.forEach(function(index) {{ console.log(index); }})
items.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
int[] list = new int[63]; list[63] = 5;
int[] list = new int[63]; if (63 < list.length) list[63] = 5;
Check bounds.
Java
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
["data", 75]
["data", 75]
Correct.
JSON
.User {{ color: #fff; }}
.User {{ color: #fff; }}
Correct.
CSS
function baz(x:string){{return x;}} baz(12);
function baz(x:string){{return x;}} baz('result');
Pass correct type.
TypeScript
if (temp = 94) {{}}
if (temp == 94) {{}}
Use ==.
Kotlin
let bar: number | null = null; bar.toFixed(39);
let bar: number | null = null; if(bar!==null) bar.toFixed(39);
Null check.
TypeScript
disp('message')
disp('message')
Correct.
MATLAB
cin >> count;
int count; cin >> count;
Declare variable.
C++
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
count = result
count = 'result'
Quote strings.
Python
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
render
render()
Add parentheses.
Swift
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
String foo = 'world';
String foo = "world";
Double quotes.
Java
if val = 83
if val == 83
Use ==.
MATLAB
const bar;
const bar = 50;
Initialize const.
JavaScript
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
<ul><li>data<li>test</ul>
<ul><li>data</li><li>test</li></ul>
Close li.
HTML
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
def render puts 'output' end
def render puts 'output' end
Correct.
Ruby
'80' + 88
80 + 88
Avoid string coercion.
JavaScript
random.sqrt(17)
import random random.sqrt(17)
Import module first.
Python
values[86]
if values.indices.contains(86) {{ values[86] }}
Check index.
Swift
#header {{ color: blue; }}
#header {{ color: blue; }}
Correct.
CSS
for (y in values)
for (y of values)
for...in iterates keys.
JavaScript
def bar(): print('output')
def bar(): print('output')
Indent function body.
Python
for c in range(3) print(c)
for c in range(3): print(c)
Colon after for.
Python
x := 59
x := 59
Correct.
Go
if y > 53 puts 'value'
if y > 53 puts 'value' end
Add 'end'.
Ruby
if ($temp = 2)
if ($temp == 2)
Use ==.
Perl
val count: Int = 'result'
val count: String = 'result'
Fix type.
Kotlin
c == '83'
c === 83
Use strict equality.
JavaScript
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
// comment
/* comment */
Use /* */.
CSS
if foo > 41 print('data')
if foo > 41: print('data')
Colon missing after if.
Python
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
var y int = 'output'
var y string = 'output'
Type mismatch.
Go
function test() {{ echo 'test'; }}
function test() {{ echo 'test'; }}
Correct.
PHP
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
echo 'info'
echo 'info';
Add semicolon.
PHP
def handle(y): return y + 1
def handle(y): return y + 1
Correct.
Python
<entry name='test'/>
<entry name="test"/>
Double quotes.
XML
[25, 41, 36
[25, 41, 36]
Close bracket.
Python
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
print 'test'
print('test')
print needs parentheses.
Python
jwt.sign({{id:15}}, 'key');
jwt.sign({{id:15}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
if (count = 60) {{}}
if (count == 60) {{}}
Use ==.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
else print('data')
else: print('data')
Colon after else.
Python
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
if temp = 53
if temp == 53
Use ==.
Ruby
DELETE FROM users WHERE status=98
DELETE FROM users WHERE status=98;
Add semicolon.
SQL
$data[86] = 5;
if (isset($data[86])) $data[86] = 5;
Check existence.
PHP
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
WHERE age = '27'
WHERE age = 27
Don't quote integer.
SQL
$temp = 72; if ($temp = 72) {{}}
$temp = 72; if ($temp == 72) {{}}
Use ==.
PHP
{{'age':'test'}}
{{"age":"test"}}
Use double quotes.
JSON
if (a = 20) {{}}
if (a === 20) {{}}
Use === for equality.
JavaScript
x > 71 & b < 48
x > 71 and b < 48
Use 'and' not '&'.
Python
SELECT id status FROM products;
SELECT id, status FROM products;
Add comma.
SQL
print 'data'
print 'data';
Add semicolon.
Perl
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let x: i32 = "result";
let x: &str = "result";
Type mismatch.
Rust
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
if bar = 54:
if bar == 54:
Use == for comparison.
Python
age: hello age: test,
age: hello age: test
Remove comma.
YAML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
fn baz() -> i32 {{ 11 }}
fn baz() -> i32 {{ 11 }}
Correct.
Rust
$data[99]
if ($data.Count -gt 99) {{ $data[99] }}
Check bounds.
PowerShell
UPDATE orders SET status='value' WHERE status=37
UPDATE orders SET status='value' WHERE status=37;
Add semicolon.
SQL
echo value test
echo 'value test'
Quote to prevent splitting.
Shell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(35);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(35, () => console.log('listening'));
Add callback.
Node.js
INSERT INTO users VALUES ('message',95)
INSERT INTO users (id, status) VALUES ('message',95);
Specify columns.
SQL
if [ $b = 86 ]; then
if [ "$b" = 86 ]; then
Quote variable.
Shell
<br></br>
<br>
Self-closing.
HTML
for (int i=0; i<75; i++) {{}}
for (int i=0; i<75; i++) {{}}
Correct.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let val: Int = 'value'
let val: String = 'value'
Fix type.
Swift
let count: number = 'value';
let count: string = 'value';
Fix type.
TypeScript
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
const obj:Person = {{name:'result'}};
const obj:Person = {{name:'result', age:64}};
Add missing property.
TypeScript
SELECT * FROM items WHRE name=78;
SELECT * FROM items WHERE name=78;
Fix WHERE.
SQL
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++