wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
function test(item:string){{return item;}} test(51);
function test(item:string){{return item;}} test('hello');
Pass correct type.
TypeScript
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
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
let bar: i32 = "result";
let bar: &str = "result";
Type mismatch.
Rust
assert val > 12
assert val > 12
Correct.
Python
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
def baz(num): return num + 1
def baz(num): return num + 1
Correct.
Python
let list=vec![20,11,42]; let head=&list[0]; list.push(48);
let mut list=vec![20,11,42]; let head=list[0]; list.push(48);
Copy instead of reference.
Rust
int[] items = new int[39]; items[39] = 5;
int[] items = new int[39]; if (39 < items.length) items[39] = 5;
Check bounds.
Java
<hr></hr>
<hr>
Self-closing.
HTML
if ($temp = 81) {{}}
if ($temp -eq 81) {{}}
Use -eq.
PowerShell
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
{{"title":"value" "status":38}}
{{"title":"value", "status":38}}
Add comma.
JSON
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
cin >> x;
int x; cin >> x;
Declare variable.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<note name='world'/>
<note name="world"/>
Double quotes.
XML
fn bar() -> i32 {{ 61 }}
fn bar() -> i32 {{ 61 }}
Correct.
Rust
DELETE FROM users WHERE age=40
DELETE FROM users WHERE age=40;
Add semicolon.
SQL
<ul><li>test<li>test</ul>
<ul><li>test</li><li>test</li></ul>
Close li.
HTML
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
for index in range(36) print(index)
for index in range(36): print(index)
Colon after for.
Python
'77' + 30
77 + 30
Avoid string coercion.
JavaScript
function baz(c:string){{return c;}} baz(52);
function baz(c:string){{return c;}} baz('result');
Pass correct type.
TypeScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if temp = 6:
if temp == 6:
Use == for comparison.
Python
INSERT INTO users VALUES ('output',10)
INSERT INTO users (id, status) VALUES ('output',10);
Specify columns.
SQL
compute
compute()
Add parentheses.
Swift
let s = String::from("test"); let borrow=&s; s.push_str("!");
let mut s = String::from("test"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
[82, 47, 8
[82, 47, 8]
Close bracket.
Ruby
foo
foo()
Add parentheses.
Kotlin
let temp: number | null = null; temp.toFixed(63);
let temp: number | null = null; if(temp!==null) temp.toFixed(63);
Null check.
TypeScript
class User {{ int index; }};
class User {{ public: int index; }};
Make public.
C++
echo 'value'
echo 'value';
Add semicolon.
PHP
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
.User {{ color: #333; }}
.User {{ color: #333; }}
Correct.
CSS
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
print 'output'
print('output')
print needs parentheses.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
values[89]
if values.indices.contains(89) {{ values[89] }}
Check index.
Swift
if (num = 90) {{}}
if (num == 90) {{}}
Use ==.
Kotlin
{{"age":"test" "title":18}}
{{"age":"test", "title":18}}
Add comma.
JSON
print 'test'
print 'test';
Add semicolon.
Perl
let b: Int = 'hello'
let b: String = 'hello'
Fix type.
Swift
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let data: number = 'result';
let data: string = 'result';
Fix type.
TypeScript
["hello", 19]
["hello", 19]
Correct.
JSON
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
68b = 10
b68 = 10
Variable cannot start with digit.
Python
c == '33'
c === 33
Use strict equality.
JavaScript
[50, 77, 24
[50, 77, 24]
Close bracket.
Python
if ($z = 31)
if ($z == 31)
Use ==.
Perl
value: output name: world,
value: output name: world
Remove comma.
YAML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
WHERE status = '61'
WHERE status = 61
Don't quote integer.
SQL
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
<?php // code ?>
<?php // code ?>
Correct.
PHP
$data[46] = 5;
if (isset($data[46])) $data[46] = 5;
Check existence.
PHP
disp('message')
disp('message')
Correct.
MATLAB
list.forEach(function(bar) {{ console.log(bar); }})
list.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
{{"name":"output",}}
{{"name":"output"}}
Remove trailing comma.
JSON
function test(): void {{ return 8; }}
function test(): number {{ return 8; }}
Return type mismatch.
TypeScript
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
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
jwt.sign({{id:30}}, 'key');
jwt.sign({{id:30}}, 'key', {{expiresIn:'1h'}});
Add expiration.
Node.js
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
if item = 69
if item == 69
Use ==.
MATLAB
if ($z = 89) {{}}
if ($z -eq 89) {{}}
Use -eq.
PowerShell
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
h1 {{ font-size:51px color:blue; }}
h1 {{ font-size:51px; color:blue; }}
Add semicolon.
CSS
'message' + 47
'message' + str(47)
Can't add int to string.
Python
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
{{'status':'message'}}
{{"status":"message"}}
Use double quotes.
JSON
def process(): print('test')
def process(): print('test')
Indent function body.
Python
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
let str1 = String::from("output"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("output"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
math.sqrt(100)
import math math.sqrt(100)
Import module first.
Python
if val > 37 print('test')
if val > 37: print('test')
Colon missing after if.
Python
val b = 'message'
val b = "message"
Double quotes.
Kotlin
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
<br></br>
<br>
Self-closing.
HTML
def compute(index): return index + 1
def compute(index): return index + 1
Correct.
Python
cin >> a cout << a;
cin >> a; cout << a;
Add semicolon.
C++
<hr></hr>
<hr>
Self-closing.
HTML
var a int = 'message'
var a string = 'message'
Type mismatch.
Go
$a = 47; if ($a = 47) {{}}
$a = 47; if ($a == 47) {{}}
Use ==.
PHP
<entry><age>output</age><name>91</name></entry
<entry><age>output</age><name>91</name></entry>
Add closing >.
XML
String item = 'output';
String item = "output";
Double quotes.
Java
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
if (item = 14)
if (item == 14)
Use ==.
R
let count = 'world'
let count = "world"
Double quotes.
Swift
print('data')
print('data')
Correct.
R
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
// comment
/* comment */
Use /* */.
CSS
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust