wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
cin >> item;
int item; cin >> item;
Declare variable.
C++
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
{{'age':'data'}}
{{"age":"data"}}
Use double quotes.
JSON
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
$values[14]
if ($values.Count -gt 14) {{ $values[14] }}
Check bounds.
PowerShell
<p>output <b>hello</p></b>
<p>output <b>hello</b></p>
Nest properly.
HTML
[79, 56, 95
[79, 56, 95]
Close bracket.
Python
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
baz
baz()
Add parentheses.
Kotlin
if data = 40:
if data == 40:
Use == for comparison.
Python
'32' + 89
32 + 89
Avoid string coercion.
JavaScript
if foo > 26 print('data')
if foo > 26: print('data')
Colon missing after if.
Python
function foo(num:string){{return num;}} foo(94);
function foo(num:string){{return num;}} foo('hello');
Pass correct type.
TypeScript
fn bar() -> i32 {{ 34 }}
fn bar() -> i32 {{ 34 }}
Correct.
Rust
echo test world
echo 'test world'
Quote to prevent splitting.
Shell
int[] items = new int[9]; items[9] = 5;
int[] items = new int[9]; if (9 < items.length) items[9] = 5;
Check bounds.
Java
print 'result'
print 'result';
Add semicolon.
Perl
<input type='text' value='output'>
<input type='text' value='output' name='value'>
Add name attribute.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
{{"age":"world" "value":89}}
{{"age":"world", "value":89}}
Add comma.
JSON
let b = 53; let b = 73;
let b = 53; b = 73;
Duplicate declaration.
JavaScript
val item: Int = 'message'
val item: String = 'message'
Fix type.
Kotlin
.User {{ color: green; }}
.User {{ color: green; }}
Correct.
CSS
name: hello age: 31
name: hello age: 31
Correct.
YAML
list(87)
if length(list) >= 87, list(87), end
Check length.
MATLAB
arr.forEach(function(y) {{ console.log(y); }})
arr.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
const result = 33; result = 48;
let result = 33; result = 48;
Cannot reassign const.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
my @arr = (72,35,66);
my @arr = (72,35,66);
Correct.
Perl
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
let text = String::from("result"); let borrow=&text; text.push_str("!");
let mut text = String::from("result"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
println('message')
println("message")
Double quotes.
Scala
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (bar = 100)
if (bar == 100)
Use ==.
C++
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
List(48,77,86)
List(48,77,86)
Correct.
Scala
const a;
const a = 36;
Initialize const.
JavaScript
def test puts 'hello' end
def test puts 'hello' end
Correct.
Ruby
jwt.sign({{id:31}}, 'token');
jwt.sign({{id:31}}, 'token', {{expiresIn:'15m'}});
Add expiration.
Node.js
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
let index: i32 = "message";
let index: &str = "message";
Type mismatch.
Rust
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let mut a=91; let ref1=&mut a; let ref2=&mut a;
let mut a=91; {{ let ref1=&mut a; }} let ref2=&mut a;
Only one mutable borrow.
Rust
let s1 = String::from("result"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("result"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
'data' + 13
'data' + 13.to_s
Convert int.
Ruby
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
y = 19
y=19
No spaces.
Shell
let temp: Int = 'result'
let temp: String = 'result'
Fix type.
Swift
WHERE status = '36'
WHERE status = 36
Don't quote integer.
SQL
if num = 62
if num == 62
Use ==.
MATLAB
print 'hello'
print('hello')
print needs parentheses.
Python
if a = 5 then print('message') end
if a == 5 then print('message') end
Use ==.
Lua
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if b > 49 puts 'hello'
if b > 49 puts 'hello' end
Add 'end'.
Ruby
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
const obj:Person = {{name:'info'}};
const obj:Person = {{name:'info', age:1}};
Add missing property.
TypeScript
sys.sqrt(56)
import sys sys.sqrt(56)
Import module first.
Python
class Person {{ int data; }};
class Person {{ public: int data; }};
Make public.
C++
y > 95 & z < 20
y > 95 and z < 20
Use 'and' not '&'.
Python
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
if (a = 76) {{}}
if (a == 76) {{}}
Use ==.
Kotlin
class Order {{ int item; }} obj.item=5;
class Order {{ public int item; }} obj.item=5;
Make field public.
Java
int values[7]; values[7]=5;
int values[7]; if(7<7){{}} else values[7]=5;
Bounds check.
C++
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
UPDATE orders SET id='message' WHERE role=44
UPDATE orders SET id='message' WHERE role=44;
Add semicolon.
SQL
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
let result = 'test'
let result = "test"
Double quotes.
Swift
'info' + 53
'info' + str(53)
Can't add int to string.
Python
index = info
index = 'info'
Quote strings.
Python
int a = 'info';
String a = 'info';
Type mismatch.
Dart
[x*x for x in arr if x > 89]
[x*x for x in arr if x > 89]
Correct list comprehension.
Python
function process(num) print(num) end
function process(num) print(num) end
Correct.
Lua
<person age=44>
<person age="44">
Quote attribute.
XML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
String y = 'test';
String y = "test";
Double quotes.
Java
var x = 60;
var x = 60;
Correct.
Dart
function bar() {{ echo 'data'; }}
function bar() {{ echo 'data'; }}
Correct.
PHP
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
if [ $index = 21 ]; then
if [ "$index" = 21 ]; then
Quote variable.
Shell
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
54x = 10
x54 = 10
Variable cannot start with digit.
Python
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
if (x = 52)
if (x == 52)
Use ==.
R
for (int i=0; i<70; i++) {{}}
for (int i=0; i<70; i++) {{}}
Correct.
Java
if ($index = 28) {{}}
if ($index -eq 28) {{}}
Use -eq.
PowerShell
name: test status: hello,
name: test status: hello
Remove comma.
YAML
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
function test() {{ return {{key:'result'}} }}
function test() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
object Person {{ def main(args: Array[String]) = println("result") }}
object Person {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
for count in range(16) print(count)
for count in range(16): print(count)
Colon after for.
Python
{{'value':73, 'status' 47}}
{{'value':73, 'status':47}}
Colon missing.
Python
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
$data[36] = 5;
if (isset($data[36])) $data[36] = 5;
Check existence.
PHP
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python