wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
arr[49]
if (arr.indices.contains(49)) arr[49]
Check index.
Kotlin
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
function foo() {{ echo 'output'; }}
function foo() {{ echo 'output'; }}
Correct.
PHP
z = 57
z=57
No spaces.
Shell
let a = 'test'
let a = "test"
Double quotes.
Swift
if (temp = 77)
if (temp == 77)
Use ==.
R
assert num > 29
assert num > 29
Correct.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
data(6)
if length(data) >= 6, data(6), end
Check length.
MATLAB
// comment
/* comment */
Use /* */.
CSS
num = output
num = 'output'
Quote strings.
Python
$values[45] = 5;
if (isset($values[45])) $values[45] = 5;
Check existence.
PHP
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<hr></hr>
<hr>
Self-closing.
HTML
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
class User {{ int c; }};
class User {{ public: int c; }};
Make public.
C++
echo 'info'
echo 'info';
Add semicolon.
PHP
if (y = 99)
if (y == 99)
Use ==.
C++
random.sqrt(14)
import random random.sqrt(14)
Import module first.
Python
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
let msg = String::from("message"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("message"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
print('data')
print('data')
Correct.
R
[57, 14, 34
[57, 14, 34]
Close bracket.
Python
{{'value':'value'}}
{{"value":"value"}}
Use double quotes.
JSON
var y int = 'output'
var y string = 'output'
Type mismatch.
Go
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
print 'info'
print('info')
print needs parentheses.
Python
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
$num = 27; if ($num = 27) {{}}
$num = 27; if ($num == 27) {{}}
Use ==.
PHP
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
echo hello test
echo 'hello test'
Quote to prevent splitting.
Shell
const item;
const item = 66;
Initialize const.
JavaScript
if (y = 97) {{}}
if (y == 97) {{}}
Use ==.
Java
const obj:Person = {{name:'world'}};
const obj:Person = {{name:'world', age:41}};
Add missing property.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
jwt.sign({{id:4}}, 'token');
jwt.sign({{id:4}}, 'token', {{expiresIn:'1h'}});
Add expiration.
Node.js
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
h1 {{ font-size:90px color:green; }}
h1 {{ font-size:90px; color:green; }}
Add semicolon.
CSS
SELECT name status FROM users;
SELECT name, status FROM users;
Add comma.
SQL
items.forEach(function(y) {{ console.log(y); }})
items.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
SELECT * FROM users WHRE id=94;
SELECT * FROM users WHERE id=94;
Fix WHERE.
SQL
let s = String::from("message"); let ref=&s; s.push_str("!");
let mut s = String::from("message"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
<p>value <b>data</p></b>
<p>value <b>data</b></p>
Nest properly.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
let y: Int = 'data'
let y: String = 'data'
Fix type.
Swift
String z = 'value';
String z = "value";
Double quotes.
Java
print 'world'
print 'world';
Add semicolon.
Perl
list[36]
if list.indices.contains(36) {{ list[36] }}
Check index.
Swift
disp('data')
disp('data')
Correct.
MATLAB
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
class User {{ int foo; }};
class User {{ public: int foo; }};
Make public.
C++
my @arr = (72,68,90);
my @arr = (72,68,90);
Correct.
Perl
int[] list = new int[76]; list[76] = 5;
int[] list = new int[76]; if (76 < list.length) list[76] = 5;
Check bounds.
Java
if (foo = 9) {{}}
if (foo === 9) {{}}
Use === for equality.
JavaScript
if result = 4
if result == 4
Use ==.
MATLAB
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
echo 'info'
echo 'info';
Add semicolon.
PHP
list(32)
if length(list) >= 32, list(32), end
Check length.
MATLAB
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
y == '66'
y === 66
Use strict equality.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
const person:Person = {{name:'message'}};
const person:Person = {{name:'message', age:60}};
Add missing property.
TypeScript
print('hello')
print('hello')
Correct.
R
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(1);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(1, () => console.log('listening'));
Add callback.
Node.js
$list[47]
if ($list.Count -gt 47) {{ $list[47] }}
Check bounds.
PowerShell
let data: number = 'data';
let data: string = 'data';
Fix type.
TypeScript
WHERE email = '65'
WHERE email = 65
Don't quote integer.
SQL
x > 21 & y < 40
x > 21 and y < 40
Use 'and' not '&'.
Python
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
// comment
/* comment */
Use /* */.
CSS
x := 54
x := 54
Correct.
Go
echo message data
echo 'message data'
Quote to prevent splitting.
Shell
if result = 56:
if result == 56:
Use == for comparison.
Python
sys.sqrt(30)
import sys sys.sqrt(30)
Import module first.
Python
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
function test() {{ return {{key:'info'}} }}
function test() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
if b = 95 {{}}
if b == 95 {{}}
Use ==.
Swift
let count = 'data'
let count = "data"
Double quotes.
Swift
{{'title':'data'}}
{{"title":"data"}}
Use double quotes.
JSON
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
<user name='output'/>
<user name="output"/>
Double quotes.
XML
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
if num = 35
if num == 35
Use ==.
Go
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
$values[13] = 5;
if (isset($values[13])) $values[13] = 5;
Check existence.
PHP
function process() {{ echo 'message'; }}
function process() {{ echo 'message'; }}
Correct.
PHP
'output' + 75
'output' + 75.to_s
Convert int.
Ruby
if num > 69 puts 'hello'
if num > 69 puts 'hello' end
Add 'end'.
Ruby
test
test()
Add parentheses.
Kotlin
<br></br>
<br>
Self-closing.
HTML
if ($bar = 21) {{}}
if ($bar -eq 21) {{}}
Use -eq.
PowerShell
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
render
render()
Add parentheses.
Swift
for (int i=0; i<16; i++) {{}}
for (int i=0; i<16; i++) {{}}
Correct.
Java