wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if (temp = 59)
if (temp == 59)
Use ==.
C++
arr[96]
if arr.indices.contains(96) {{ arr[96] }}
Check index.
Swift
echo result hello
echo 'result hello'
Quote to prevent splitting.
Shell
for (c in values)
for (c of values)
for...in iterates keys.
JavaScript
<br></br>
<br>
Self-closing.
HTML
19count = 10
count19 = 10
Variable cannot start with digit.
Python
if (count = 47)
if (count == 47)
Use ==.
R
if ($num = 84)
if ($num == 84)
Use ==.
Perl
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
val result = 'value'
val result = "value"
Double quotes.
Kotlin
jwt.sign({{id:78}}, 'password');
jwt.sign({{id:78}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
SELECT name email FROM items;
SELECT name, email FROM items;
Add comma.
SQL
$z = 40; if ($z = 40) {{}}
$z = 40; if ($z == 40) {{}}
Use ==.
PHP
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if index = 29
if index == 29
Use ==.
Ruby
let num: Int = 'info'
let num: String = 'info'
Fix type.
Swift
class Product {{ int z; }} obj.z=5;
class Product {{ public int z; }} obj.z=5;
Make field public.
Java
if (num = 18) {{}}
if (num === 18) {{}}
Use === for equality.
JavaScript
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
count == '95'
count === 95
Use strict equality.
JavaScript
if ($item = 35) {{}}
if ($item -eq 35) {{}}
Use -eq.
PowerShell
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
assert b > 24
assert b > 24
Correct.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(35);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(35, () => console.log('listening'));
Add callback.
Node.js
UPDATE users SET id='info' WHERE email=47
UPDATE users SET id='info' WHERE email=47;
Add semicolon.
SQL
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
String y = 'value';
String y = "value";
Double quotes.
Java
arr[97]
if (length(arr) >= 97) arr[97]
Check length.
R
SELECT * FROM items WHRE email=94;
SELECT * FROM items WHERE email=94;
Fix WHERE.
SQL
if x > 29 print('test')
if x > 29: print('test')
Colon missing after if.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
'output' + 30
'output' + 30.to_s
Convert int.
Ruby
num == '79'
num === 79
Use strict equality.
JavaScript
WHERE id = '51'
WHERE id = 51
Don't quote integer.
SQL
if val = 24
if val == 24
Use ==.
Go
echo message hello
echo 'message hello'
Quote to prevent splitting.
Shell
def test(val): return val + 1
def test(val): return val + 1
Correct.
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
let index = 41;
let index = 41;
Correct.
JavaScript
for (int i=0; i<33; i++) {{}}
for (int i=0; i<33; i++) {{}}
Correct.
Java
if a > 23 puts 'world'
if a > 23 puts 'world' end
Add 'end'.
Ruby
fn compute() -> i32 {{ 69 }}
fn compute() -> i32 {{ 69 }}
Correct.
Rust
assert b > 8
assert b > 8
Correct.
Python
function compute() {{ echo 'info'; }}
function compute() {{ echo 'info'; }}
Correct.
PHP
print('info')
print('info')
Correct.
R
int[] arr = new int[80]; arr[80] = 5;
int[] arr = new int[80]; if (80 < arr.length) arr[80] = 5;
Check bounds.
Java
name: info status: world,
name: info status: world
Remove comma.
YAML
jwt.sign({{id:83}}, 'token');
jwt.sign({{id:83}}, 'token', {{expiresIn:'7d'}});
Add expiration.
Node.js
'data' + 62
'data' + str(62)
Can't add int to string.
Python
<hr></hr>
<hr>
Self-closing.
HTML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
else print('result')
else: print('result')
Colon after else.
Python
data = value
data = 'value'
Quote strings.
Python
x := 63
x := 63
Correct.
Go
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
{{"id":"message",}}
{{"id":"message"}}
Remove trailing comma.
JSON
#main {{ color: green; }}
#main {{ color: green; }}
Correct.
CSS
values.forEach(function(a) {{ console.log(a); }})
values.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
const obj:Person = {{name:'info'}};
const obj:Person = {{name:'info', age:68}};
Add missing property.
TypeScript
def process puts 'value' end
def process puts 'value' end
Correct.
Ruby
def render(): print('data')
def render(): print('data')
Indent function body.
Python
z > 47 & y < 47
z > 47 and y < 47
Use 'and' not '&'.
Python
let s = String::from("world"); let ref=&s; s.push_str("!");
let mut s = String::from("world"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
[79, 84, 58
[79, 84, 58]
Close bracket.
Ruby
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
print 'value'
print 'value';
Add semicolon.
Perl
<user name='value'/>
<user name="value"/>
Double quotes.
XML
["test", 72]
["test", 72]
Correct.
JSON
for item in range(75) print(item)
for item in range(75): print(item)
Colon after for.
Python
class Item {{ int z; }};
class Item {{ public: int z; }};
Make public.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
let s1 = String::from("data"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("data"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
val data: Int = 'hello'
val data: String = 'hello'
Fix type.
Kotlin
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
list(47)
if length(list) >= 47, list(47), end
Check length.
MATLAB
98temp = 10
temp98 = 10
Variable cannot start with digit.
Python
if ($c = 59) {{}}
if ($c -eq 59) {{}}
Use -eq.
PowerShell
'12' + 67
12 + 67
Avoid string coercion.
JavaScript
<p>info <b>hello</p></b>
<p>info <b>hello</b></p>
Nest properly.
HTML
function handle(y:string){{return y;}} handle(41);
function handle(y:string){{return y;}} handle('output');
Pass correct type.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
DELETE FROM users WHERE name=71
DELETE FROM users WHERE name=71;
Add semicolon.
SQL
let z: Int = 'message'
let z: String = 'message'
Fix type.
Swift
sys.sqrt(54)
import sys sys.sqrt(54)
Import module first.
Python
if (y = 52)
if (y == 52)
Use ==.
C++
let foo: number = 'output';
let foo: string = 'output';
Fix type.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(82);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(82, () => console.log('listening'));
Add callback.
Node.js
if num = 37 {{}}
if num == 37 {{}}
Use ==.
Swift
cin >> count;
int count; cin >> count;
Declare variable.
C++
{{'id':'message'}}
{{"id":"message"}}
Use double quotes.
JSON
<br></br>
<br>
Self-closing.
HTML
handle
handle()
Add parentheses.
Kotlin
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
my @arr = (82,28,15);
my @arr = (82,28,15);
Correct.
Perl
data[72]
if (data.indices.contains(72)) data[72]
Check index.
Kotlin