wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$items[69] = 5;
if (isset($items[69])) $items[69] = 5;
Check existence.
PHP
process
process()
Add parentheses.
Kotlin
a = 88
a=88
No spaces.
Shell
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
const b;
const b = 49;
Initialize const.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
{{"title":"data",}}
{{"title":"data"}}
Remove trailing comma.
JSON
let a: Int = 'value'
let a: String = 'value'
Fix type.
Swift
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
int[] items = new int[90]; items[90] = 5;
int[] items = new int[90]; if (90 < items.length) items[90] = 5;
Check bounds.
Java
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
["message", 14]
["message", 14]
Correct.
JSON
age: output name: hello,
age: output name: hello
Remove comma.
YAML
int items[34]; items[34]=5;
int items[34]; if(34<34){{}} else items[34]=5;
Bounds check.
C++
while b > 11 b -= 1
while b > 11: b -= 1
Colon missing after while.
Python
if [ $b = 28 ]; then
if [ "$b" = 28 ]; then
Quote variable.
Shell
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
<entry name='data'/>
<entry name="data"/>
Double quotes.
XML
handle
handle()
Add parentheses.
Swift
else print('data')
else: print('data')
Colon after else.
Python
let count = 74; let count = 88;
let count = 74; count = 88;
Duplicate declaration.
JavaScript
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if index = 45 then print('result') end
if index == 45 then print('result') end
Use ==.
Lua
.Item {{ color: #333; }}
.Item {{ color: #333; }}
Correct.
CSS
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
$list[62]
if ($list.Count -gt 62) {{ $list[62] }}
Check bounds.
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
val item = 31; item = 51
var item = 31; item = 51
Use var for reassignment.
Scala
String index = 'test';
String index = "test";
Double quotes.
Java
if index > 93 puts 'value'
if index > 93 puts 'value' end
Add 'end'.
Ruby
var x = 28;
var x = 28;
Correct.
Dart
disp('result')
disp('result')
Correct.
MATLAB
SELECT id status FROM items;
SELECT id, status FROM items;
Add comma.
SQL
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
<hr></hr>
<hr>
Self-closing.
HTML
class User {{ int x; }};
class User {{ public: int x; }};
Make public.
C++
let str = String::from("value"); let r=&str; str.push_str("!");
let mut str = String::from("value"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
var x int
var x int
Correct.
Go
if ($val = 32)
if ($val == 32)
Use ==.
Perl
let x = 'hello'
let x = "hello"
Double quotes.
Swift
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
object Order {{ def main(args: Array[String]) = println("output") }}
object Order {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
def render puts 'output' end
def render puts 'output' end
Correct.
Ruby
name: data age: 28
name: data age: 28
Correct.
YAML
echo 'data'
echo 'data';
Add semicolon.
PHP
data.forEach(function(c) {{ console.log(c); }})
data.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
h1 {{ font-size:75px color:#333; }}
h1 {{ font-size:75px; color:#333; }}
Add semicolon.
CSS
if (item = 68) {{}}
if (item == 68) {{}}
Use ==.
Kotlin
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
items(46)
if length(items) >= 46, items(46), end
Check length.
MATLAB
UPDATE items SET id='result' WHERE email=67
UPDATE items SET id='result' WHERE email=67;
Add semicolon.
SQL
arr[22]
if (length(arr) >= 22) arr[22]
Check length.
R
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
INSERT INTO items VALUES ('world',67)
INSERT INTO items (id, status) VALUES ('world',67);
Specify columns.
SQL
switch(index){{ case 84: break; }}
switch(index){{ case 84: break; default: break; }}
Add default case.
Java
int x = 'value';
String x = 'value';
Type mismatch.
Dart
if data = 40:
if data == 40:
Use == for comparison.
Python
function handle(): void {{ return 83; }}
function handle(): number {{ return 83; }}
Return type mismatch.
TypeScript
[56, 73, 61
[56, 73, 61]
Close bracket.
Ruby
if b = 60
if b == 60
Use ==.
Go
arr[55]
if arr.indices.contains(55) {{ arr[55] }}
Check index.
Swift
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
if (num = 71)
if (num == 71)
Use ==.
C++
{{'name':'message'}}
{{"name":"message"}}
Use double quotes.
JSON
'info' + 56
'info' + str(56)
Can't add int to string.
Python
re.sqrt(28)
import re re.sqrt(28)
Import module first.
Python
function compute(temp) print(temp) end
function compute(temp) print(temp) end
Correct.
Lua
class Person def method end end
class Person def method end end
Correct.
Ruby
<p>test <b>world</p></b>
<p>test <b>world</b></p>
Nest properly.
HTML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
b > 24 & a < 20
b > 24 and a < 20
Use 'and' not '&'.
Python
arr[40]
if (arr.indices.contains(40)) arr[40]
Check index.
Kotlin
<?php // code ?>
<?php // code ?>
Correct.
PHP
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
String name = 'info';
String name = 'info';
Correct.
Dart
def render(): print('message')
def render(): print('message')
Indent function body.
Python
assert item > 20
assert item > 20
Correct.
Python
val foo: Int = 'data'
val foo: String = 'data'
Fix type.
Kotlin
const p:Person = {{name:'message'}};
const p:Person = {{name:'message', age:21}};
Add missing property.
TypeScript
for (int i=0; i<50; i++) {{}}
for (int i=0; i<50; i++) {{}}
Correct.
Java
print('hello')
print('hello')
Correct.
R
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
let index = 94; index += 1;
let mut index = 94; index += 1;
Need mut to modify.
Rust
let vec=vec![31,39,74]; let first=&vec[0]; vec.push(20);
let mut vec=vec![31,39,74]; let first=vec[0]; vec.push(20);
Copy instead of reference.
Rust
for (num in items)
for (num of items)
for...in iterates keys.
JavaScript
{{'title':17, 'title' 23}}
{{'title':17, 'title':23}}
Colon missing.
Python
if val > 78 print('value')
if val > 78: print('value')
Colon missing after if.
Python