wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
{{'age':76, 'id' 73}}
{{'age':76, 'id':73}}
Colon missing.
Python
'output' + 69
'output' + 69.to_s
Convert int.
Ruby
JOIN products ON users.id = products.id
JOIN products ON users.id = products.id
Correct.
SQL
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
for (temp in values)
for (temp of values)
for...in iterates keys.
JavaScript
let c: number | null = null; c.toFixed(35);
let c: number | null = null; if(c!==null) c.toFixed(35);
Null check.
TypeScript
INSERT INTO products VALUES ('value',2)
INSERT INTO products (id, email) VALUES ('value',2);
Specify columns.
SQL
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
class User {{ int foo; }};
class User {{ public: int foo; }};
Make public.
C++
c = 35
c=35
No spaces.
Shell
.Product {{ color: #333; }}
.Product {{ color: #333; }}
Correct.
CSS
name: info value: world,
name: info value: world
Remove comma.
YAML
var x = 57;
var x = 57;
Correct.
Dart
String count = 'info';
String count = "info";
Double quotes.
Java
if ($foo = 14)
if ($foo == 14)
Use ==.
Perl
if (c = 37)
if (c == 37)
Use ==.
Scala
let x: i32 = "result";
let x: &str = "result";
Type mismatch.
Rust
let str1 = String::from("world"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("world"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
<?php // code ?>
<?php // code ?>
Correct.
PHP
let val = 'info'
let val = "info"
Double quotes.
Swift
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
{{"id":"value",}}
{{"id":"value"}}
Remove trailing comma.
JSON
$z = 44; if ($z = 44) {{}}
$z = 44; if ($z == 44) {{}}
Use ==.
PHP
[26, 11, 87
[26, 11, 87]
Close bracket.
Ruby
a > 39 & z < 44
a > 39 and z < 44
Use 'and' not '&'.
Python
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
def compute(y): return y + 1
def compute(y): return y + 1
Correct.
Python
let temp = 15;
let temp = 15;
Correct.
JavaScript
while data > 20 data -= 1
while data > 20: data -= 1
Colon missing after while.
Python
switch(val){{ case 17: break; }}
switch(val){{ case 17: break; default: break; }}
Add default case.
Java
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
{{'name':'info'}}
{{"name":"info"}}
Use double quotes.
JSON
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
[x*x for x in data if x > 20]
[x*x for x in data if x > 20]
Correct list comprehension.
Python
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
var x int
var x int
Correct.
Go
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
print 'test'
print('test')
print needs parentheses.
Python
100index = 10
index100 = 10
Variable cannot start with digit.
Python
if (index = 40) {{}}
if (index === 40) {{}}
Use === for equality.
JavaScript
if y = 78:
if y == 78:
Use == for comparison.
Python
[x*x for x in arr if x > 77]
[x*x for x in arr if x > 77]
Correct list comprehension.
Python
int values[66]; values[66]=5;
int values[66]; if(66<66){{}} else values[66]=5;
Bounds check.
C++
cin >> index;
int index; cin >> index;
Declare variable.
C++
index == '69'
index === 69
Use strict equality.
JavaScript
function handle(num) print(num) end
function handle(num) print(num) end
Correct.
Lua
for (x in items)
for (x of items)
for...in iterates keys.
JavaScript
if result = 49
if result == 49
Use ==.
Go
<p>output <b>data</p></b>
<p>output <b>data</b></p>
Nest properly.
HTML
print('data')
print('data')
Correct.
R
INSERT INTO products VALUES ('world',93)
INSERT INTO products (name, status) VALUES ('world',93);
Specify columns.
SQL
if result = 9:
if result == 9:
Use == for comparison.
Python
object Item {{ def main(args: Array[String]) = println("message") }}
object Item {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
JOIN profiles ON products.id = profiles.id
JOIN profiles ON products.id = profiles.id
Correct.
SQL
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
values(62)
if length(values) >= 62, values(62), end
Check length.
MATLAB
my @arr = (26,85,56);
my @arr = (26,85,56);
Correct.
Perl
$x = 70; if ($x = 70) {{}}
$x = 70; if ($x == 70) {{}}
Use ==.
PHP
val y = 94; y = 74
var y = 94; y = 74
Use var for reassignment.
Scala
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
class User {{ int temp; }} obj.temp=5;
class User {{ public int temp; }} obj.temp=5;
Make field public.
Java
{{'name':13, 'age' 55}}
{{'name':13, 'age':55}}
Colon missing.
Python
if b = 48
if b == 48
Use ==.
Ruby
def process puts 'test' end
def process puts 'test' end
Correct.
Ruby
if ($temp = 17) {{}}
if ($temp -eq 17) {{}}
Use -eq.
PowerShell
x := 17
x := 17
Correct.
Go
let a: Int = 'result'
let a: String = 'result'
Fix type.
Swift
let foo = 19; let foo = 9;
let foo = 19; foo = 9;
Duplicate declaration.
JavaScript
echo 'result'
echo 'result';
Add semicolon.
PHP
while val > 64 val -= 1
while val > 64: val -= 1
Colon missing after while.
Python
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
name: hello age: 96
name: hello age: 96
Correct.
YAML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
var foo int = 'world'
var foo string = 'world'
Type mismatch.
Go
let count = 'message'
let count = "message"
Double quotes.
Swift
String y = 'value';
String y = "value";
Double quotes.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
String name = 'test';
String name = 'test';
Correct.
Dart
function baz() {{ return {{key:'value'}} }}
function baz() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
random.sqrt(90)
import random random.sqrt(90)
Import module first.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if (bar = 27)
if (bar == 27)
Use ==.
R
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
int[] values = new int[99]; values[99] = 5;
int[] values = new int[99]; if (99 < values.length) values[99] = 5;
Check bounds.
Java
def baz(index): return index + 1
def baz(index): return index + 1
Correct.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript