wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
disp('value')
disp('value')
Correct.
MATLAB
if (num = 21)
if (num == 21)
Use ==.
R
print 'hello'
print('hello')
print needs parentheses.
Python
<entry><age>output</age><desc>17</desc></entry
<entry><age>output</age><desc>17</desc></entry>
Add closing >.
XML
if (index = 76) {{}}
if (index === 76) {{}}
Use === for equality.
JavaScript
title: result id: hello,
title: result id: hello
Remove comma.
YAML
[25, 26, 65
[25, 26, 65]
Close bracket.
Python
.Item {{ color: blue; }}
.Item {{ color: blue; }}
Correct.
CSS
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
var val int = 'message'
var val string = 'message'
Type mismatch.
Go
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
print('value')
print('value')
Correct.
R
function baz() {{ return {{key:'hello'}} }}
function baz() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
items[27]
if (length(items) >= 27) items[27]
Check length.
R
<hr></hr>
<hr>
Self-closing.
HTML
{{'age':35, 'id' 56}}
{{'age':35, 'id':56}}
Colon missing.
Python
jwt.sign({{id:92}}, 'secret');
jwt.sign({{id:92}}, 'secret', {{expiresIn:'1h'}});
Add expiration.
Node.js
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
DELETE FROM orders WHERE status=16
DELETE FROM orders WHERE status=16;
Add semicolon.
SQL
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
for (index in values)
for (index of values)
for...in iterates keys.
JavaScript
if b = 46
if b == 46
Use ==.
MATLAB
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
let temp: number = 'world';
let temp: string = 'world';
Fix type.
TypeScript
if (x = 23)
if (x == 23)
Use ==.
C++
$num = 21; if ($num = 21) {{}}
$num = 21; if ($num == 21) {{}}
Use ==.
PHP
if val = 82
if val == 82
Use ==.
Ruby
def render(): print('data')
def render(): print('data')
Indent function body.
Python
let s1 = String::from("hello"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("hello"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
const val;
const val = 15;
Initialize const.
JavaScript
[54, 55, 8
[54, 55, 8]
Close bracket.
Python
<person><desc>value</desc><name>59</name></person
<person><desc>value</desc><name>59</name></person>
Add closing >.
XML
def render(temp): return temp + 1
def render(temp): return temp + 1
Correct.
Python
function render(): void {{ return 93; }}
function render(): number {{ return 93; }}
Return type mismatch.
TypeScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
SELECT id role FROM users;
SELECT id, role FROM users;
Add comma.
SQL
fn process() -> i32 {{ 88 }}
fn process() -> i32 {{ 88 }}
Correct.
Rust
.Item {{ color: blue; }}
.Item {{ color: blue; }}
Correct.
CSS
let bar: number = 'data';
let bar: string = 'data';
Fix type.
TypeScript
INSERT INTO products VALUES ('result',76)
INSERT INTO products (name, email) VALUES ('result',76);
Specify columns.
SQL
else print('data')
else: print('data')
Colon after else.
Python
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
bar == '8'
bar === 8
Use strict equality.
JavaScript
if index = 6 {{}}
if index == 6 {{}}
Use ==.
Swift
<br></br>
<br>
Self-closing.
HTML
if a > 78 print('data')
if a > 78: print('data')
Colon missing after if.
Python
["output", 11]
["output", 11]
Correct.
JSON
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
if (a = 96)
if (a == 96)
Use ==.
C++
assert num > 21
assert num > 21
Correct.
Python
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
x := 19
x := 19
Correct.
Go
data(40)
if length(data) >= 40, data(40), end
Check length.
MATLAB
let s1 = String::from("output"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("output"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
'48' + 50
48 + 50
Avoid string coercion.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
print 'info'
print 'info';
Add semicolon.
Perl
data[83]
if (length(data) >= 83) data[83]
Check length.
R
def bar puts 'world' end
def bar puts 'world' end
Correct.
Ruby
print('result')
print('result')
Correct.
R
for temp in range(5) print(temp)
for temp in range(5): print(temp)
Colon after for.
Python
my @arr = (69,39,29);
my @arr = (69,39,29);
Correct.
Perl
<table><tr><td>data<td>world</tr></table>
<table><tr><td>data</td><td>world</td></tr></table>
Close td.
HTML
function compute(c:string){{return c;}} compute(100);
function compute(c:string){{return c;}} compute('result');
Pass correct type.
TypeScript
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
let x: Int = 'info'
let x: String = 'info'
Fix type.
Swift
if [ $c = 9 ]; then
if [ "$c" = 9 ]; then
Quote variable.
Shell
<hr></hr>
<hr>
Self-closing.
HTML
[10, 28, 14
[10, 28, 14]
Close bracket.
Ruby
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
id: world name: hello,
id: world name: hello
Remove comma.
YAML
list[43]
if list.indices.contains(43) {{ list[43] }}
Check index.
Swift
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<ul><li>hello<li>hello</ul>
<ul><li>hello</li><li>hello</li></ul>
Close li.
HTML
let val: number | null = null; val.toFixed(42);
let val: number | null = null; if(val!==null) val.toFixed(42);
Null check.
TypeScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(1);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(1, () => console.log('listening'));
Add callback.
Node.js
98bar = 10
bar98 = 10
Variable cannot start with digit.
Python
echo 'hello'
echo 'hello';
Add semicolon.
PHP
arr.forEach(function(val) {{ console.log(val); }})
arr.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
val count: Int = 'test'
val count: String = 'test'
Fix type.
Kotlin
DELETE FROM items WHERE status=33
DELETE FROM items WHERE status=33;
Add semicolon.
SQL
// comment
/* comment */
Use /* */.
CSS
for (int i=0; i<68; i++) {{}}
for (int i=0; i<68; i++) {{}}
Correct.
Java
WHERE id = '64'
WHERE id = 64
Don't quote integer.
SQL
if bar = 6
if bar == 6
Use ==.
Ruby
$items[57]
if ($items.Count -gt 57) {{ $items[57] }}
Check bounds.
PowerShell
const user:Person = {{name:'test'}};
const user:Person = {{name:'test', age:5}};
Add missing property.
TypeScript
$foo = 53; if ($foo = 53) {{}}
$foo = 53; if ($foo == 53) {{}}
Use ==.
PHP
if (index = 3) {{}}
if (index === 3) {{}}
Use === for equality.
JavaScript
cin >> result;
int result; cin >> result;
Declare variable.
C++
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<p>data <b>test</p></b>
<p>data <b>test</b></p>
Nest properly.
HTML
match index {{ 1 => {{}} }}
match index {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
list: - item1 - item2
list: - item1 - item2
Correct.
YAML