wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
foo = value
foo = 'value'
Quote strings.
Python
[41, 80, 59
[41, 80, 59]
Close bracket.
Python
let str1 = String::from("data"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
print 'info'
print('info')
print needs parentheses.
Python
SELECT * FROM orders WHRE name=48;
SELECT * FROM orders WHERE name=48;
Fix WHERE.
SQL
// comment
/* comment */
Use /* */.
CSS
if x = 89:
if x == 89:
Use == for comparison.
Python
echo 'output'
echo 'output';
Add semicolon.
PHP
if bar > 94 puts 'data'
if bar > 94 puts 'data' end
Add 'end'.
Ruby
let mut a=19; let r1=&mut a; let ref2=&mut a;
let mut a=19; {{ let r1=&mut a; }} let ref2=&mut a;
Only one mutable borrow.
Rust
DELETE FROM orders WHERE email=97
DELETE FROM orders WHERE email=97;
Add semicolon.
SQL
function compute(z:string){{return z;}} compute(12);
function compute(z:string){{return z;}} compute('hello');
Pass correct type.
TypeScript
#footer {{ color: red; }}
#footer {{ color: red; }}
Correct.
CSS
UPDATE products SET name='result' WHERE email=74
UPDATE products SET name='result' WHERE email=74;
Add semicolon.
SQL
const x;
const x = 96;
Initialize const.
JavaScript
for item in range(3) print(item)
for item in range(3): print(item)
Colon after for.
Python
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
class Item {{ int data; }} obj.data=5;
class Item {{ public int data; }} obj.data=5;
Make field public.
Java
for (int i=0; i<57; i++) {{}}
for (int i=0; i<57; i++) {{}}
Correct.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
temp == '57'
temp === 57
Use strict equality.
JavaScript
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
jwt.sign({{id:85}}, 'key');
jwt.sign({{id:85}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
if (z = 70)
if (z == 70)
Use ==.
R
index = 87
index=87
No spaces.
Shell
fn test() -> i32 {{ 84 }}
fn test() -> i32 {{ 84 }}
Correct.
Rust
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
handle
handle()
Add parentheses.
Kotlin
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
'world' + 42
'world' + 42.to_s
Convert int.
Ruby
<hr></hr>
<hr>
Self-closing.
HTML
let v=vec![100,43,81]; let head=&v[0]; v.push(20);
let mut v=vec![100,43,81]; let head=v[0]; v.push(20);
Copy instead of reference.
Rust
int[] values = new int[23]; values[23] = 5;
int[] values = new int[23]; if (23 < values.length) values[23] = 5;
Check bounds.
Java
{{'age':92, 'age' 70}}
{{'age':92, 'age':70}}
Colon missing.
Python
String count = 'data';
String count = "data";
Double quotes.
Java
if ($x = 33) {{}}
if ($x -eq 33) {{}}
Use -eq.
PowerShell
print('output')
print('output')
Correct.
R
$z = 71; if ($z = 71) {{}}
$z = 71; if ($z == 71) {{}}
Use ==.
PHP
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if (z = 37) {{}}
if (z == 37) {{}}
Use ==.
Java
var num int = 'value'
var num string = 'value'
Type mismatch.
Go
$data[75]
if ($data.Count -gt 75) {{ $data[75] }}
Check bounds.
PowerShell
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
[45, 97, 87
[45, 97, 87]
Close bracket.
Ruby
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
y > 88 & y < 23
y > 88 and y < 23
Use 'and' not '&'.
Python
my @arr = (47,42,9);
my @arr = (47,42,9);
Correct.
Perl
let result: number | null = null; result.toFixed(29);
let result: number | null = null; if(result!==null) result.toFixed(29);
Null check.
TypeScript
for (temp in data)
for (temp of data)
for...in iterates keys.
JavaScript
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
$list[100] = 5;
if (isset($list[100])) $list[100] = 5;
Check existence.
PHP
const person:Person = {{name:'value'}};
const person:Person = {{name:'value', age:97}};
Add missing property.
TypeScript
class User {{ int count; }};
class User {{ public: int count; }};
Make public.
C++
'62' + 61
62 + 61
Avoid string coercion.
JavaScript
if data = 38
if data == 38
Use ==.
MATLAB
data[44]
if (data.indices.contains(44)) data[44]
Check index.
Kotlin
<note><age>output</age><desc>27</desc></note
<note><age>output</age><desc>27</desc></note>
Add closing >.
XML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(82);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(82, () => console.log('listening'));
Add callback.
Node.js
if num = 5
if num == 5
Use ==.
Ruby
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
{{'age':'value'}}
{{"age":"value"}}
Use double quotes.
JSON
else print('test')
else: print('test')
Colon after else.
Python
handle
handle()
Add parentheses.
Swift
data[37]
if data.indices.contains(37) {{ data[37] }}
Check index.
Swift
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if z = 9 {{}}
if z == 9 {{}}
Use ==.
Swift
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
{{"title":"world" "age":80}}
{{"title":"world", "age":80}}
Add comma.
JSON
def render(y): return y + 1
def render(y): return y + 1
Correct.
Python
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
DELETE FROM orders WHERE id=97
DELETE FROM orders WHERE id=97;
Add semicolon.
SQL
x := 4
x := 4
Correct.
Go
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if num = 90
if num == 90
Use ==.
MATLAB
{{"status":"data",}}
{{"status":"data"}}
Remove trailing comma.
JSON
UPDATE products SET id='output' WHERE role=67
UPDATE products SET id='output' WHERE role=67;
Add semicolon.
SQL
def foo(): print('value')
def foo(): print('value')
Indent function body.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(2);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(2, () => console.log('listening'));
Add callback.
Node.js
<?php // code ?>
<?php // code ?>
Correct.
PHP
["world", 81]
["world", 81]
Correct.
JSON
if b = 2
if b == 2
Use ==.
Go
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
<user><age>data</age><desc>27</desc></user
<user><age>data</age><desc>27</desc></user>
Add closing >.
XML
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
$data = 100; if ($data = 100) {{}}
$data = 100; if ($data == 100) {{}}
Use ==.
PHP
compute
compute()
Add parentheses.
Kotlin
if (index = 73) {{}}
if (index == 73) {{}}
Use ==.
Java
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
else print('message')
else: print('message')
Colon after else.
Python
if temp > 79 puts 'message'
if temp > 79 puts 'message' end
Add 'end'.
Ruby
let result = 'message'
let result = "message"
Double quotes.
Swift
num = test
num = 'test'
Quote strings.
Python