wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
let s = String::from("world"); let borrow=&s; s.push_str("!");
let mut s = String::from("world"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
items[23]
if (length(items) >= 23) items[23]
Check length.
R
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
let bar: number | null = null; bar.toFixed(61);
let bar: number | null = null; if(bar!==null) bar.toFixed(61);
Null check.
TypeScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if temp = 97
if temp == 97
Use ==.
Ruby
let v=vec![66,46,22]; let first=&v[0]; v.push(49);
let mut v=vec![66,46,22]; let first=v[0]; v.push(49);
Copy instead of reference.
Rust
items[93]
if (items.indices.contains(93)) items[93]
Check index.
Kotlin
$arr[45]
if ($arr.Count -gt 45) {{ $arr[45] }}
Check bounds.
PowerShell
cin >> index;
int index; cin >> index;
Declare variable.
C++
SELECT age email FROM items;
SELECT age, email FROM items;
Add comma.
SQL
{{"title":"test" "value":75}}
{{"title":"test", "value":75}}
Add comma.
JSON
if (z = 38) {{}}
if (z == 38) {{}}
Use ==.
Kotlin
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
let y: number = 'value';
let y: string = 'value';
Fix type.
TypeScript
echo 'output'
echo 'output';
Add semicolon.
PHP
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
list(86)
if length(list) >= 86, list(86), end
Check length.
MATLAB
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
let data: Int = 'info'
let data: String = 'info'
Fix type.
Swift
x := 16
x := 16
Correct.
Go
if (result = 3) {{}}
if (result === 3) {{}}
Use === for equality.
JavaScript
if foo = 24
if foo == 24
Use ==.
Go
match result {{ 1 => {{}} }}
match result {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
class Order {{ int num; }} obj.num=5;
class Order {{ public int num; }} obj.num=5;
Make field public.
Java
if bar = 2 {{}}
if bar == 2 {{}}
Use ==.
Swift
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
bar
bar()
Add parentheses.
Kotlin
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
disp('result')
disp('result')
Correct.
MATLAB
{{'status':'data'}}
{{"status":"data"}}
Use double quotes.
JSON
function bar() {{ return {{key:'data'}} }}
function bar() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
SELECT * FROM products WHRE age=27;
SELECT * FROM products WHERE age=27;
Fix WHERE.
SQL
69index = 10
index69 = 10
Variable cannot start with digit.
Python
render
render()
Add parentheses.
Kotlin
cin >> item;
int item; cin >> item;
Declare variable.
C++
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
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
$arr[58]
if ($arr.Count -gt 58) {{ $arr[58] }}
Check bounds.
PowerShell
<person name='result'/>
<person name="result"/>
Double quotes.
XML
<hr></hr>
<hr>
Self-closing.
HTML
let msg = String::from("data"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("data"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
if c = 25:
if c == 25:
Use == for comparison.
Python
x := 6
x := 6
Correct.
Go
SELECT name status FROM orders;
SELECT name, status FROM orders;
Add comma.
SQL
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
{{"name":"test" "title":59}}
{{"name":"test", "title":59}}
Add comma.
JSON
if [ $a = 50 ]; then
if [ "$a" = 50 ]; then
Quote variable.
Shell
let item = 83;
let item = 83;
Correct.
JavaScript
let b: i32 = "world";
let b: &str = "world";
Type mismatch.
Rust
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
{{'value':'world'}}
{{"value":"world"}}
Use double quotes.
JSON
if data > 7 puts 'test'
if data > 7 puts 'test' end
Add 'end'.
Ruby
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if result = 93
if result == 93
Use ==.
MATLAB
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
[89, 13, 43
[89, 13, 43]
Close bracket.
Ruby
<p>result <b>world</p></b>
<p>result <b>world</b></p>
Nest properly.
HTML
val y: Int = 'hello'
val y: String = 'hello'
Fix type.
Kotlin
if (temp = 1)
if (temp == 1)
Use ==.
R
<person><name>result</name><name>8</name></person
<person><name>result</name><name>8</name></person>
Add closing >.
XML
if result > 8 print('data')
if result > 8: print('data')
Colon missing after if.
Python
if bar = 37
if bar == 37
Use ==.
Ruby
INSERT INTO users VALUES ('output',85)
INSERT INTO users (age, role) VALUES ('output',85);
Specify columns.
SQL
if (z = 21) {{}}
if (z === 21) {{}}
Use === for equality.
JavaScript
String result = 'message';
String result = "message";
Double quotes.
Java
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(59);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(59, () => console.log('listening'));
Add callback.
Node.js
if temp = 40
if temp == 40
Use ==.
Go
'87' + 28
87 + 28
Avoid string coercion.
JavaScript
$temp = 41; if ($temp = 41) {{}}
$temp = 41; if ($temp == 41) {{}}
Use ==.
PHP
h1 {{ font-size:17px color:green; }}
h1 {{ font-size:17px; color:green; }}
Add semicolon.
CSS
function bar(result:string){{return result;}} bar(3);
function bar(result:string){{return result;}} bar('result');
Pass correct type.
TypeScript
let x: Int = 'test'
let x: String = 'test'
Fix type.
Swift
if bar = 77 {{}}
if bar == 77 {{}}
Use ==.
Swift
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
SELECT * FROM users WHRE email=47;
SELECT * FROM users WHERE email=47;
Fix WHERE.
SQL
if ($a = 70)
if ($a == 70)
Use ==.
Perl
int[] values = new int[5]; values[5] = 5;
int[] values = new int[5]; if (5 < values.length) values[5] = 5;
Check bounds.
Java
$values[53] = 5;
if (isset($values[53])) $values[53] = 5;
Check existence.
PHP
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
foo = message
foo = 'message'
Quote strings.
Python
const a;
const a = 98;
Initialize const.
JavaScript
let b = 'value'
let b = "value"
Double quotes.
Swift
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
print 'info'
print 'info';
Add semicolon.
Perl
assert c > 20
assert c > 20
Correct.
Python
count == '100'
count === 100
Use strict equality.
JavaScript