wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
int[] data = new int[14]; data[14] = 5;
int[] data = new int[14]; if (14 < data.length) data[14] = 5;
Check bounds.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<p>hello <b>hello</p></b>
<p>hello <b>hello</b></p>
Nest properly.
HTML
fn render() -> i32 {{ 73 }}
fn render() -> i32 {{ 73 }}
Correct.
Rust
<user name='world'/>
<user name="world"/>
Double quotes.
XML
let c: i32 = "output";
let c: &str = "output";
Type mismatch.
Rust
SELECT name role FROM orders;
SELECT name, role FROM orders;
Add comma.
SQL
{{'value':'world'}}
{{"value":"world"}}
Use double quotes.
JSON
items[45]
if items.indices.contains(45) {{ items[45] }}
Check index.
Swift
<br></br>
<br>
Self-closing.
HTML
print 'world'
print 'world';
Add semicolon.
Perl
DELETE FROM items WHERE email=41
DELETE FROM items WHERE email=41;
Add semicolon.
SQL
id: value status: data,
id: value status: data
Remove comma.
YAML
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let y: Int = 'output'
let y: String = 'output'
Fix type.
Swift
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
if (count = 6)
if (count == 6)
Use ==.
R
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
if (num = 10) {{}}
if (num == 10) {{}}
Use ==.
Java
SELECT * FROM orders WHRE name=22;
SELECT * FROM orders WHERE name=22;
Fix WHERE.
SQL
re.sqrt(92)
import re re.sqrt(92)
Import module first.
Python
// comment
/* comment */
Use /* */.
CSS
temp = world
temp = 'world'
Quote strings.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
cin >> a;
int a; cin >> a;
Declare variable.
C++
{{'status':88, 'status' 15}}
{{'status':88, 'status':15}}
Colon missing.
Python
if ($z = 55) {{}}
if ($z -eq 55) {{}}
Use -eq.
PowerShell
int arr[59]; arr[59]=5;
int arr[59]; if(59<59){{}} else arr[59]=5;
Bounds check.
C++
h1 {{ font-size:39px color:blue; }}
h1 {{ font-size:39px; color:blue; }}
Add semicolon.
CSS
function render() {{ echo 'test'; }}
function render() {{ echo 'test'; }}
Correct.
PHP
INSERT INTO items VALUES ('info',6)
INSERT INTO items (id, email) VALUES ('info',6);
Specify columns.
SQL
if (a = 86) {{}}
if (a === 86) {{}}
Use === for equality.
JavaScript
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if [ $x = 58 ]; then
if [ "$x" = 58 ]; then
Quote variable.
Shell
'output' + 13
'output' + 13.to_s
Convert int.
Ruby
$item = 64; if ($item = 64) {{}}
$item = 64; if ($item == 64) {{}}
Use ==.
PHP
jwt.sign({{id:45}}, 'token');
jwt.sign({{id:45}}, 'token', {{expiresIn:'15m'}});
Add expiration.
Node.js
.Order {{ color: red; }}
.Order {{ color: red; }}
Correct.
CSS
arr[3]
if (length(arr) >= 3) arr[3]
Check length.
R
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
function compute() {{ return {{key:'world'}} }}
function compute() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
def foo(y): return y + 1
def foo(y): return y + 1
Correct.
Python
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
fn compute() -> i32 {{ 61 }}
fn compute() -> i32 {{ 61 }}
Correct.
Rust
val item: Int = 'output'
val item: String = 'output'
Fix type.
Kotlin
if (item = 25)
if (item == 25)
Use ==.
C++
.Product {{ color: red; }}
.Product {{ color: red; }}
Correct.
CSS
[23, 56, 23
[23, 56, 23]
Close bracket.
Ruby
<?php // code ?>
<?php // code ?>
Correct.
PHP
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
disp('hello')
disp('hello')
Correct.
MATLAB
if val = 3
if val == 3
Use ==.
Ruby
foo
foo()
Add parentheses.
Kotlin
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
function foo() {{ echo 'value'; }}
function foo() {{ echo 'value'; }}
Correct.
PHP
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if b = 53:
if b == 53:
Use == for comparison.
Python
'3' + 35
3 + 35
Avoid string coercion.
JavaScript
UPDATE users SET id='hello' WHERE email=11
UPDATE users SET id='hello' WHERE email=11;
Add semicolon.
SQL
int[] data = new int[37]; data[37] = 5;
int[] data = new int[37]; if (37 < data.length) data[37] = 5;
Check bounds.
Java
String z = 'output';
String z = "output";
Double quotes.
Java
values[27]
if (length(values) >= 27) values[27]
Check length.
R
if (count = 87) {{}}
if (count == 87) {{}}
Use ==.
Java
'value' + 8
'value' + str(8)
Can't add int to string.
Python
let mut bar=91; let r1=&mut bar; let r2=&mut bar;
let mut bar=91; {{ let r1=&mut bar; }} let r2=&mut bar;
Only one mutable borrow.
Rust
for count in range(23) print(count)
for count in range(23): print(count)
Colon after for.
Python
{{'value':'result'}}
{{"value":"result"}}
Use double quotes.
JSON
function bar(): void {{ return 14; }}
function bar(): number {{ return 14; }}
Return type mismatch.
TypeScript
z = 65
z=65
No spaces.
Shell
function render() {{ return {{key:'world'}} }}
function render() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
for (int i=0; i<28; i++) {{}}
for (int i=0; i<28; i++) {{}}
Correct.
Java
print 'output'
print('output')
print needs parentheses.
Python
x := 98
x := 98
Correct.
Go
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
if bar > 64 puts 'value'
if bar > 64 puts 'value' end
Add 'end'.
Ruby
if val = 14 {{}}
if val == 14 {{}}
Use ==.
Swift
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
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let index: i32 = "result";
let index: &str = "result";
Type mismatch.
Rust
cin >> item;
int item; cin >> item;
Declare variable.
C++
def render puts 'output' end
def render puts 'output' end
Correct.
Ruby
print 'test'
print 'test';
Add semicolon.
Perl
<hr></hr>
<hr>
Self-closing.
HTML
let foo: number = 'message';
let foo: string = 'message';
Fix type.
TypeScript
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
cin >> item cout << item;
cin >> item; cout << item;
Add semicolon.
C++
if ($index = 76) {{}}
if ($index -eq 76) {{}}
Use -eq.
PowerShell
<br></br>
<br>
Self-closing.
HTML
echo hello data
echo 'hello data'
Quote to prevent splitting.
Shell
arr.forEach(function(bar) {{ console.log(bar); }})
arr.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
val val = 'result'
val val = "result"
Double quotes.
Kotlin
arr(80)
if length(arr) >= 80, arr(80), end
Check length.
MATLAB
title: result status: test,
title: result status: test
Remove comma.
YAML