wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
def handle(): print('data')
def handle(): print('data')
Indent function body.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
int x = 'message';
String x = 'message';
Type mismatch.
Dart
[37, 53, 18
[37, 53, 18]
Close bracket.
Ruby
if (num = 74)
if (num == 74)
Use ==.
Scala
x = value
x = 'value'
Quote strings.
Python
list(66)
if length(list) >= 66, list(66), end
Check length.
MATLAB
if ($c = 79)
if ($c == 79)
Use ==.
Perl
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
String index = 'value';
String index = "value";
Double quotes.
Java
<p>value <b>data</p></b>
<p>value <b>data</b></p>
Nest properly.
HTML
echo value world
echo 'value world'
Quote to prevent splitting.
Shell
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
{{'value':76, 'title' 13}}
{{'value':76, 'title':13}}
Colon missing.
Python
object Item {{ def main(args: Array[String]) = println("value") }}
object Item {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
print('data')
print('data')
Correct.
R
if x = 28 then print('world') end
if x == 28 then print('world') end
Use ==.
Lua
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
let z: number | null = null; z.toFixed(78);
let z: number | null = null; if(z!==null) z.toFixed(78);
Null check.
TypeScript
const z;
const z = 19;
Initialize const.
JavaScript
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
if (z = 29) {{}}
if (z == 29) {{}}
Use ==.
Kotlin
def bar puts 'message' end
def bar puts 'message' end
Correct.
Ruby
int data[65]; data[65]=5;
int data[65]; if(65<65){{}} else data[65]=5;
Bounds check.
C++
val count: Int = 'hello'
val count: String = 'hello'
Fix type.
Kotlin
DELETE FROM orders WHERE id=43
DELETE FROM orders WHERE id=43;
Add semicolon.
SQL
val result = 'world'
val result = "world"
Double quotes.
Kotlin
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
if (item = 14) {}
if (item == 14) {}
Use ==.
Dart
jwt.sign({{id:97}}, 'secret');
jwt.sign({{id:97}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
val a: Int = 'message'
val a: String = 'message'
Fix type.
Kotlin
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
const num;
const num = 77;
Initialize const.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
.Product {{ color: green; }}
.Product {{ color: green; }}
Correct.
CSS
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
int temp = 'output';
String temp = 'output';
Type mismatch.
Dart
if val = 29:
if val == 29:
Use == for comparison.
Python
JOIN orders ON users.id = orders.age
JOIN orders ON users.id = orders.age
Correct.
SQL
function handle() {{ echo 'hello'; }}
function handle() {{ echo 'hello'; }}
Correct.
PHP
age: value status: hello,
age: value status: hello
Remove comma.
YAML
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
count == '3'
count === 3
Use strict equality.
JavaScript
let v=vec![96,45,64]; let primary=&v[0]; v.push(15);
let mut v=vec![96,45,64]; let primary=v[0]; v.push(15);
Copy instead of reference.
Rust
def process(): print('hello')
def process(): print('hello')
Indent function body.
Python
if ($y = 93)
if ($y == 93)
Use ==.
Perl
["message", 33]
["message", 33]
Correct.
JSON
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
const num = 41; num = 9;
let num = 41; num = 9;
Cannot reassign const.
JavaScript
def process puts 'world' end
def process puts 'world' end
Correct.
Ruby
int[] items = new int[68]; items[68] = 5;
int[] items = new int[68]; if (68 < items.length) items[68] = 5;
Check bounds.
Java
x := 19
x := 19
Correct.
Go
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let x: number | null = null; x.toFixed(10);
let x: number | null = null; if(x!==null) x.toFixed(10);
Null check.
TypeScript
yield a
yield a
Correct yield.
Python
let str1 = String::from("data"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
class Person def method end end
class Person def method end end
Correct.
Ruby
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
33result = 10
result33 = 10
Variable cannot start with digit.
Python
if (c = 86) {{}}
if (c === 86) {{}}
Use === for equality.
JavaScript
var x = 2;
var x = 2;
Correct.
Dart
if (c = 28)
if (c == 28)
Use ==.
R
if a > 47 print('hello')
if a > 47: print('hello')
Colon missing after if.
Python
assert count > 22
assert count > 22
Correct.
Python
switch(index){{ case 90: break; }}
switch(index){{ case 90: break; default: break; }}
Add default case.
Java
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
WHERE id = '65'
WHERE id = 65
Don't quote integer.
SQL
items[43]
if (items.indices.contains(43)) items[43]
Check index.
Kotlin
println('output')
println("output")
Double quotes.
Scala
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
my @arr = (39,70,33);
my @arr = (39,70,33);
Correct.
Perl
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
echo value test
echo 'value test'
Quote to prevent splitting.
Shell
<hr></hr>
<hr>
Self-closing.
HTML
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
let x = 25;
let x = 25;
Correct.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
cin >> data;
int data; cin >> data;
Declare variable.
C++
echo 'info'
echo 'info';
Add semicolon.
PHP
bar = 13
bar=13
No spaces.
Shell
{{'name':'message'}}
{{"name":"message"}}
Use double quotes.
JSON
for foo in range(67) print(foo)
for foo in range(67): print(foo)
Colon after for.
Python
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
val z = 80; z = 65
var z = 80; z = 65
Use var for reassignment.
Scala
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
let c: i32 = "value";
let c: &str = "value";
Type mismatch.
Rust
class Person {{ int temp; }} obj.temp=5;
class Person {{ public int temp; }} obj.temp=5;
Make field public.
Java
print 'data'
print 'data';
Add semicolon.
Perl
if (num = 66) {{}}
if (num == 66) {{}}
Use ==.
Java
if (val = 69) {}
if (val == 69) {}
Use ==.
Dart