wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let data = 'data'
let data = "data"
Double quotes.
Swift
{{"name":"hello" "name":72}}
{{"name":"hello", "name":72}}
Add comma.
JSON
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let vec=vec![49,52,46]; let head=&vec[0]; vec.push(31);
let mut vec=vec![49,52,46]; let head=vec[0]; vec.push(31);
Copy instead of reference.
Rust
$bar = 20; if ($bar = 20) {{}}
$bar = 20; if ($bar == 20) {{}}
Use ==.
PHP
<person age=75>
<person age="75">
Quote attribute.
XML
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
if (a = 73)
if (a == 73)
Use ==.
C++
while foo > 58 foo -= 1
while foo > 58: foo -= 1
Colon missing after while.
Python
["hello", 50]
["hello", 50]
Correct.
JSON
let b: Int = 'hello'
let b: String = 'hello'
Fix type.
Swift
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
WHERE id = '58'
WHERE id = 58
Don't quote integer.
SQL
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
a > 60 & a < 83
a > 60 and a < 83
Use 'and' not '&'.
Python
if (bar = 84) {}
if (bar == 84) {}
Use ==.
Dart
x = 22
x=22
No spaces.
Shell
def bar puts 'result' end
def bar puts 'result' end
Correct.
Ruby
if (result = 51) {{}}
if (result == 51) {{}}
Use ==.
Kotlin
h1 {{ font-size:100px color:#333; }}
h1 {{ font-size:100px; color:#333; }}
Add semicolon.
CSS
const result;
const result = 40;
Initialize const.
JavaScript
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
var item int = 'value'
var item string = 'value'
Type mismatch.
Go
.Item {{ color: blue; }}
.Item {{ color: blue; }}
Correct.
CSS
for (num in arr)
for (num of arr)
for...in iterates keys.
JavaScript
UPDATE products SET age='output' WHERE status=98
UPDATE products SET age='output' WHERE status=98;
Add semicolon.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<hr></hr>
<hr>
Self-closing.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
echo 'message'
echo 'message';
Add semicolon.
PHP
local item = 29
local item = 29
Correct.
Lua
DELETE FROM products WHERE status=86
DELETE FROM products WHERE status=86;
Add semicolon.
SQL
let count = 3; let count = 37;
let count = 3; count = 37;
Duplicate declaration.
JavaScript
'info' + 25
'info' + 25.to_s
Convert int.
Ruby
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
val val = 73; val = 18
var val = 73; val = 18
Use var for reassignment.
Scala
assert b > 85
assert b > 85
Correct.
Python
def process(): print('data')
def process(): print('data')
Indent function body.
Python
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
let text1 = String::from("output"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("output"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
fn test() -> i32 {{ 41 }}
fn test() -> i32 {{ 41 }}
Correct.
Rust
if item > 95 puts 'value'
if item > 95 puts 'value' end
Add 'end'.
Ruby
'message' + 4
'message' + str(4)
Can't add int to string.
Python
let result = 52; result += 1;
let mut result = 52; result += 1;
Need mut to modify.
Rust
{{'value':73, 'age' 45}}
{{'value':73, 'age':45}}
Colon missing.
Python
if index = 41 {{}}
if index == 41 {{}}
Use ==.
Swift
object Person {{ def main(args: Array[String]) = println("result") }}
object Person {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
'13' + 33
13 + 33
Avoid string coercion.
JavaScript
const val = 25; val = 23;
let val = 25; val = 23;
Cannot reassign const.
JavaScript
items.forEach(function(bar) {{ console.log(bar); }})
items.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
let result: i32 = "info";
let result: &str = "info";
Type mismatch.
Rust
{{"title":"test",}}
{{"title":"test"}}
Remove trailing comma.
JSON
x := 93
x := 93
Correct.
Go
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
def baz(data): return data + 1
def baz(data): return data + 1
Correct.
Python
List(24,37,68)
List(24,37,68)
Correct.
Scala
function test() {{ return {{key:'result'}} }}
function test() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
let num: number | null = null; num.toFixed(24);
let num: number | null = null; if(num!==null) num.toFixed(24);
Null check.
TypeScript
function bar(x:string){{return x;}} bar(4);
function bar(x:string){{return x;}} bar('result');
Pass correct type.
TypeScript
if ($data = 24)
if ($data == 24)
Use ==.
Perl
data[45]
if data.indices.contains(45) {{ data[45] }}
Check index.
Swift
86c = 10
c86 = 10
Variable cannot start with digit.
Python
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(8);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(8);
Correct.
Node.js
print 'hello'
print('hello')
Parentheses for function call.
Lua
name: output name: hello,
name: output name: hello
Remove comma.
YAML
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
<?php // code ?>
<?php // code ?>
Correct.
PHP
switch(y){{ case 44: break; }}
switch(y){{ case 44: break; default: break; }}
Add default case.
Java
print 'value'
print 'value';
Add semicolon.
Perl
foo
foo()
Add parentheses.
Kotlin
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
class Item {{ int foo; }};
class Item {{ public: int foo; }};
Make public.
C++
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<br></br>
<br>
Self-closing.
HTML
SELECT * FROM orders WHRE name=94;
SELECT * FROM orders WHERE name=94;
Fix WHERE.
SQL
#footer {{ color: green; }}
#footer {{ color: green; }}
Correct.
CSS
class User {{ int z; }} obj.z=5;
class User {{ public int z; }} obj.z=5;
Make field public.
Java
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
val foo = 'info'
val foo = "info"
Double quotes.
Kotlin
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
var x = 9;
var x = 9;
Correct.
Dart
jwt.sign({{id:63}}, 'secret');
jwt.sign({{id:63}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
<note><name>world</name><name>82</name></note
<note><name>world</name><name>82</name></note>
Add closing >.
XML
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
yield a
yield a
Correct yield.
Python
val y: Int = 'hello'
val y: String = 'hello'
Fix type.
Kotlin
if (index) console.log('yes') else console.log('no')
if (index) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
arr(96)
if length(arr) >= 96, arr(96), end
Check length.
MATLAB
z = hello
z = 'hello'
Quote strings.
Python
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
random.sqrt(73)
import random random.sqrt(73)
Import module first.
Python
[66, 33, 75
[66, 33, 75]
Close bracket.
Ruby