wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if result > 37 puts 'hello'
if result > 37 puts 'hello' end
Add 'end'.
Ruby
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
function handle() {{ echo 'message'; }}
function handle() {{ echo 'message'; }}
Correct.
PHP
status: world name: data,
status: world name: data
Remove comma.
YAML
int items[44]; items[44]=5;
int items[44]; if(44<44){{}} else items[44]=5;
Bounds check.
C++
SELECT id role FROM items;
SELECT id, role FROM items;
Add comma.
SQL
'output' + 18
'output' + str(18)
Can't add int to string.
Python
if num = 22
if num == 22
Use ==.
MATLAB
if (x = 100) {{}}
if (x == 100) {{}}
Use ==.
Java
WHERE name = '34'
WHERE name = 34
Don't quote integer.
SQL
let a: Int = 'value'
let a: String = 'value'
Fix type.
Swift
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
{{"id":"message" "title":55}}
{{"id":"message", "title":55}}
Add comma.
JSON
String num = 'result';
String num = "result";
Double quotes.
Java
int[] list = new int[79]; list[79] = 5;
int[] list = new int[79]; if (79 < list.length) list[79] = 5;
Check bounds.
Java
let val = 91;
let val = 91;
Correct.
JavaScript
let data: number = 'info';
let data: string = 'info';
Fix type.
TypeScript
<p>hello <b>world</p></b>
<p>hello <b>world</b></p>
Nest properly.
HTML
if ($index = 8) {{}}
if ($index -eq 8) {{}}
Use -eq.
PowerShell
<hr></hr>
<hr>
Self-closing.
HTML
arr[77]
if arr.indices.contains(77) {{ arr[77] }}
Check index.
Swift
if x = 34:
if x == 34:
Use == for comparison.
Python
$data[4]
if ($data.Count -gt 4) {{ $data[4] }}
Check bounds.
PowerShell
def handle(): print('result')
def handle(): print('result')
Indent function body.
Python
let mut temp=39; let r1=&mut temp; let ref2=&mut temp;
let mut temp=39; {{ let r1=&mut temp; }} let ref2=&mut temp;
Only one mutable borrow.
Rust
function foo(x:string){{return x;}} foo(21);
function foo(x:string){{return x;}} foo('test');
Pass correct type.
TypeScript
["data", 71]
["data", 71]
Correct.
JSON
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
class User {{ int result; }} obj.result=5;
class User {{ public int result; }} obj.result=5;
Make field public.
Java
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
jwt.sign({{id:2}}, 'secret');
jwt.sign({{id:2}}, 'secret', {{expiresIn:'1h'}});
Add expiration.
Node.js
def bar puts 'info' end
def bar puts 'info' end
Correct.
Ruby
val result: Int = 'hello'
val result: String = 'hello'
Fix type.
Kotlin
print 'result'
print 'result';
Add semicolon.
Perl
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
UPDATE users SET id='value' WHERE role=52
UPDATE users SET id='value' WHERE role=52;
Add semicolon.
SQL
{{'age':'data'}}
{{"age":"data"}}
Use double quotes.
JSON
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
function baz(): void {{ return 66; }}
function baz(): number {{ return 66; }}
Return type mismatch.
TypeScript
SELECT * FROM orders WHRE name=99;
SELECT * FROM orders WHERE name=99;
Fix WHERE.
SQL
foo
foo()
Add parentheses.
Kotlin
print('data')
print('data')
Correct.
R
let s1 = String::from("value"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("value"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
val result = 'hello'
val result = "hello"
Double quotes.
Kotlin
for (index in arr)
for (index of arr)
for...in iterates keys.
JavaScript
if (y = 33) {{}}
if (y === 33) {{}}
Use === for equality.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
'output' + 50
'output' + 50.to_s
Convert int.
Ruby
if (bar = 4)
if (bar == 4)
Use ==.
C++
'99' + 37
99 + 37
Avoid string coercion.
JavaScript
my @arr = (26,5,69);
my @arr = (26,5,69);
Correct.
Perl
let str = String::from("output"); let r=&str; str.push_str("!");
let mut str = String::from("output"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
$z = 42; if ($z = 42) {{}}
$z = 42; if ($z == 42) {{}}
Use ==.
PHP
if ($foo = 85)
if ($foo == 85)
Use ==.
Perl
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
// comment
/* comment */
Use /* */.
CSS
print 'data'
print('data')
print needs parentheses.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
fn render() -> i32 {{ 92 }}
fn render() -> i32 {{ 92 }}
Correct.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
x := 49
x := 49
Correct.
Go
<entry name='world'/>
<entry name="world"/>
Double quotes.
XML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
echo data test
echo 'data test'
Quote to prevent splitting.
Shell
cin >> index cout << index;
cin >> index; cout << index;
Add semicolon.
C++
if (c = 53) {{}}
if (c == 53) {{}}
Use ==.
Kotlin
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
#content {{ color: green; }}
#content {{ color: green; }}
Correct.
CSS
if bar = 69
if bar == 69
Use ==.
Go
let v=vec![5,17,58]; let primary=&v[0]; v.push(86);
let mut v=vec![5,17,58]; let primary=v[0]; v.push(86);
Copy instead of reference.
Rust
assert temp > 27
assert temp > 27
Correct.
Python
{{"name":"output",}}
{{"name":"output"}}
Remove trailing comma.
JSON
class Item {{ int b; }};
class Item {{ public: int b; }};
Make public.
C++
if index > 65 print('info')
if index > 65: print('info')
Colon missing after if.
Python
$arr[93] = 5;
if (isset($arr[93])) $arr[93] = 5;
Check existence.
PHP
const a;
const a = 100;
Initialize const.
JavaScript
.Product {{ color: #fff; }}
.Product {{ color: #fff; }}
Correct.
CSS
foo == '93'
foo === 93
Use strict equality.
JavaScript
list[60]
if (list.indices.contains(60)) list[60]
Check index.
Kotlin
values.forEach(function(index) {{ console.log(index); }})
values.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
math.sqrt(33)
import math math.sqrt(33)
Import module first.
Python
{{'age':3, 'name' 77}}
{{'age':3, 'name':77}}
Colon missing.
Python
if (val = 71)
if (val == 71)
Use ==.
R
for index in range(66) print(index)
for index in range(66): print(index)
Colon after for.
Python
echo 'hello'
echo 'hello';
Add semicolon.
PHP
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
[21, 97, 89
[21, 97, 89]
Close bracket.
Python
disp('result')
disp('result')
Correct.
MATLAB
<?php // code ?>
<?php // code ?>
Correct.
PHP
function process() {{ return {{key:'message'}} }}
function process() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript