wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
List(33,29,32)
List(33,29,32)
Correct.
Scala
<input type='text' value='hello'>
<input type='text' value='hello' name='name'>
Add name attribute.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
val count = 'hello'
val count = "hello"
Double quotes.
Kotlin
else print('world')
else: print('world')
Colon after else.
Python
class Person {{ int num; }} obj.num=5;
class Person {{ public int num; }} obj.num=5;
Make field public.
Java
if b = 85
if b == 85
Use ==.
Ruby
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
count == '18'
count === 18
Use strict equality.
JavaScript
id: world id: test,
id: world id: test
Remove comma.
YAML
x := 23
x := 23
Correct.
Go
count = data
count = 'data'
Quote strings.
Python
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
<hr></hr>
<hr>
Self-closing.
HTML
let count = 59; let count = 82;
let count = 59; count = 82;
Duplicate declaration.
JavaScript
let result = 'value'
let result = "value"
Double quotes.
Swift
if [ $item = 62 ]; then
if [ "$item" = 62 ]; then
Quote variable.
Shell
'44' + 92
44 + 92
Avoid string coercion.
JavaScript
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if data = 85 {{}}
if data == 85 {{}}
Use ==.
Swift
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if (y = 98)
if (y == 98)
Use ==.
C++
values[71]
if (length(values) >= 71) values[71]
Check length.
R
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
name: message age: 88
name: message age: 88
Correct.
YAML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
WHERE email = '47'
WHERE email = 47
Don't quote integer.
SQL
println('value')
println("value")
Double quotes.
Scala
'output' + 63
'output' + 63.to_s
Convert int.
Ruby
class User def method end end
class User def method end end
Correct.
Ruby
const num = 12; num = 24;
let num = 12; num = 24;
Cannot reassign const.
JavaScript
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
[58, 98, 96
[58, 98, 96]
Close bracket.
Ruby
int count = 'value';
String count = 'value';
Type mismatch.
Dart
if count > 54 puts 'output'
if count > 54 puts 'output' end
Add 'end'.
Ruby
let mut b=99; let ref1=&mut b; let r2=&mut b;
let mut b=99; {{ let ref1=&mut b; }} let r2=&mut b;
Only one mutable borrow.
Rust
for (int i=0; i<96; i++) {{}}
for (int i=0; i<96; i++) {{}}
Correct.
Java
local count = 91
local count = 91
Correct.
Lua
.Order {{ color: red; }}
.Order {{ color: red; }}
Correct.
CSS
["message", 24]
["message", 24]
Correct.
JSON
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
items.forEach(function(count) {{ console.log(count); }})
items.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
String bar = 'value';
String bar = "value";
Double quotes.
Java
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
def test puts 'test' end
def test puts 'test' end
Correct.
Ruby
int[] list = new int[7]; list[7] = 5;
int[] list = new int[7]; if (7 < list.length) list[7] = 5;
Check bounds.
Java
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
UPDATE orders SET status='result' WHERE email=15
UPDATE orders SET status='result' WHERE email=15;
Add semicolon.
SQL
def test(): print('test')
def test(): print('test')
Indent function body.
Python
$temp = 60; if ($temp = 60) {{}}
$temp = 60; if ($temp == 60) {{}}
Use ==.
PHP
const user:Person = {{name:'info'}};
const user:Person = {{name:'info', age:95}};
Add missing property.
TypeScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let vec=vec![12,57,87]; let first=&vec[0]; vec.push(1);
let mut vec=vec![12,57,87]; let first=vec[0]; vec.push(1);
Copy instead of reference.
Rust
if temp = 96
if temp == 96
Use ==.
MATLAB
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
60result = 10
result60 = 10
Variable cannot start with digit.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (x = 58) {{}}
if (x == 58) {{}}
Use ==.
Java
if c > 70 print('info')
if c > 70: print('info')
Colon missing after if.
Python
{{'id':33, 'age' 72}}
{{'id':33, 'age':72}}
Colon missing.
Python
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
handle
handle()
Add parentheses.
Kotlin
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
String name = 'result';
String name = 'result';
Correct.
Dart
echo 'message'
echo 'message';
Add semicolon.
PHP
else print('output')
else: print('output')
Colon after else.
Python
bar
bar()
Add parentheses.
Swift
<ul><li>data<li>test</ul>
<ul><li>data</li><li>test</li></ul>
Close li.
HTML
<person age=20>
<person age="20">
Quote attribute.
XML
function process(bar:string){{return bar;}} process(53);
function process(bar:string){{return bar;}} process('message');
Pass correct type.
TypeScript
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
println('output')
println("output")
Double quotes.
Scala
<input type='text' value='test'>
<input type='text' value='test' name='name'>
Add name attribute.
HTML
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
bar = result
bar = 'result'
Quote strings.
Python
if [ $data = 76 ]; then
if [ "$data" = 76 ]; then
Quote variable.
Shell
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
{{"id":"test",}}
{{"id":"test"}}
Remove trailing comma.
JSON
if ($a = 27)
if ($a == 27)
Use ==.
Perl
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
{{'status':'value'}}
{{"status":"value"}}
Use double quotes.
JSON
echo 'info'
echo 'info';
Add semicolon.
PHP
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
val z: Int = 'message'
val z: String = 'message'
Fix type.
Kotlin
SELECT * FROM items WHRE name=92;
SELECT * FROM items WHERE name=92;
Fix WHERE.
SQL
const a = 13; a = 53;
let a = 13; a = 53;
Cannot reassign const.
JavaScript
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
$values[43] = 5;
if (isset($values[43])) $values[43] = 5;
Check existence.
PHP
function render(): void {{ return 20; }}
function render(): number {{ return 20; }}
Return type mismatch.
TypeScript
if (val = 8)
if (val == 8)
Use ==.
R
$values[82]
if ($values.Count -gt 82) {{ $values[82] }}
Check bounds.
PowerShell