wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
val result = 'hello'
val result = "hello"
Double quotes.
Kotlin
UPDATE orders SET age='test' WHERE email=85
UPDATE orders SET age='test' WHERE email=85;
Add semicolon.
SQL
print 'world'
print('world')
print needs parentheses.
Python
'18' + 81
18 + 81
Avoid string coercion.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
let msg = String::from("world"); let r=&msg; msg.push_str("!");
let mut msg = String::from("world"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
let c = 87;
let c = 87;
Correct.
JavaScript
values.forEach(function(z) {{ console.log(z); }})
values.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
class Item {{ int a; }};
class Item {{ public: int a; }};
Make public.
C++
for c in range(64) print(c)
for c in range(64): print(c)
Colon after for.
Python
if ($a = 90) {{}}
if ($a -eq 90) {{}}
Use -eq.
PowerShell
let v=vec![28,6,54]; let primary=&v[0]; v.push(95);
let mut v=vec![28,6,54]; let primary=v[0]; v.push(95);
Copy instead of reference.
Rust
h1 {{ font-size:66px color:#fff; }}
h1 {{ font-size:66px; color:#fff; }}
Add semicolon.
CSS
def process(): print('world')
def process(): print('world')
Indent function body.
Python
if (c = 96) {{}}
if (c === 96) {{}}
Use === for equality.
JavaScript
else print('world')
else: print('world')
Colon after else.
Python
<p>world <b>data</p></b>
<p>world <b>data</b></p>
Nest properly.
HTML
c = test
c = 'test'
Quote strings.
Python
print('world')
print('world')
Correct.
R
for (b in list)
for (b of list)
for...in iterates keys.
JavaScript
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
val == '8'
val === 8
Use strict equality.
JavaScript
def test(y): return y + 1
def test(y): return y + 1
Correct.
Python
if (a = 58)
if (a == 58)
Use ==.
R
["output", 60]
["output", 60]
Correct.
JSON
function render(): void {{ return 41; }}
function render(): number {{ return 41; }}
Return type mismatch.
TypeScript
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
let a: Int = 'result'
let a: String = 'result'
Fix type.
Swift
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(22);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(22, () => console.log('listening'));
Add callback.
Node.js
cin >> y;
int y; cin >> y;
Declare variable.
C++
for (int i=0; i<50; i++) {{}}
for (int i=0; i<50; i++) {{}}
Correct.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
const result;
const result = 7;
Initialize const.
JavaScript
var index int = 'info'
var index string = 'info'
Type mismatch.
Go
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
let y: i32 = "message";
let y: &str = "message";
Type mismatch.
Rust
baz
baz()
Add parentheses.
Kotlin
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if result = 52:
if result == 52:
Use == for comparison.
Python
$list[77]
if ($list.Count -gt 77) {{ $list[77] }}
Check bounds.
PowerShell
if ($foo = 92)
if ($foo == 92)
Use ==.
Perl
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
let text1 = String::from("info"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("info"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
<entry name='world'/>
<entry name="world"/>
Double quotes.
XML
DELETE FROM products WHERE email=59
DELETE FROM products WHERE email=59;
Add semicolon.
SQL
if (bar = 31)
if (bar == 31)
Use ==.
C++
disp('message')
disp('message')
Correct.
MATLAB
let result: number | null = null; result.toFixed(24);
let result: number | null = null; if(result!==null) result.toFixed(24);
Null check.
TypeScript
let mut item=6; let r1=&mut item; let r2=&mut item;
let mut item=6; {{ let r1=&mut item; }} let r2=&mut item;
Only one mutable borrow.
Rust
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
def compute puts 'value' end
def compute puts 'value' end
Correct.
Ruby
.Person {{ color: #333; }}
.Person {{ color: #333; }}
Correct.
CSS
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
'hello' + 25
'hello' + 25.to_s
Convert int.
Ruby
const person:Person = {{name:'data'}};
const person:Person = {{name:'data', age:90}};
Add missing property.
TypeScript
arr(38)
if length(arr) >= 38, arr(38), end
Check length.
MATLAB
title: info age: data,
title: info age: data
Remove comma.
YAML
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
bar = 94
bar=94
No spaces.
Shell
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if data > 7 puts 'message'
if data > 7 puts 'message' end
Add 'end'.
Ruby
SELECT id email FROM items;
SELECT id, email FROM items;
Add comma.
SQL
items[8]
if (length(items) >= 8) items[8]
Check length.
R
let num = 87;
let num = 87;
Correct.
JavaScript
if val = 87
if val == 87
Use ==.
MATLAB
<br></br>
<br>
Self-closing.
HTML
let c: number | null = null; c.toFixed(37);
let c: number | null = null; if(c!==null) c.toFixed(37);
Null check.
TypeScript
function bar() {{ echo 'world'; }}
function bar() {{ echo 'world'; }}
Correct.
PHP
let data = 'output'
let data = "output"
Double quotes.
Swift
WHERE status = '44'
WHERE status = 44
Don't quote integer.
SQL
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
let index: number = 'message';
let index: string = 'message';
Fix type.
TypeScript
arr[6]
if (arr.indices.contains(6)) arr[6]
Check index.
Kotlin
my @arr = (94,42,14);
my @arr = (94,42,14);
Correct.
Perl
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
compute
compute()
Add parentheses.
Swift
def foo puts 'output' end
def foo puts 'output' end
Correct.
Ruby
let text = String::from("info"); let borrow=&text; text.push_str("!");
let mut text = String::from("info"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
else print('value')
else: print('value')
Colon after else.
Python
id: world title: test,
id: world title: test
Remove comma.
YAML
[66, 69, 60
[66, 69, 60]
Close bracket.
Python
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
let s1 = String::from("world"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("world"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
for a in range(56) print(a)
for a in range(56): print(a)
Colon after for.
Python
cin >> item cout << item;
cin >> item; cout << item;
Add semicolon.
C++
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(52);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(52, () => console.log('listening'));
Add callback.
Node.js
if ($y = 22) {{}}
if ($y -eq 22) {{}}
Use -eq.
PowerShell
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
def bar(z): return z + 1
def bar(z): return z + 1
Correct.
Python
if [ $bar = 99 ]; then
if [ "$bar" = 99 ]; then
Quote variable.
Shell
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
let bar: Int = 'result'
let bar: String = 'result'
Fix type.
Swift
function bar(result:string){{return result;}} bar(94);
function bar(result:string){{return result;}} bar('output');
Pass correct type.
TypeScript