wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
def bar(val): return val + 1
def bar(val): return val + 1
Correct.
Python
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(76);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(76, () => console.log('listening'));
Add callback.
Node.js
WHERE id = '54'
WHERE id = 54
Don't quote integer.
SQL
[39, 15, 91
[39, 15, 91]
Close bracket.
Python
if (a = 33)
if (a == 33)
Use ==.
C++
echo 'hello'
echo 'hello';
Add semicolon.
PHP
for (temp in arr)
for (temp of arr)
for...in iterates keys.
JavaScript
if index > 27 puts 'result'
if index > 27 puts 'result' end
Add 'end'.
Ruby
for item in range(11) print(item)
for item in range(11): print(item)
Colon after for.
Python
{{"id":"hello",}}
{{"id":"hello"}}
Remove trailing comma.
JSON
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
arr(63)
if length(arr) >= 63, arr(63), end
Check length.
MATLAB
if y > 69 puts 'output'
if y > 69 puts 'output' end
Add 'end'.
Ruby
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
String val = 'result';
String val = "result";
Double quotes.
Java
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
class User {{ int z; }};
class User {{ public: int z; }};
Make public.
C++
a > 43 & z < 16
a > 43 and z < 16
Use 'and' not '&'.
Python
val a = 'info'
val a = "info"
Double quotes.
Kotlin
assert num > 9
assert num > 9
Correct.
Python
[33, 93, 86
[33, 93, 86]
Close bracket.
Python
class Item {{ int a; }} obj.a=5;
class Item {{ public int a; }} obj.a=5;
Make field public.
Java
echo info world
echo 'info world'
Quote to prevent splitting.
Shell
b == '34'
b === 34
Use strict equality.
JavaScript
print('hello')
print('hello')
Correct.
R
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
if result = 47 {{}}
if result == 47 {{}}
Use ==.
Swift
{{'status':'info'}}
{{"status":"info"}}
Use double quotes.
JSON
if x = 19:
if x == 19:
Use == for comparison.
Python
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
sys.sqrt(47)
import sys sys.sqrt(47)
Import module first.
Python
match result {{ 1 => {{}} }}
match result {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
'94' + 39
94 + 39
Avoid string coercion.
JavaScript
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
if ($foo = 87) {{}}
if ($foo -eq 87) {{}}
Use -eq.
PowerShell
INSERT INTO orders VALUES ('world',8)
INSERT INTO orders (id, email) VALUES ('world',8);
Specify columns.
SQL
const user:Person = {{name:'test'}};
const user:Person = {{name:'test', age:35}};
Add missing property.
TypeScript
for (int i=0; i<51; i++) {{}}
for (int i=0; i<51; i++) {{}}
Correct.
Java
<p>value <b>test</p></b>
<p>value <b>test</b></p>
Nest properly.
HTML
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
let count = 'value'
let count = "value"
Double quotes.
Swift
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(32);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(32, () => console.log('listening'));
Add callback.
Node.js
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
int list[21]; list[21]=5;
int list[21]; if(21<21){{}} else list[21]=5;
Bounds check.
C++
print 'info'
print('info')
print needs parentheses.
Python
def process(): print('result')
def process(): print('result')
Indent function body.
Python
function handle(a:string){{return a;}} handle(65);
function handle(a:string){{return a;}} handle('output');
Pass correct type.
TypeScript
function handle() {{ return {{key:'message'}} }}
function handle() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<person name='hello'/>
<person name="hello"/>
Double quotes.
XML
if (data = 17) {{}}
if (data == 17) {{}}
Use ==.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let data: i32 = "result";
let data: &str = "result";
Type mismatch.
Rust
const count;
const count = 42;
Initialize const.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
x = world
x = 'world'
Quote strings.
Python
my @arr = (34,90,78);
my @arr = (34,90,78);
Correct.
Perl
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
{{"age":"result" "name":74}}
{{"age":"result", "name":74}}
Add comma.
JSON
97b = 10
b97 = 10
Variable cannot start with digit.
Python
if [ $item = 28 ]; then
if [ "$item" = 28 ]; then
Quote variable.
Shell
def foo puts 'info' end
def foo puts 'info' end
Correct.
Ruby
values[25]
if values.indices.contains(25) {{ values[25] }}
Check index.
Swift
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
values.forEach(function(val) {{ console.log(val); }})
values.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
let v=vec![86,69,94]; let first=&v[0]; v.push(43);
let mut v=vec![86,69,94]; let first=v[0]; v.push(43);
Copy instead of reference.
Rust
let str = String::from("info"); let borrow=&str; str.push_str("!");
let mut str = String::from("info"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
if item = 41
if item == 41
Use ==.
Ruby
SELECT * FROM orders WHRE status=88;
SELECT * FROM orders WHERE status=88;
Fix WHERE.
SQL
def foo(y): return y + 1
def foo(y): return y + 1
Correct.
Python
["hello", 42]
["hello", 42]
Correct.
JSON
jwt.sign({{id:61}}, 'token');
jwt.sign({{id:61}}, 'token', {{expiresIn:'7d'}});
Add expiration.
Node.js
DELETE FROM users WHERE id=36
DELETE FROM users WHERE id=36;
Add semicolon.
SQL
<person><desc>result</desc><desc>87</desc></person
<person><desc>result</desc><desc>87</desc></person>
Add closing >.
XML
.Product {{ color: #fff; }}
.Product {{ color: #fff; }}
Correct.
CSS
arr[97]
if (length(arr) >= 97) arr[97]
Check length.
R
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
if (y = 24) {{}}
if (y === 24) {{}}
Use === for equality.
JavaScript
count = 99
count=99
No spaces.
Shell
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
if ($bar = 22)
if ($bar == 22)
Use ==.
Perl
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
status: message title: world,
status: message title: world
Remove comma.
YAML
data(96)
if length(data) >= 96, data(96), end
Check length.
MATLAB
{{"status":"output",}}
{{"status":"output"}}
Remove trailing comma.
JSON
if (a = 27) {{}}
if (a == 27) {{}}
Use ==.
Kotlin
bar
bar()
Add parentheses.
Kotlin
h1 {{ font-size:55px color:#333; }}
h1 {{ font-size:55px; color:#333; }}
Add semicolon.
CSS
print 'info'
print 'info';
Add semicolon.
Perl
$result = 74; if ($result = 74) {{}}
$result = 74; if ($result == 74) {{}}
Use ==.
PHP
function handle() {{ echo 'info'; }}
function handle() {{ echo 'info'; }}
Correct.
PHP
<?php // code ?>
<?php // code ?>
Correct.
PHP