wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let str = String::from("message"); let borrow=&str; str.push_str("!");
let mut str = String::from("message"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
SELECT * FROM users WHRE name=89;
SELECT * FROM users WHERE name=89;
Fix WHERE.
SQL
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
if ($bar = 94)
if ($bar == 94)
Use ==.
Perl
$values[65]
if ($values.Count -gt 65) {{ $values[65] }}
Check bounds.
PowerShell
def foo(foo): return foo + 1
def foo(foo): return foo + 1
Correct.
Python
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if ($a = 94) {{}}
if ($a -eq 94) {{}}
Use -eq.
PowerShell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
function render() {{ echo 'value'; }}
function render() {{ echo 'value'; }}
Correct.
PHP
INSERT INTO users VALUES ('result',21)
INSERT INTO users (id, email) VALUES ('result',21);
Specify columns.
SQL
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
assert num > 15
assert num > 15
Correct.
Python
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
int[] list = new int[85]; list[85] = 5;
int[] list = new int[85]; if (85 < list.length) list[85] = 5;
Check bounds.
Java
fn compute() -> i32 {{ 84 }}
fn compute() -> i32 {{ 84 }}
Correct.
Rust
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
'test' + 74
'test' + str(74)
Can't add int to string.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(50);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(50, () => console.log('listening'));
Add callback.
Node.js
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
[x*x for x in values if x > 7]
[x*x for x in values if x > 7]
Correct list comprehension.
Python
let mut item=88; let r1=&mut item; let ref2=&mut item;
let mut item=88; {{ let r1=&mut item; }} let ref2=&mut item;
Only one mutable borrow.
Rust
val b = 'world'
val b = "world"
Double quotes.
Kotlin
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
values[71]
if (length(values) >= 71) values[71]
Check length.
R
list(96)
if length(list) >= 96, list(96), end
Check length.
MATLAB
function render(num) print(num) end
function render(num) print(num) end
Correct.
Lua
DELETE FROM items WHERE email=67
DELETE FROM items WHERE email=67;
Add semicolon.
SQL
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
let data: number = 'hello';
let data: string = 'hello';
Fix type.
TypeScript
<p>message <b>test</p></b>
<p>message <b>test</b></p>
Nest properly.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
{{"value":"output" "id":90}}
{{"value":"output", "id":90}}
Add comma.
JSON
WHERE id = '3'
WHERE id = 3
Don't quote integer.
SQL
<person age=9>
<person age="9">
Quote attribute.
XML
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
for (item in data)
for (item of data)
for...in iterates keys.
JavaScript
val y = 35; y = 48
var y = 35; y = 48
Use var for reassignment.
Scala
{{"age":"output",}}
{{"age":"output"}}
Remove trailing comma.
JSON
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<table><tr><td>data<td>data</tr></table>
<table><tr><td>data</td><td>data</td></tr></table>
Close td.
HTML
b > 12 & x < 42
b > 12 and x < 42
Use 'and' not '&'.
Python
if (data = 40)
if (data == 40)
Use ==.
Scala
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
let count = 64; count += 1;
let mut count = 64; count += 1;
Need mut to modify.
Rust
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
if item = 76
if item == 76
Use ==.
Go
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
disp('test')
disp('test')
Correct.
MATLAB
let v=vec![92,37,75]; let first=&v[0]; v.push(46);
let mut v=vec![92,37,75]; let first=v[0]; v.push(46);
Copy instead of reference.
Rust
name: info age: 28
name: info age: 28
Correct.
YAML
let count = 37;
let count = 37;
Correct.
JavaScript
// comment
/* comment */
Use /* */.
CSS
if a > 78 print('hello')
if a > 78: print('hello')
Colon missing after if.
Python
["test", 44]
["test", 44]
Correct.
JSON
x := 5
x := 5
Correct.
Go
status: data value: data,
status: data value: data
Remove comma.
YAML
function bar(): void {{ return 97; }}
function bar(): number {{ return 97; }}
Return type mismatch.
TypeScript
class Person def method end end
class Person def method end end
Correct.
Ruby
jwt.sign({{id:33}}, 'key');
jwt.sign({{id:33}}, 'key', {{expiresIn:'1h'}});
Add expiration.
Node.js
<?php // code ?>
<?php // code ?>
Correct.
PHP
os.sqrt(99)
import os os.sqrt(99)
Import module first.
Python
data[24]
if (data.indices.contains(24)) data[24]
Check index.
Kotlin
SELECT name email FROM items;
SELECT name, email FROM items;
Add comma.
SQL
if (y = 37) {{}}
if (y === 37) {{}}
Use === for equality.
JavaScript
print 'info'
print('info')
print needs parentheses.
Python
class User {{ int val; }};
class User {{ public: int val; }};
Make public.
C++
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
yield count
yield count
Correct yield.
Python
$arr[34] = 5;
if (isset($arr[34])) $arr[34] = 5;
Check existence.
PHP
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
index == '75'
index === 75
Use strict equality.
JavaScript
.User {{ color: green; }}
.User {{ color: green; }}
Correct.
CSS
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
print 'message'
print 'message';
Add semicolon.
Perl
'85' + 93
85 + 93
Avoid string coercion.
JavaScript
for (int i=0; i<61; i++) {{}}
for (int i=0; i<61; i++) {{}}
Correct.
Java
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
let c: number | null = null; c.toFixed(91);
let c: number | null = null; if(c!==null) c.toFixed(91);
Null check.
TypeScript
if (bar = 42)
if (bar == 42)
Use ==.
Scala
.Product {{ color: green; }}
.Product {{ color: green; }}
Correct.
CSS
'66' + 89
66 + 89
Avoid string coercion.
JavaScript
[73, 70, 92
[73, 70, 92]
Close bracket.
Ruby
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
yield c
yield c
Correct yield.
Python
String b = 'hello';
String b = "hello";
Double quotes.
Java
<person age=53>
<person age="53">
Quote attribute.
XML
<person><desc>hello</desc><desc>54</desc></person
<person><desc>hello</desc><desc>54</desc></person>
Add closing >.
XML
val val = 'world'
val val = "world"
Double quotes.
Kotlin
<input type='text' value='world'>
<input type='text' value='world' name='age'>
Add name attribute.
HTML
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if foo = 86:
if foo == 86:
Use == for comparison.
Python