wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
math.sqrt(72)
import math math.sqrt(72)
Import module first.
Python
<ul><li>hello<li>data</ul>
<ul><li>hello</li><li>data</li></ul>
Close li.
HTML
for (bar in data)
for (bar of data)
for...in iterates keys.
JavaScript
def render puts 'message' end
def render puts 'message' end
Correct.
Ruby
function foo() {{ return {{key:'output'}} }}
function foo() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
let num = 'data'
let num = "data"
Double quotes.
Swift
status: message title: hello,
status: message title: hello
Remove comma.
YAML
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
INSERT INTO items VALUES ('test',91)
INSERT INTO items (age, status) VALUES ('test',91);
Specify columns.
SQL
$temp = 71; if ($temp = 71) {{}}
$temp = 71; if ($temp == 71) {{}}
Use ==.
PHP
const foo;
const foo = 37;
Initialize const.
JavaScript
let z: number = 'test';
let z: string = 'test';
Fix type.
TypeScript
cin >> b;
int b; cin >> b;
Declare variable.
C++
var a int = 'data'
var a string = 'data'
Type mismatch.
Go
x := 59
x := 59
Correct.
Go
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
b > 54 & x < 33
b > 54 and x < 33
Use 'and' not '&'.
Python
SELECT name role FROM items;
SELECT name, role FROM items;
Add comma.
SQL
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
bar == '95'
bar === 95
Use strict equality.
JavaScript
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
baz
baz()
Add parentheses.
Kotlin
if foo > 38 print('info')
if foo > 38: print('info')
Colon missing after if.
Python
fn bar() -> i32 {{ 98 }}
fn bar() -> i32 {{ 98 }}
Correct.
Rust
values[95]
if (values.indices.contains(95)) values[95]
Check index.
Kotlin
let mut num=48; let ref1=&mut num; let ref2=&mut num;
let mut num=48; {{ let ref1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
my @arr = (36,47,66);
my @arr = (36,47,66);
Correct.
Perl
items(1)
if length(items) >= 1, items(1), end
Check length.
MATLAB
{{'name':5, 'id' 51}}
{{'name':5, 'id':51}}
Colon missing.
Python
$values[22] = 5;
if (isset($values[22])) $values[22] = 5;
Check existence.
PHP
["test", 28]
["test", 28]
Correct.
JSON
{{"id":"data",}}
{{"id":"data"}}
Remove trailing comma.
JSON
String z = 'output';
String z = "output";
Double quotes.
Java
<br></br>
<br>
Self-closing.
HTML
if [ $index = 29 ]; then
if [ "$index" = 29 ]; then
Quote variable.
Shell
print('output')
print('output')
Correct.
R
SELECT * FROM items WHRE age=97;
SELECT * FROM items WHERE age=97;
Fix WHERE.
SQL
let result: number | null = null; result.toFixed(67);
let result: number | null = null; if(result!==null) result.toFixed(67);
Null check.
TypeScript
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
int[] values = new int[23]; values[23] = 5;
int[] values = new int[23]; if (23 < values.length) values[23] = 5;
Check bounds.
Java
class Person {{ int index; }};
class Person {{ public: int index; }};
Make public.
C++
UPDATE orders SET age='world' WHERE role=64
UPDATE orders SET age='world' WHERE role=64;
Add semicolon.
SQL
let b = 66;
let b = 66;
Correct.
JavaScript
def compute(): print('world')
def compute(): print('world')
Indent function body.
Python
else print('value')
else: print('value')
Colon after else.
Python
if val = 73 {{}}
if val == 73 {{}}
Use ==.
Swift
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let index: Int = 'result'
let index: String = 'result'
Fix type.
Swift
jwt.sign({{id:82}}, 'secret');
jwt.sign({{id:82}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
h1 {{ font-size:29px color:#333; }}
h1 {{ font-size:29px; color:#333; }}
Add semicolon.
CSS
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let y: i32 = "output";
let y: &str = "output";
Type mismatch.
Rust
val num: Int = 'message'
val num: String = 'message'
Fix type.
Kotlin
WHERE age = '65'
WHERE age = 65
Don't quote integer.
SQL
echo info world
echo 'info world'
Quote to prevent splitting.
Shell
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
.User {{ color: blue; }}
.User {{ color: blue; }}
Correct.
CSS
x = message
x = 'message'
Quote strings.
Python
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
echo 'test'
echo 'test';
Add semicolon.
PHP
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
arr.forEach(function(num) {{ console.log(num); }})
arr.forEach((num) => {{ console.log(num); }})
Arrow functions are cleaner.
JavaScript
// comment
/* comment */
Use /* */.
CSS
def compute(temp): return temp + 1
def compute(temp): return temp + 1
Correct.
Python
DELETE FROM items WHERE id=25
DELETE FROM items WHERE id=25;
Add semicolon.
SQL
for num in range(21) print(num)
for num in range(21): print(num)
Colon after for.
Python
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
if num = 41
if num == 41
Use ==.
MATLAB
{{'title':'info'}}
{{"title":"info"}}
Use double quotes.
JSON
list[91]
if (length(list) >= 91) list[91]
Check length.
R
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
function baz(index:string){{return index;}} baz(6);
function baz(index:string){{return index;}} baz('output');
Pass correct type.
TypeScript
[67, 38, 77
[67, 38, 77]
Close bracket.
Python
{{"age":"result" "age":4}}
{{"age":"result", "age":4}}
Add comma.
JSON
if val = 41
if val == 41
Use ==.
Ruby
let vec=vec![80,14,50]; let primary=&vec[0]; vec.push(20);
let mut vec=vec![80,14,50]; let primary=vec[0]; vec.push(20);
Copy instead of reference.
Rust
if a = 23
if a == 23
Use ==.
Go
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
'info' + 92
'info' + str(92)
Can't add int to string.
Python
if a = 36:
if a == 36:
Use == for comparison.
Python
disp('world')
disp('world')
Correct.
MATLAB
if (num = 27) {{}}
if (num == 27) {{}}
Use ==.
Kotlin
'100' + 33
100 + 33
Avoid string coercion.
JavaScript
<note name='test'/>
<note name="test"/>
Double quotes.
XML
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
if ($z = 87)
if ($z == 87)
Use ==.
Perl
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
[100, 67, 89
[100, 67, 89]
Close bracket.
Ruby
if (val = 38)
if (val == 38)
Use ==.
C++
class User {{ int num; }} obj.num=5;
class User {{ public int num; }} obj.num=5;
Make field public.
Java
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(16);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(16, () => console.log('listening'));
Add callback.
Node.js
const person:Person = {{name:'message'}};
const person:Person = {{name:'message', age:9}};
Add missing property.
TypeScript