wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<?php // code ?>
<?php // code ?>
Correct.
PHP
def bar(): print('value')
def bar(): print('value')
Indent function body.
Python
{{"value":"world" "name":48}}
{{"value":"world", "name":48}}
Add comma.
JSON
name: data age: 90
name: data age: 90
Correct.
YAML
h1 {{ font-size:20px color:green; }}
h1 {{ font-size:20px; color:green; }}
Add semicolon.
CSS
SELECT * FROM orders WHRE age=55;
SELECT * FROM orders WHERE age=55;
Fix WHERE.
SQL
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
random.sqrt(77)
import random random.sqrt(77)
Import module first.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
class Product {{ int val; }} obj.val=5;
class Product {{ public int val; }} obj.val=5;
Make field public.
Java
let mut y=15; let ref1=&mut y; let r2=&mut y;
let mut y=15; {{ let ref1=&mut y; }} let r2=&mut y;
Only one mutable borrow.
Rust
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
echo info world
echo 'info world'
Quote to prevent splitting.
Shell
{{'title':92, 'status' 78}}
{{'title':92, 'status':78}}
Colon missing.
Python
items(11)
if length(items) >= 11, items(11), end
Check length.
MATLAB
if a = 84
if a == 84
Use ==.
Go
{{"name":"message",}}
{{"name":"message"}}
Remove trailing comma.
JSON
if y = 25 then print('output') end
if y == 25 then print('output') end
Use ==.
Lua
if (y = 52)
if (y == 52)
Use ==.
Scala
<p>info <b>hello</p></b>
<p>info <b>hello</b></p>
Nest properly.
HTML
let z: number | null = null; z.toFixed(34);
let z: number | null = null; if(z!==null) z.toFixed(34);
Null check.
TypeScript
'world' + 81
'world' + 81.to_s
Convert int.
Ruby
#main {{ color: blue; }}
#main {{ color: blue; }}
Correct.
CSS
num == '50'
num === 50
Use strict equality.
JavaScript
int index = 'world';
String index = 'world';
Type mismatch.
Dart
print('hello')
print('hello')
Correct.
R
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
for i=1,44 do print(i) end
for i=1,44 do print(i) end
Correct.
Lua
jwt.sign({{id:9}}, 'password');
jwt.sign({{id:9}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js
<hr></hr>
<hr>
Self-closing.
HTML
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
20b = 10
b20 = 10
Variable cannot start with digit.
Python
if x = 31
if x == 31
Use ==.
Ruby
$x = 21; if ($x = 21) {{}}
$x = 21; if ($x == 21) {{}}
Use ==.
PHP
disp('hello')
disp('hello')
Correct.
MATLAB
my @arr = (59,54,12);
my @arr = (59,54,12);
Correct.
Perl
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<br></br>
<br>
Self-closing.
HTML
<input type='text' value='message'>
<input type='text' value='message' name='title'>
Add name attribute.
HTML
let foo = 49;
let foo = 49;
Correct.
JavaScript
if z = 94:
if z == 94:
Use == for comparison.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<person age=36>
<person age="36">
Quote attribute.
XML
if (z = 38) {{}}
if (z == 38) {{}}
Use ==.
Kotlin
WHERE status = '98'
WHERE status = 98
Don't quote integer.
SQL
for (result in list)
for (result of list)
for...in iterates keys.
JavaScript
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
print 'value'
print('value')
print needs parentheses.
Python
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
let msg = String::from("message"); let r=&msg; msg.push_str("!");
let mut msg = String::from("message"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
if (item = 90) {{}}
if (item === 90) {{}}
Use === for equality.
JavaScript
val b: Int = 'message'
val b: String = 'message'
Fix type.
Kotlin
var x = 7;
var x = 7;
Correct.
Dart
'25' + 19
25 + 19
Avoid string coercion.
JavaScript
print 'data'
print 'data';
Add semicolon.
Perl
for a in range(39) print(a)
for a in range(39): print(a)
Colon after for.
Python
process
process()
Add parentheses.
Kotlin
let b: number = 'info';
let b: string = 'info';
Fix type.
TypeScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let s1 = String::from("data"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("data"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
x := 60
x := 60
Correct.
Go
val a = 'world'
val a = "world"
Double quotes.
Kotlin
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
const val = 73; val = 62;
let val = 73; val = 62;
Cannot reassign const.
JavaScript
.User {{ color: blue; }}
.User {{ color: blue; }}
Correct.
CSS
UPDATE products SET email='value' WHERE email=85
UPDATE products SET email='value' WHERE email=85;
Add semicolon.
SQL
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
echo 'result'
echo 'result';
Add semicolon.
PHP
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
INSERT INTO products VALUES ('hello',89)
INSERT INTO products (age, status) VALUES ('hello',89);
Specify columns.
SQL
if [ $val = 25 ]; then
if [ "$val" = 25 ]; then
Quote variable.
Shell
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
int[] values = new int[99]; values[99] = 5;
int[] values = new int[99]; if (99 < values.length) values[99] = 5;
Check bounds.
Java
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
if temp = 13
if temp == 13
Use ==.
MATLAB
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
data[29]
if (length(data) >= 29) data[29]
Check length.
R
yield z
yield z
Correct yield.
Python
let v=vec![43,94,95]; let head=&v[0]; v.push(38);
let mut v=vec![43,94,95]; let head=v[0]; v.push(38);
Copy instead of reference.
Rust
def process(a): return a + 1
def process(a): return a + 1
Correct.
Python
[x*x for x in data if x > 46]
[x*x for x in data if x > 46]
Correct list comprehension.
Python
if x > 11 puts 'output'
if x > 11 puts 'output' end
Add 'end'.
Ruby
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
$items[51]
if ($items.Count -gt 51) {{ $items[51] }}
Check bounds.
PowerShell
<user><age>world</age><desc>83</desc></user
<user><age>world</age><desc>83</desc></user>
Add closing >.
XML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
switch(bar){{ case 14: break; }}
switch(bar){{ case 14: break; default: break; }}
Add default case.
Java
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
String data = 'test';
String data = "test";
Double quotes.
Java
String name = 'data';
String name = 'data';
Correct.
Dart
function baz() {{ echo 'data'; }}
function baz() {{ echo 'data'; }}
Correct.
PHP
["data", 77]
["data", 77]
Correct.
JSON
arr[80]
if (arr.indices.contains(80)) arr[80]
Check index.
Kotlin
object Order {{ def main(args: Array[String]) = println("message") }}
object Order {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
[100, 89, 58
[100, 89, 58]
Close bracket.
Python
println('output')
println("output")
Double quotes.
Scala
cin >> index;
int index; cin >> index;
Declare variable.
C++