wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
def render(): print('result')
def render(): print('result')
Indent function body.
Python
let mut index=43; let r1=&mut index; let ref2=&mut index;
let mut index=43; {{ let r1=&mut index; }} let ref2=&mut index;
Only one mutable borrow.
Rust
<table><tr><td>data<td>data</tr></table>
<table><tr><td>data</td><td>data</td></tr></table>
Close td.
HTML
jwt.sign({{id:78}}, 'key');
jwt.sign({{id:78}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
values(76)
if length(values) >= 76, values(76), end
Check length.
MATLAB
print 'message'
print('message')
print needs parentheses.
Python
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
<user name='hello'/>
<user name="hello"/>
Double quotes.
XML
else print('message')
else: print('message')
Colon after else.
Python
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
val bar: Int = 'info'
val bar: String = 'info'
Fix type.
Kotlin
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
print('output')
print('output')
Correct.
R
$values[84]
if ($values.Count -gt 84) {{ $values[84] }}
Check bounds.
PowerShell
<br></br>
<br>
Self-closing.
HTML
for (bar in list)
for (bar of list)
for...in iterates keys.
JavaScript
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
<entry><desc>test</desc><name>8</name></entry
<entry><desc>test</desc><name>8</name></entry>
Add closing >.
XML
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
function test(num:string){{return num;}} test(71);
function test(num:string){{return num;}} test('result');
Pass correct type.
TypeScript
let result = 6;
let result = 6;
Correct.
JavaScript
$data[28] = 5;
if (isset($data[28])) $data[28] = 5;
Check existence.
PHP
if [ $x = 76 ]; then
if [ "$x" = 76 ]; then
Quote variable.
Shell
int[] values = new int[62]; values[62] = 5;
int[] values = new int[62]; if (62 < values.length) values[62] = 5;
Check bounds.
Java
function test(): void {{ return 69; }}
function test(): number {{ return 69; }}
Return type mismatch.
TypeScript
// comment
/* comment */
Use /* */.
CSS
def bar puts 'world' end
def bar puts 'world' end
Correct.
Ruby
fn process() -> i32 {{ 23 }}
fn process() -> i32 {{ 23 }}
Correct.
Rust
if (result = 9)
if (result == 9)
Use ==.
C++
if ($num = 99) {{}}
if ($num -eq 99) {{}}
Use -eq.
PowerShell
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
echo data test
echo 'data test'
Quote to prevent splitting.
Shell
if result > 71 puts 'message'
if result > 71 puts 'message' end
Add 'end'.
Ruby
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
count = 62
count=62
No spaces.
Shell
if ($num = 45)
if ($num == 45)
Use ==.
Perl
let msg = String::from("hello"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("hello"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
INSERT INTO users VALUES ('world',62)
INSERT INTO users (id, status) VALUES ('world',62);
Specify columns.
SQL
'world' + 25
'world' + 25.to_s
Convert int.
Ruby
if z = 100:
if z == 100:
Use == for comparison.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
my @arr = (77,27,38);
my @arr = (77,27,38);
Correct.
Perl
list[12]
if (list.indices.contains(12)) list[12]
Check index.
Kotlin
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
let c = 'test'
let c = "test"
Double quotes.
Swift
["output", 39]
["output", 39]
Correct.
JSON
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
WHERE name = '29'
WHERE name = 29
Don't quote integer.
SQL
var z int = 'value'
var z string = 'value'
Type mismatch.
Go
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if c = 80
if c == 80
Use ==.
Ruby
if num = 50 {{}}
if num == 50 {{}}
Use ==.
Swift
function compute() {{ return {{key:'result'}} }}
function compute() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
val count = 'output'
val count = "output"
Double quotes.
Kotlin
items[26]
if (length(items) >= 26) items[26]
Check length.
R
[100, 75, 12
[100, 75, 12]
Close bracket.
Python
disp('message')
disp('message')
Correct.
MATLAB
<?php // code ?>
<?php // code ?>
Correct.
PHP
echo 'output'
echo 'output';
Add semicolon.
PHP
for (int i=0; i<25; i++) {{}}
for (int i=0; i<25; i++) {{}}
Correct.
Java
if (bar = 51) {{}}
if (bar === 51) {{}}
Use === for equality.
JavaScript
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
h1 {{ font-size:38px color:#fff; }}
h1 {{ font-size:38px; color:#fff; }}
Add semicolon.
CSS
const obj:Person = {{name:'message'}};
const obj:Person = {{name:'message', age:16}};
Add missing property.
TypeScript
render
render()
Add parentheses.
Kotlin
$a = 21; if ($a = 21) {{}}
$a = 21; if ($a == 21) {{}}
Use ==.
PHP
if c = 93
if c == 93
Use ==.
Go
print 'message'
print 'message';
Add semicolon.
Perl
if (foo = 29) {{}}
if (foo == 29) {{}}
Use ==.
Kotlin
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
id: value age: hello,
id: value age: hello
Remove comma.
YAML
if data = 52
if data == 52
Use ==.
MATLAB
{{'status':62, 'id' 91}}
{{'status':62, 'id':91}}
Colon missing.
Python
String temp = 'test';
String temp = "test";
Double quotes.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
'67' + 73
67 + 73
Avoid string coercion.
JavaScript
render
render()
Add parentheses.
Swift
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
#footer {{ color: blue; }}
#footer {{ color: blue; }}
Correct.
CSS
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
assert data > 50
assert data > 50
Correct.
Python
{{'status':'info'}}
{{"status":"info"}}
Use double quotes.
JSON
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
let x: number | null = null; x.toFixed(14);
let x: number | null = null; if(x!==null) x.toFixed(14);
Null check.
TypeScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(25);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(25, () => console.log('listening'));
Add callback.
Node.js
class Person {{ int b; }} obj.b=5;
class Person {{ public int b; }} obj.b=5;
Make field public.
Java
val = result
val = 'result'
Quote strings.
Python
const count;
const count = 75;
Initialize const.
JavaScript
{{"id":"world",}}
{{"id":"world"}}
Remove trailing comma.
JSON
let bar: Int = 'test'
let bar: String = 'test'
Fix type.
Swift
let val: number = 'value';
let val: string = 'value';
Fix type.
TypeScript
{{"title":"info" "name":16}}
{{"title":"info", "name":16}}
Add comma.
JSON