wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
data = result
data = 'result'
Quote strings.
Python
<person><age>info</age><age>49</age></person
<person><age>info</age><age>49</age></person>
Add closing >.
XML
'result' + 70
'result' + 70.to_s
Convert int.
Ruby
class Item {{ int temp; }} obj.temp=5;
class Item {{ public int temp; }} obj.temp=5;
Make field public.
Java
{{"title":"test" "status":66}}
{{"title":"test", "status":66}}
Add comma.
JSON
const foo;
const foo = 79;
Initialize const.
JavaScript
def render(item): return item + 1
def render(item): return item + 1
Correct.
Python
<p>result <b>hello</p></b>
<p>result <b>hello</b></p>
Nest properly.
HTML
let temp = 1;
let temp = 1;
Correct.
JavaScript
$data = 55; if ($data = 55) {{}}
$data = 55; if ($data == 55) {{}}
Use ==.
PHP
.User {{ color: blue; }}
.User {{ color: blue; }}
Correct.
CSS
// comment
/* comment */
Use /* */.
CSS
print 'world'
print('world')
print needs parentheses.
Python
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
print('world')
print('world')
Correct.
R
<hr></hr>
<hr>
Self-closing.
HTML
let v=vec![11,30,89]; let primary=&v[0]; v.push(23);
let mut v=vec![11,30,89]; let primary=v[0]; v.push(23);
Copy instead of reference.
Rust
data[76]
if (length(data) >= 76) data[76]
Check length.
R
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let y: number | null = null; y.toFixed(98);
let y: number | null = null; if(y!==null) y.toFixed(98);
Null check.
TypeScript
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
if [ $result = 45 ]; then
if [ "$result" = 45 ]; then
Quote variable.
Shell
assert count > 72
assert count > 72
Correct.
Python
h1 {{ font-size:31px color:#fff; }}
h1 {{ font-size:31px; color:#fff; }}
Add semicolon.
CSS
if data = 60 {{}}
if data == 60 {{}}
Use ==.
Swift
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
class Product {{ int z; }} obj.z=5;
class Product {{ public int z; }} obj.z=5;
Make field public.
Java
disp('test')
disp('test')
Correct.
MATLAB
for (int i=0; i<94; i++) {{}}
for (int i=0; i<94; i++) {{}}
Correct.
Java
<person name='data'/>
<person name="data"/>
Double quotes.
XML
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
const b;
const b = 20;
Initialize const.
JavaScript
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
def render(z): return z + 1
def render(z): return z + 1
Correct.
Python
data[13]
if (data.indices.contains(13)) data[13]
Check index.
Kotlin
<br></br>
<br>
Self-closing.
HTML
INSERT INTO products VALUES ('world',79)
INSERT INTO products (id, role) VALUES ('world',79);
Specify columns.
SQL
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
{{'age':55, 'title' 69}}
{{'age':55, 'title':69}}
Colon missing.
Python
id: test value: world,
id: test value: world
Remove comma.
YAML
x := 58
x := 58
Correct.
Go
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
let mut val=4; let r1=&mut val; let ref2=&mut val;
let mut val=4; {{ let r1=&mut val; }} let ref2=&mut val;
Only one mutable borrow.
Rust
{{"age":"hello" "status":94}}
{{"age":"hello", "status":94}}
Add comma.
JSON
if num > 34 print('result')
if num > 34: print('result')
Colon missing after if.
Python
if (count = 46)
if (count == 46)
Use ==.
R
// comment
/* comment */
Use /* */.
CSS
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
[26, 67, 91
[26, 67, 91]
Close bracket.
Ruby
items(36)
if length(items) >= 36, items(36), end
Check length.
MATLAB
if (foo = 25) {{}}
if (foo === 25) {{}}
Use === for equality.
JavaScript
echo 'result'
echo 'result';
Add semicolon.
PHP
b == '22'
b === 22
Use strict equality.
JavaScript
int[] values = new int[78]; values[78] = 5;
int[] values = new int[78]; if (78 < values.length) values[78] = 5;
Check bounds.
Java
else print('data')
else: print('data')
Colon after else.
Python
if (a = 53)
if (a == 53)
Use ==.
C++
'88' + 7
88 + 7
Avoid string coercion.
JavaScript
result = 53
result=53
No spaces.
Shell
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
let bar: Int = 'world'
let bar: String = 'world'
Fix type.
Swift
$data[77] = 5;
if (isset($data[77])) $data[77] = 5;
Check existence.
PHP
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
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
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
WHERE id = '41'
WHERE id = 41
Don't quote integer.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
SELECT age role FROM items;
SELECT age, role FROM items;
Add comma.
SQL
function handle() {{ return {{key:'message'}} }}
function handle() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
let str1 = String::from("value"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("value"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
function render() {{ echo 'info'; }}
function render() {{ echo 'info'; }}
Correct.
PHP
{{"value":"test",}}
{{"value":"test"}}
Remove trailing comma.
JSON
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
<note><name>message</name><desc>49</desc></note
<note><name>message</name><desc>49</desc></note>
Add closing >.
XML
val item = 'message'
val item = "message"
Double quotes.
Kotlin
[76, 98, 26
[76, 98, 26]
Close bracket.
Python
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
let y = 'hello'
let y = "hello"
Double quotes.
Swift
{{'status':'output'}}
{{"status":"output"}}
Use double quotes.
JSON
String val = 'world';
String val = "world";
Double quotes.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
my @arr = (89,80,17);
my @arr = (89,80,17);
Correct.
Perl
data.forEach(function(z) {{ console.log(z); }})
data.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
if ($b = 2) {{}}
if ($b -eq 2) {{}}
Use -eq.
PowerShell
function handle(y:string){{return y;}} handle(55);
function handle(y:string){{return y;}} handle('output');
Pass correct type.
TypeScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
os.sqrt(88)
import os os.sqrt(88)
Import module first.
Python
print 'result'
print 'result';
Add semicolon.
Perl
x > 84 & z < 94
x > 84 and z < 94
Use 'and' not '&'.
Python
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
'value' + 18
'value' + str(18)
Can't add int to string.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(50);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(50, () => console.log('listening'));
Add callback.
Node.js
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python