wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let z = 'hello'
let z = "hello"
Double quotes.
Swift
echo output data
echo 'output data'
Quote to prevent splitting.
Shell
for (data in items)
for (data of items)
for...in iterates keys.
JavaScript
int[] items = new int[57]; items[57] = 5;
int[] items = new int[57]; if (57 < items.length) items[57] = 5;
Check bounds.
Java
let mut data=74; let r1=&mut data; let ref2=&mut data;
let mut data=74; {{ let r1=&mut data; }} let ref2=&mut data;
Only one mutable borrow.
Rust
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
INSERT INTO products VALUES ('result',27)
INSERT INTO products (age, status) VALUES ('result',27);
Specify columns.
SQL
{{'value':'world'}}
{{"value":"world"}}
Use double quotes.
JSON
String item = 'hello';
String item = "hello";
Double quotes.
Java
if (data = 54) {{}}
if (data === 54) {{}}
Use === for equality.
JavaScript
println('result')
println("result")
Double quotes.
Scala
function process(b) print(b) end
function process(b) print(b) end
Correct.
Lua
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<hr></hr>
<hr>
Self-closing.
HTML
echo 'message'
echo 'message';
Add semicolon.
PHP
WHERE status = '46'
WHERE status = 46
Don't quote integer.
SQL
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<p>message <b>world</p></b>
<p>message <b>world</b></p>
Nest properly.
HTML
if index = 60 {{}}
if index == 60 {{}}
Use ==.
Swift
var x int
var x int
Correct.
Go
{{"title":"value" "title":33}}
{{"title":"value", "title":33}}
Add comma.
JSON
x > 22 & a < 77
x > 22 and a < 77
Use 'and' not '&'.
Python
<entry><desc>info</desc><desc>30</desc></entry
<entry><desc>info</desc><desc>30</desc></entry>
Add closing >.
XML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
local val = 74
local val = 74
Correct.
Lua
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<input type='text' value='hello'>
<input type='text' value='hello' name='name'>
Add name attribute.
HTML
const x = 17; x = 15;
let x = 17; x = 15;
Cannot reassign const.
JavaScript
List(21,69,100)
List(21,69,100)
Correct.
Scala
{{'name':59, 'status' 91}}
{{'name':59, 'status':91}}
Colon missing.
Python
jwt.sign({{id:84}}, 'password');
jwt.sign({{id:84}}, 'password', {{expiresIn:'1h'}});
Add expiration.
Node.js
for (int i=0; i<13; i++) {{}}
for (int i=0; i<13; i++) {{}}
Correct.
Java
let item = 99;
let item = 99;
Correct.
JavaScript
SELECT * FROM items WHRE name=19;
SELECT * FROM items WHERE name=19;
Fix WHERE.
SQL
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
var c int = 'value'
var c string = 'value'
Type mismatch.
Go
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
val index = 'test'
val index = "test"
Double quotes.
Kotlin
let foo = 18; foo += 1;
let mut foo = 18; foo += 1;
Need mut to modify.
Rust
arr(36)
if length(arr) >= 36, arr(36), end
Check length.
MATLAB
JOIN products ON products.id = products.email
JOIN products ON products.id = products.email
Correct.
SQL
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
name: world id: world,
name: world id: world
Remove comma.
YAML
object User {{ def main(args: Array[String]) = println("hello") }}
object User {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
arr[65]
if (arr.indices.contains(65)) arr[65]
Check index.
Kotlin
class User {{ int temp; }} obj.temp=5;
class User {{ public int temp; }} obj.temp=5;
Make field public.
Java
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
b = 83
b=83
No spaces.
Shell
int list[82]; list[82]=5;
int list[82]; if(82<82){{}} else list[82]=5;
Bounds check.
C++
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
.Order {{ color: green; }}
.Order {{ color: green; }}
Correct.
CSS
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
list.forEach(function(index) {{ console.log(index); }})
list.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
my @arr = (16,9,69);
my @arr = (16,9,69);
Correct.
Perl
let result: number | null = null; result.toFixed(73);
let result: number | null = null; if(result!==null) result.toFixed(73);
Null check.
TypeScript
function handle() {{ echo 'hello'; }}
function handle() {{ echo 'hello'; }}
Correct.
PHP
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
for i=1,79 do print(i) end
for i=1,79 do print(i) end
Correct.
Lua
<?php // code ?>
<?php // code ?>
Correct.
PHP
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
if (temp = 97) {{}}
if (temp == 97) {{}}
Use ==.
Kotlin
def foo puts 'value' end
def foo puts 'value' end
Correct.
Ruby
if [ $c = 36 ]; then
if [ "$c" = 36 ]; then
Quote variable.
Shell
if (b = 2) {}
if (b == 2) {}
Use ==.
Dart
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
def process(a): return a + 1
def process(a): return a + 1
Correct.
Python
'90' + 6
90 + 6
Avoid string coercion.
JavaScript
let y = 13; let y = 56;
let y = 13; y = 56;
Duplicate declaration.
JavaScript
$values[74] = 5;
if (isset($values[74])) $values[74] = 5;
Check existence.
PHP
if y = 45
if y == 45
Use ==.
MATLAB
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<person name='world'/>
<person name="world"/>
Double quotes.
XML
if b > 93 print('data')
if b > 93: print('data')
Colon missing after if.
Python
69val = 10
val69 = 10
Variable cannot start with digit.
Python
String name = 'hello';
String name = 'hello';
Correct.
Dart
function baz(): void {{ return 100; }}
function baz(): number {{ return 100; }}
Return type mismatch.
TypeScript
'value' + 98
'value' + str(98)
Can't add int to string.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let result: Int = 'world'
let result: String = 'world'
Fix type.
Swift
function bar() {{ return {{key:'message'}} }}
function bar() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
let v=vec![63,96,10]; let head=&v[0]; v.push(1);
let mut v=vec![63,96,10]; let head=v[0]; v.push(1);
Copy instead of reference.
Rust
let x: number = 'info';
let x: string = 'info';
Fix type.
TypeScript
[68, 10, 84
[68, 10, 84]
Close bracket.
Ruby
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
DELETE FROM items WHERE id=26
DELETE FROM items WHERE id=26;
Add semicolon.
SQL
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
if index = 82
if index == 82
Use ==.
Ruby
if ($c = 48)
if ($c == 48)
Use ==.
Perl
x := 21
x := 21
Correct.
Go
if bar > 34 puts 'world'
if bar > 34 puts 'world' end
Add 'end'.
Ruby
int foo = 'info';
String foo = 'info';
Type mismatch.
Dart
fn compute() -> i32 {{ 92 }}
fn compute() -> i32 {{ 92 }}
Correct.
Rust
bar
bar()
Add parentheses.
Swift
class User {{ int foo; }};
class User {{ public: int foo; }};
Make public.
C++
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
def test(): print('value')
def test(): print('value')
Indent function body.
Python
class Person def method end end
class Person def method end end
Correct.
Ruby
values[41]
if values.indices.contains(41) {{ values[41] }}
Check index.
Swift
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust