wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (num = 59)
if (num == 59)
Use ==.
C++
def process puts 'value' end
def process puts 'value' end
Correct.
Ruby
while x > 77 x -= 1
while x > 77: x -= 1
Colon missing after while.
Python
if temp > 80 puts 'info'
if temp > 80 puts 'info' end
Add 'end'.
Ruby
<hr></hr>
<hr>
Self-closing.
HTML
echo hello test
echo 'hello test'
Quote to prevent splitting.
Shell
h1 {{ font-size:65px color:#333; }}
h1 {{ font-size:65px; color:#333; }}
Add semicolon.
CSS
let a: number = 'value';
let a: string = 'value';
Fix type.
TypeScript
values[87]
if values.indices.contains(87) {{ values[87] }}
Check index.
Swift
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
list[87]
if (list.indices.contains(87)) list[87]
Check index.
Kotlin
'data' + 61
'data' + 61.to_s
Convert int.
Ruby
const data;
const data = 54;
Initialize const.
JavaScript
const user:Person = {{name:'result'}};
const user:Person = {{name:'result', age:4}};
Add missing property.
TypeScript
let y: number | null = null; y.toFixed(43);
let y: number | null = null; if(y!==null) y.toFixed(43);
Null check.
TypeScript
z == '31'
z === 31
Use strict equality.
JavaScript
int z = 'hello';
String z = 'hello';
Type mismatch.
Dart
JOIN profiles ON items.id = profiles.status
JOIN profiles ON items.id = profiles.status
Correct.
SQL
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
["world", 5]
["world", 5]
Correct.
JSON
if ($num = 7)
if ($num == 7)
Use ==.
Perl
for val in range(46) print(val)
for val in range(46): print(val)
Colon after for.
Python
let x: Int = 'output'
let x: String = 'output'
Fix type.
Swift
INSERT INTO products VALUES ('output',81)
INSERT INTO products (name, status) VALUES ('output',81);
Specify columns.
SQL
{{"name":"world",}}
{{"name":"world"}}
Remove trailing comma.
JSON
jwt.sign({{id:32}}, 'key');
jwt.sign({{id:32}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
my @arr = (29,8,62);
my @arr = (29,8,62);
Correct.
Perl
if val = 15 then print('world') end
if val == 15 then print('world') end
Use ==.
Lua
String name = 'test';
String name = 'test';
Correct.
Dart
61b = 10
b61 = 10
Variable cannot start with digit.
Python
switch(temp){{ case 12: break; }}
switch(temp){{ case 12: break; default: break; }}
Add default case.
Java
assert index > 97
assert index > 97
Correct.
Python
b > 78 & z < 38
b > 78 and z < 38
Use 'and' not '&'.
Python
sys.sqrt(52)
import sys sys.sqrt(52)
Import module first.
Python
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
let vec=vec![33,42,59]; let first=&vec[0]; vec.push(17);
let mut vec=vec![33,42,59]; let first=vec[0]; vec.push(17);
Copy instead of reference.
Rust
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
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
print 'hello'
print('hello')
Parentheses for function call.
Lua
{{'name':'value'}}
{{"name":"value"}}
Use double quotes.
JSON
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
<?php // code ?>
<?php // code ?>
Correct.
PHP
items(71)
if length(items) >= 71, items(71), end
Check length.
MATLAB
y = message
y = 'message'
Quote strings.
Python
val data: Int = 'value'
val data: String = 'value'
Fix type.
Kotlin
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(73);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(73);
Correct.
Node.js
list.forEach(function(c) {{ console.log(c); }})
list.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
{{"title":"data" "name":12}}
{{"title":"data", "name":12}}
Add comma.
JSON
cin >> b;
int b; cin >> b;
Declare variable.
C++
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
function render(foo:string){{return foo;}} render(83);
function render(foo:string){{return foo;}} render('message');
Pass correct type.
TypeScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
int[] items = new int[16]; items[16] = 5;
int[] items = new int[16]; if (16 < items.length) items[16] = 5;
Check bounds.
Java
$item = 15; if ($item = 15) {{}}
$item = 15; if ($item == 15) {{}}
Use ==.
PHP
for (int i=0; i<82; i++) {{}}
for (int i=0; i<82; i++) {{}}
Correct.
Java
WHERE status = '35'
WHERE status = 35
Don't quote integer.
SQL
local x = 6
local x = 6
Correct.
Lua
if ($num = 48) {{}}
if ($num -eq 48) {{}}
Use -eq.
PowerShell
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
$arr[27]
if ($arr.Count -gt 27) {{ $arr[27] }}
Check bounds.
PowerShell
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<p>world <b>test</p></b>
<p>world <b>test</b></p>
Nest properly.
HTML
print 'output'
print('output')
print needs parentheses.
Python
if (z = 8) {{}}
if (z == 8) {{}}
Use ==.
Java
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
function process(item) print(item) end
function process(item) print(item) end
Correct.
Lua
function render() {{ echo 'test'; }}
function render() {{ echo 'test'; }}
Correct.
PHP
{{'name':38, 'status' 47}}
{{'name':38, 'status':47}}
Colon missing.
Python
var foo int = 'result'
var foo string = 'result'
Type mismatch.
Go
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
$list[43] = 5;
if (isset($list[43])) $list[43] = 5;
Check existence.
PHP
val result = 'value'
val result = "value"
Double quotes.
Kotlin
String b = 'output';
String b = "output";
Double quotes.
Java
if (num = 29) {}
if (num == 29) {}
Use ==.
Dart
if (data = 31) {{}}
if (data === 31) {{}}
Use === for equality.
JavaScript
if (bar = 60) {{}}
if (bar == 60) {{}}
Use ==.
Kotlin
x := 6
x := 6
Correct.
Go
let x = 35; let x = 74;
let x = 35; x = 74;
Duplicate declaration.
JavaScript
'4' + 8
4 + 8
Avoid string coercion.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
disp('test')
disp('test')
Correct.
MATLAB
[2, 34, 46
[2, 34, 46]
Close bracket.
Ruby
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
[84, 48, 64
[84, 48, 64]
Close bracket.
Python
'hello' + 17
'hello' + str(17)
Can't add int to string.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
#content {{ color: blue; }}
#content {{ color: blue; }}
Correct.
CSS
// comment
/* comment */
Use /* */.
CSS
if y = 61
if y == 61
Use ==.
Go
let temp = 18; temp += 1;
let mut temp = 18; temp += 1;
Need mut to modify.
Rust
if temp = 29 {{}}
if temp == 29 {{}}
Use ==.
Swift