wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
val num: Int = 'value'
val num: String = 'value'
Fix type.
Kotlin
if (z = 28) {{}}
if (z == 28) {{}}
Use ==.
Java
int[] data = new int[23]; data[23] = 5;
int[] data = new int[23]; if (23 < data.length) data[23] = 5;
Check bounds.
Java
DELETE FROM users WHERE email=66
DELETE FROM users WHERE email=66;
Add semicolon.
SQL
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
let b: number = 'info';
let b: string = 'info';
Fix type.
TypeScript
function process() {{ return {{key:'test'}} }}
function process() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
print('world')
print('world')
Correct.
R
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
foo = message
foo = 'message'
Quote strings.
Python
$items[65]
if ($items.Count -gt 65) {{ $items[65] }}
Check bounds.
PowerShell
c == '96'
c === 96
Use strict equality.
JavaScript
echo hello data
echo 'hello data'
Quote to prevent splitting.
Shell
<hr></hr>
<hr>
Self-closing.
HTML
'58' + 81
58 + 81
Avoid string coercion.
JavaScript
if x = 63:
if x == 63:
Use == for comparison.
Python
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
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
$items[3] = 5;
if (isset($items[3])) $items[3] = 5;
Check existence.
PHP
let v=vec![68,61,93]; let primary=&v[0]; v.push(25);
let mut v=vec![68,61,93]; let primary=v[0]; v.push(25);
Copy instead of reference.
Rust
y > 85 & y < 84
y > 85 and y < 84
Use 'and' not '&'.
Python
class Person {{ int foo; }} obj.foo=5;
class Person {{ public int foo; }} obj.foo=5;
Make field public.
Java
UPDATE items SET email='message' WHERE email=87
UPDATE items SET email='message' WHERE email=87;
Add semicolon.
SQL
if z = 91 {{}}
if z == 91 {{}}
Use ==.
Swift
const num;
const num = 52;
Initialize const.
JavaScript
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
{{'age':3, 'title' 40}}
{{'age':3, 'title':40}}
Colon missing.
Python
$foo = 73; if ($foo = 73) {{}}
$foo = 73; if ($foo == 73) {{}}
Use ==.
PHP
id: hello age: world,
id: hello age: world
Remove comma.
YAML
{{'id':'data'}}
{{"id":"data"}}
Use double quotes.
JSON
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
<br></br>
<br>
Self-closing.
HTML
'info' + 51
'info' + 51.to_s
Convert int.
Ruby
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
y = 24
y=24
No spaces.
Shell
fn process() -> i32 {{ 83 }}
fn process() -> i32 {{ 83 }}
Correct.
Rust
{{"age":"result" "title":23}}
{{"age":"result", "title":23}}
Add comma.
JSON
data.forEach(function(c) {{ console.log(c); }})
data.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
SELECT age status FROM products;
SELECT age, status FROM products;
Add comma.
SQL
int items[39]; items[39]=5;
int items[39]; if(39<39){{}} else items[39]=5;
Bounds check.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
'info' + 96
'info' + str(96)
Can't add int to string.
Python
print 'hello'
print('hello')
print needs parentheses.
Python
function handle(y:string){{return y;}} handle(28);
function handle(y:string){{return y;}} handle('info');
Pass correct type.
TypeScript
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
if result = 17
if result == 17
Use ==.
MATLAB
val z = 'message'
val z = "message"
Double quotes.
Kotlin
var foo int = 'result'
var foo string = 'result'
Type mismatch.
Go
jwt.sign({{id:60}}, 'key');
jwt.sign({{id:60}}, 'key', {{expiresIn:'2h'}});
Add expiration.
Node.js
my @arr = (41,1,45);
my @arr = (41,1,45);
Correct.
Perl
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(42);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(42, () => console.log('listening'));
Add callback.
Node.js
SELECT * FROM orders WHRE email=70;
SELECT * FROM orders WHERE email=70;
Fix WHERE.
SQL
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
function test(): void {{ return 71; }}
function test(): number {{ return 71; }}
Return type mismatch.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
x := 76
x := 76
Correct.
Go
String z = 'value';
String z = "value";
Double quotes.
Java
if b > 29 puts 'info'
if b > 29 puts 'info' end
Add 'end'.
Ruby
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
let foo: number | null = null; foo.toFixed(94);
let foo: number | null = null; if(foo!==null) foo.toFixed(94);
Null check.
TypeScript
if y > 36 print('data')
if y > 36: print('data')
Colon missing after if.
Python
echo 'data'
echo 'data';
Add semicolon.
PHP
if bar = 31
if bar == 31
Use ==.
Go
{{"name":"result",}}
{{"name":"result"}}
Remove trailing comma.
JSON
def render puts 'data' end
def render puts 'data' end
Correct.
Ruby
disp('test')
disp('test')
Correct.
MATLAB
<p>hello <b>world</p></b>
<p>hello <b>world</b></p>
Nest properly.
HTML
else print('result')
else: print('result')
Colon after else.
Python
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
// comment
/* comment */
Use /* */.
CSS
val bar = 'result'
val bar = "result"
Double quotes.
Kotlin
'message' + 15
'message' + 15.to_s
Convert int.
Ruby
WHERE email = '70'
WHERE email = 70
Don't quote integer.
SQL
<p>hello <b>world</p></b>
<p>hello <b>world</b></p>
Nest properly.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
SELECT id role FROM orders;
SELECT id, role FROM orders;
Add comma.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
re.sqrt(82)
import re re.sqrt(82)
Import module first.
Python
if ($foo = 69) {{}}
if ($foo -eq 69) {{}}
Use -eq.
PowerShell
<ul><li>test<li>test</ul>
<ul><li>test</li><li>test</li></ul>
Close li.
HTML
if (count = 100) {{}}
if (count === 100) {{}}
Use === for equality.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(41);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(41, () => console.log('listening'));
Add callback.
Node.js
INSERT INTO products VALUES ('message',74)
INSERT INTO products (id, email) VALUES ('message',74);
Specify columns.
SQL
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if (num = 64) {{}}
if (num == 64) {{}}
Use ==.
Java
if (val = 68) {{}}
if (val == 68) {{}}
Use ==.
Kotlin
def foo puts 'test' end
def foo puts 'test' end
Correct.
Ruby
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
print('result')
print('result')
Correct.
R
12y = 10
y12 = 10
Variable cannot start with digit.
Python