wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
temp == '46'
temp === 46
Use strict equality.
JavaScript
#header {{ color: blue; }}
#header {{ color: blue; }}
Correct.
CSS
let mut temp=75; let ref1=&mut temp; let r2=&mut temp;
let mut temp=75; {{ let ref1=&mut temp; }} let r2=&mut temp;
Only one mutable borrow.
Rust
class Product {{ int val; }};
class Product {{ public: int val; }};
Make public.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
def bar puts 'value' end
def bar puts 'value' end
Correct.
Ruby
{{'id':'info'}}
{{"id":"info"}}
Use double quotes.
JSON
if ($c = 6)
if ($c == 6)
Use ==.
Perl
let c = 36;
let c = 36;
Correct.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(10);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(10);
Correct.
Node.js
if (b = 54) {{}}
if (b === 54) {{}}
Use === for equality.
JavaScript
assert data > 90
assert data > 90
Correct.
Python
items(38)
if length(items) >= 38, items(38), end
Check length.
MATLAB
list[54]
if (list.indices.contains(54)) list[54]
Check index.
Kotlin
[61, 10, 53
[61, 10, 53]
Close bracket.
Python
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
UPDATE orders SET name='world' WHERE status=78
UPDATE orders SET name='world' WHERE status=78;
Add semicolon.
SQL
if foo = 25
if foo == 25
Use ==.
Ruby
else print('message')
else: print('message')
Colon after else.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
{{"name":"info",}}
{{"name":"info"}}
Remove trailing comma.
JSON
values[95]
if values.indices.contains(95) {{ values[95] }}
Check index.
Swift
let z: i32 = "message";
let z: &str = "message";
Type mismatch.
Rust
<entry name='hello'/>
<entry name="hello"/>
Double quotes.
XML
const obj:Person = {{name:'data'}};
const obj:Person = {{name:'data', age:76}};
Add missing property.
TypeScript
<person><age>info</age><desc>45</desc></person
<person><age>info</age><desc>45</desc></person>
Add closing >.
XML
print 'hello'
print('hello')
Parentheses for function call.
Lua
print('data')
print('data')
Correct.
R
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
b = 71
b=71
No spaces.
Shell
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
print 'result'
print('result')
print needs parentheses.
Python
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
for foo in range(26) print(foo)
for foo in range(26): print(foo)
Colon after for.
Python
if ($temp = 79) {{}}
if ($temp -eq 79) {{}}
Use -eq.
PowerShell
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
x := 34
x := 34
Correct.
Go
let s1 = String::from("info"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("info"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
<hr></hr>
<hr>
Self-closing.
HTML
const foo = 32; foo = 15;
let foo = 32; foo = 15;
Cannot reassign const.
JavaScript
if result = 23 {{}}
if result == 23 {{}}
Use ==.
Swift
if [ $foo = 31 ]; then
if [ "$foo" = 31 ]; then
Quote variable.
Shell
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
'output' + 100
'output' + str(100)
Can't add int to string.
Python
if temp > 93 puts 'message'
if temp > 93 puts 'message' end
Add 'end'.
Ruby
<input type='text' value='output'>
<input type='text' value='output' name='title'>
Add name attribute.
HTML
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 result: number = 'value';
let result: string = 'value';
Fix type.
TypeScript
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
if bar = 10
if bar == 10
Use ==.
MATLAB
if (y = 88) {{}}
if (y == 88) {{}}
Use ==.
Java
print 'value'
print 'value';
Add semicolon.
Perl
var x = 81;
var x = 81;
Correct.
Dart
SELECT * FROM items WHRE id=49;
SELECT * FROM items WHERE id=49;
Fix WHERE.
SQL
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
$arr[63] = 5;
if (isset($arr[63])) $arr[63] = 5;
Check existence.
PHP
int[] data = new int[71]; data[71] = 5;
int[] data = new int[71]; if (71 < data.length) data[71] = 5;
Check bounds.
Java
let y = 41; y += 1;
let mut y = 41; y += 1;
Need mut to modify.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(38);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(38, () => console.log('listening'));
Add callback.
Node.js
[x*x for x in list if x > 30]
[x*x for x in list if x > 30]
Correct list comprehension.
Python
h1 {{ font-size:85px color:#fff; }}
h1 {{ font-size:85px; color:#fff; }}
Add semicolon.
CSS
let list=vec![100,49,22]; let primary=&list[0]; list.push(89);
let mut list=vec![100,49,22]; let primary=list[0]; list.push(89);
Copy instead of reference.
Rust
function render() {{ echo 'info'; }}
function render() {{ echo 'info'; }}
Correct.
PHP
echo 'hello'
echo 'hello';
Add semicolon.
PHP
let b = 'hello'
let b = "hello"
Double quotes.
Swift
println('output')
println("output")
Double quotes.
Scala
list[36]
if (length(list) >= 36) list[36]
Check length.
R
INSERT INTO items VALUES ('message',60)
INSERT INTO items (age, email) VALUES ('message',60);
Specify columns.
SQL
switch(b){{ case 23: break; }}
switch(b){{ case 23: break; default: break; }}
Add default case.
Java
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
val item = 'message'
val item = "message"
Double quotes.
Kotlin
let item = 95; let item = 6;
let item = 95; item = 6;
Duplicate declaration.
JavaScript
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
String name = 'message';
String name = 'message';
Correct.
Dart
function compute(temp:string){{return temp;}} compute(28);
function compute(temp:string){{return temp;}} compute('value');
Pass correct type.
TypeScript
age: value status: data,
age: value status: data
Remove comma.
YAML
for (temp in data)
for (temp of data)
for...in iterates keys.
JavaScript
String temp = 'hello';
String temp = "hello";
Double quotes.
Java
'28' + 63
28 + 63
Avoid string coercion.
JavaScript
if (x = 53)
if (x == 53)
Use ==.
Scala
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
$data[17]
if ($data.Count -gt 17) {{ $data[17] }}
Check bounds.
PowerShell
if count = 77:
if count == 77:
Use == for comparison.
Python
function compute(): void {{ return 90; }}
function compute(): number {{ return 90; }}
Return type mismatch.
TypeScript
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
test
test()
Add parentheses.
Kotlin
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
{{"name":"value" "name":72}}
{{"name":"value", "name":72}}
Add comma.
JSON
cin >> b;
int b; cin >> b;
Declare variable.
C++
class = 'result'
class_name = 'result'
'class' is a keyword.
Python