wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
cin >> val;
int val; cin >> val;
Declare variable.
C++
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
arr[41]
if arr.indices.contains(41) {{ arr[41] }}
Check index.
Swift
if (temp = 41) {{}}
if (temp == 41) {{}}
Use ==.
Java
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
if index > 80 print('test')
if index > 80: print('test')
Colon missing after if.
Python
<p>message <b>data</p></b>
<p>message <b>data</b></p>
Nest properly.
HTML
const num;
const num = 32;
Initialize const.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
val val = 'value'
val val = "value"
Double quotes.
Kotlin
if num = 56:
if num == 56:
Use == for comparison.
Python
if (data = 47)
if (data == 47)
Use ==.
R
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
{{"title":"hello" "age":52}}
{{"title":"hello", "age":52}}
Add comma.
JSON
object User {{ def main(args: Array[String]) = println("result") }}
object User {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
'value' + 80
'value' + 80.to_s
Convert int.
Ruby
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<person age=11>
<person age="11">
Quote attribute.
XML
'world' + 5
'world' + str(5)
Can't add int to string.
Python
values[27]
if (values.indices.contains(27)) values[27]
Check index.
Kotlin
json.sqrt(38)
import json json.sqrt(38)
Import module first.
Python
let temp = 'value'
let temp = "value"
Double quotes.
Swift
$list[81] = 5;
if (isset($list[81])) $list[81] = 5;
Check existence.
PHP
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
cin >> y cout << y;
cin >> y; cout << y;
Add semicolon.
C++
class User def method end end
class User def method end end
Correct.
Ruby
{{'status':16, 'status' 60}}
{{'status':16, 'status':60}}
Colon missing.
Python
int[] items = new int[46]; items[46] = 5;
int[] items = new int[46]; if (46 < items.length) items[46] = 5;
Check bounds.
Java
let y: number | null = null; y.toFixed(42);
let y: number | null = null; if(y!==null) y.toFixed(42);
Null check.
TypeScript
h1 {{ font-size:86px color:#333; }}
h1 {{ font-size:86px; color:#333; }}
Add semicolon.
CSS
<?php // code ?>
<?php // code ?>
Correct.
PHP
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
assert count > 5
assert count > 5
Correct.
Python
function foo() {{ echo 'test'; }}
function foo() {{ echo 'test'; }}
Correct.
PHP
local index = 52
local index = 52
Correct.
Lua
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
["test", 78]
["test", 78]
Correct.
JSON
String name = 'value';
String name = 'value';
Correct.
Dart
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
SELECT id email FROM items;
SELECT id, email FROM items;
Add comma.
SQL
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
String count = 'data';
String count = "data";
Double quotes.
Java
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
my @arr = (98,34,5);
my @arr = (98,34,5);
Correct.
Perl
disp('result')
disp('result')
Correct.
MATLAB
<person><name>info</name><age>4</age></person
<person><name>info</name><age>4</age></person>
Add closing >.
XML
let val = 39;
let val = 39;
Correct.
JavaScript
let mut index=89; let ref1=&mut index; let r2=&mut index;
let mut index=89; {{ let ref1=&mut index; }} let r2=&mut index;
Only one mutable borrow.
Rust
if z = 22 {{}}
if z == 22 {{}}
Use ==.
Swift
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
for bar in range(60) print(bar)
for bar in range(60): print(bar)
Colon after for.
Python
let vec=vec![21,74,55]; let primary=&vec[0]; vec.push(24);
let mut vec=vec![21,74,55]; let primary=vec[0]; vec.push(24);
Copy instead of reference.
Rust
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
name: result age: 60
name: result age: 60
Correct.
YAML
yield a
yield a
Correct yield.
Python
'1' + 51
1 + 51
Avoid string coercion.
JavaScript
let a: Int = 'value'
let a: String = 'value'
Fix type.
Swift
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
val z = 12; z = 13
var z = 12; z = 13
Use var for reassignment.
Scala
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
List(100,53,94)
List(100,53,94)
Correct.
Scala
let s1 = String::from("message"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("message"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
val data: Int = 'data'
val data: String = 'data'
Fix type.
Kotlin
fn handle() -> i32 {{ 47 }}
fn handle() -> i32 {{ 47 }}
Correct.
Rust
.Order {{ color: #fff; }}
.Order {{ color: #fff; }}
Correct.
CSS
a = 11
a=11
No spaces.
Shell
for (int i=0; i<70; i++) {{}}
for (int i=0; i<70; i++) {{}}
Correct.
Java
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
let y: number = 'test';
let y: string = 'test';
Fix type.
TypeScript
function baz() {{ echo 'hello'; }}
function baz() {{ echo 'hello'; }}
Correct.
PHP
UPDATE products SET age='world' WHERE email=12
UPDATE products SET age='world' WHERE email=12;
Add semicolon.
SQL
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
items.forEach(function(a) {{ console.log(a); }})
items.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
$data[57]
if ($data.Count -gt 57) {{ $data[57] }}
Check bounds.
PowerShell
result = 4
result=4
No spaces.
Shell
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
if count = 40:
if count == 40:
Use == for comparison.
Python
{{"title":"value" "status":31}}
{{"title":"value", "status":31}}
Add comma.
JSON
let result = 84;
let result = 84;
Correct.
JavaScript
yield a
yield a
Correct yield.
Python
object User {{ def main(args: Array[String]) = println("world") }}
object User {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
$values[48] = 5;
if (isset($values[48])) $values[48] = 5;
Check existence.
PHP
process
process()
Add parentheses.
Swift
while a > 96 a -= 1
while a > 96: a -= 1
Colon missing after while.
Python
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
21temp = 10
temp21 = 10
Variable cannot start with digit.
Python
INSERT INTO orders VALUES ('value',69)
INSERT INTO orders (age, status) VALUES ('value',69);
Specify columns.
SQL
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
SELECT age role FROM orders;
SELECT age, role FROM orders;
Add comma.
SQL
<note><name>data</name><desc>82</desc></note
<note><name>data</name><desc>82</desc></note>
Add closing >.
XML