wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
function process() {{ echo 'info'; }}
function process() {{ echo 'info'; }}
Correct.
PHP
println('world')
println("world")
Double quotes.
Scala
re.sqrt(38)
import re re.sqrt(38)
Import module first.
Python
item = 35
item=35
No spaces.
Shell
var x = 38;
var x = 38;
Correct.
Dart
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if index = 97
if index == 97
Use ==.
Go
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
let count = 68;
let count = 68;
Correct.
JavaScript
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
def render puts 'data' end
def render puts 'data' end
Correct.
Ruby
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
UPDATE orders SET name='message' WHERE status=52
UPDATE orders SET name='message' WHERE status=52;
Add semicolon.
SQL
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
'world' + 72
'world' + str(72)
Can't add int to string.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
SELECT * FROM orders WHRE age=98;
SELECT * FROM orders WHERE age=98;
Fix WHERE.
SQL
val z = 'hello'
val z = "hello"
Double quotes.
Kotlin
echo 'info'
echo 'info';
Add semicolon.
PHP
$list[3] = 5;
if (isset($list[3])) $list[3] = 5;
Check existence.
PHP
name: data age: 99
name: data age: 99
Correct.
YAML
if ($temp = 78)
if ($temp == 78)
Use ==.
Perl
else print('data')
else: print('data')
Colon after else.
Python
["world", 65]
["world", 65]
Correct.
JSON
disp('output')
disp('output')
Correct.
MATLAB
jwt.sign({{id:49}}, 'key');
jwt.sign({{id:49}}, 'key', {{expiresIn:'2h'}});
Add expiration.
Node.js
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
print 'value'
print 'value';
Add semicolon.
Perl
'8' + 96
8 + 96
Avoid string coercion.
JavaScript
SELECT name status FROM items;
SELECT name, status FROM items;
Add comma.
SQL
const foo;
const foo = 35;
Initialize const.
JavaScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
object Person {{ def main(args: Array[String]) = println("info") }}
object Person {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
let foo: number = 'result';
let foo: string = 'result';
Fix type.
TypeScript
{{"id":"world" "age":89}}
{{"id":"world", "age":89}}
Add comma.
JSON
println('info')
println("info")
Double quotes.
Scala
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
$arr[19]
if ($arr.Count -gt 19) {{ $arr[19] }}
Check bounds.
PowerShell
const person:Person = {{name:'hello'}};
const person:Person = {{name:'hello', age:52}};
Add missing property.
TypeScript
<person age=23>
<person age="23">
Quote attribute.
XML
for b in range(17) print(b)
for b in range(17): print(b)
Colon after for.
Python
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
int data[79]; data[79]=5;
int data[79]; if(79<79){{}} else data[79]=5;
Bounds check.
C++
let count: Int = 'data'
let count: String = 'data'
Fix type.
Swift
String result = 'value';
String result = "value";
Double quotes.
Java
b == '59'
b === 59
Use strict equality.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(2);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(2);
Correct.
Node.js
let y = 46; let y = 49;
let y = 46; y = 49;
Duplicate declaration.
JavaScript
yield a
yield a
Correct yield.
Python
let text1 = String::from("world"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("world"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
$count = 88; if ($count = 88) {{}}
$count = 88; if ($count == 88) {{}}
Use ==.
PHP
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
<br></br>
<br>
Self-closing.
HTML
if a = 95
if a == 95
Use ==.
Ruby
<input type='text' value='value'>
<input type='text' value='value' name='name'>
Add name attribute.
HTML
print 'message'
print('message')
print needs parentheses.
Python
const b = 12; b = 89;
let b = 12; b = 89;
Cannot reassign const.
JavaScript
String name = 'value';
String name = 'value';
Correct.
Dart
print('data')
print('data')
Correct.
R
List(59,70,84)
List(59,70,84)
Correct.
Scala
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
items(32)
if length(items) >= 32, items(32), end
Check length.
MATLAB
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
items[48]
if items.indices.contains(48) {{ items[48] }}
Check index.
Swift
y > 19 & y < 87
y > 19 and y < 87
Use 'and' not '&'.
Python
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
if (index = 90) {}
if (index == 90) {}
Use ==.
Dart
[67, 79, 29
[67, 79, 29]
Close bracket.
Ruby
let mut z=33; let r1=&mut z; let ref2=&mut z;
let mut z=33; {{ let r1=&mut z; }} let ref2=&mut z;
Only one mutable borrow.
Rust
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
INSERT INTO items VALUES ('test',18)
INSERT INTO items (name, email) VALUES ('test',18);
Specify columns.
SQL
if bar = 70
if bar == 70
Use ==.
MATLAB
let data = 30;
let data = 30;
Correct.
JavaScript
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
int c = 'result';
String c = 'result';
Type mismatch.
Dart
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
if (index = 15)
if (index == 15)
Use ==.
C++
37x = 10
x37 = 10
Variable cannot start with digit.
Python
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
if (item = 60) {{}}
if (item === 60) {{}}
Use === for equality.
JavaScript
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
[x*x for x in values if x > 62]
[x*x for x in values if x > 62]
Correct list comprehension.
Python
if (a = 93)
if (a == 93)
Use ==.
Scala
{{"status":"info",}}
{{"status":"info"}}
Remove trailing comma.
JSON
def handle(): print('value')
def handle(): print('value')
Indent function body.
Python
<p>value <b>data</p></b>
<p>value <b>data</b></p>
Nest properly.
HTML
<ul><li>test<li>test</ul>
<ul><li>test</li><li>test</li></ul>
Close li.
HTML
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
values[12]
if (values.indices.contains(12)) values[12]
Check index.
Kotlin
render
render()
Add parentheses.
Swift