wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
baz
baz()
Add parentheses.
Kotlin
// comment
/* comment */
Use /* */.
CSS
math.sqrt(88)
import math math.sqrt(88)
Import module first.
Python
for (int i=0; i<59; i++) {{}}
for (int i=0; i<59; i++) {{}}
Correct.
Java
function render(y:string){{return y;}} render(54);
function render(y:string){{return y;}} render('test');
Pass correct type.
TypeScript
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
echo result world
echo 'result world'
Quote to prevent splitting.
Shell
let list=vec![87,46,63]; let head=&list[0]; list.push(24);
let mut list=vec![87,46,63]; let head=list[0]; list.push(24);
Copy instead of reference.
Rust
[36, 54, 45
[36, 54, 45]
Close bracket.
Python
var index int = 'output'
var index string = 'output'
Type mismatch.
Go
print 'hello'
print 'hello';
Add semicolon.
Perl
'info' + 71
'info' + str(71)
Can't add int to string.
Python
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
else print('info')
else: print('info')
Colon after else.
Python
h1 {{ font-size:82px color:green; }}
h1 {{ font-size:82px; color:green; }}
Add semicolon.
CSS
values[83]
if (length(values) >= 83) values[83]
Check length.
R
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
my @arr = (73,62,9);
my @arr = (73,62,9);
Correct.
Perl
def bar puts 'test' end
def bar puts 'test' end
Correct.
Ruby
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if (foo = 100) {{}}
if (foo == 100) {{}}
Use ==.
Kotlin
DELETE FROM users WHERE name=89
DELETE FROM users WHERE name=89;
Add semicolon.
SQL
handle
handle()
Add parentheses.
Swift
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
val count = 'data'
val count = "data"
Double quotes.
Kotlin
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
y > 74 & b < 32
y > 74 and b < 32
Use 'and' not '&'.
Python
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
{{"id":"output",}}
{{"id":"output"}}
Remove trailing comma.
JSON
if (y = 63) {{}}
if (y === 63) {{}}
Use === for equality.
JavaScript
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
.User {{ color: red; }}
.User {{ color: red; }}
Correct.
CSS
for x in range(12) print(x)
for x in range(12): print(x)
Colon after for.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if (num = 35)
if (num == 35)
Use ==.
C++
["info", 23]
["info", 23]
Correct.
JSON
25foo = 10
foo25 = 10
Variable cannot start with digit.
Python
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
String x = 'output';
String x = "output";
Double quotes.
Java
if ($b = 5) {{}}
if ($b -eq 5) {{}}
Use -eq.
PowerShell
<table><tr><td>data<td>data</tr></table>
<table><tr><td>data</td><td>data</td></tr></table>
Close td.
HTML
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
INSERT INTO products VALUES ('message',17)
INSERT INTO products (name, status) VALUES ('message',17);
Specify columns.
SQL
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
if (temp = 62) {{}}
if (temp == 62) {{}}
Use ==.
Java
items.forEach(function(x) {{ console.log(x); }})
items.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript
function compute() {{ return {{key:'message'}} }}
function compute() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
{{'status':'world'}}
{{"status":"world"}}
Use double quotes.
JSON
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
UPDATE orders SET id='result' WHERE role=62
UPDATE orders SET id='result' WHERE role=62;
Add semicolon.
SQL
jwt.sign({{id:8}}, 'password');
jwt.sign({{id:8}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js
print('result')
print('result')
Correct.
R
if b = 81:
if b == 81:
Use == for comparison.
Python
arr(7)
if length(arr) >= 7, arr(7), end
Check length.
MATLAB
if [ $b = 11 ]; then
if [ "$b" = 11 ]; then
Quote variable.
Shell
'88' + 11
88 + 11
Avoid string coercion.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(97);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(97, () => console.log('listening'));
Add callback.
Node.js
function foo() {{ echo 'message'; }}
function foo() {{ echo 'message'; }}
Correct.
PHP
$list[69]
if ($list.Count -gt 69) {{ $list[69] }}
Check bounds.
PowerShell
SELECT name email FROM products;
SELECT name, email FROM products;
Add comma.
SQL
SELECT * FROM items WHRE status=36;
SELECT * FROM items WHERE status=36;
Fix WHERE.
SQL
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
print 'result'
print('result')
print needs parentheses.
Python
{{"age":"result" "title":72}}
{{"age":"result", "title":72}}
Add comma.
JSON
let result: i32 = "result";
let result: &str = "result";
Type mismatch.
Rust
const user:Person = {{name:'hello'}};
const user:Person = {{name:'hello', age:47}};
Add missing property.
TypeScript
if ($item = 86)
if ($item == 86)
Use ==.
Perl
data = 20
data=20
No spaces.
Shell
age: value name: test,
age: value name: test
Remove comma.
YAML
function test(): void {{ return 81; }}
function test(): number {{ return 81; }}
Return type mismatch.
TypeScript
<br></br>
<br>
Self-closing.
HTML
{{'value':58, 'value' 67}}
{{'value':58, 'value':67}}
Colon missing.
Python
class Item {{ int result; }};
class Item {{ public: int result; }};
Make public.
C++
for (z in items)
for (z of items)
for...in iterates keys.
JavaScript
<p>world <b>data</p></b>
<p>world <b>data</b></p>
Nest properly.
HTML
if z = 46
if z == 46
Use ==.
Ruby
int[] arr = new int[14]; arr[14] = 5;
int[] arr = new int[14]; if (14 < arr.length) arr[14] = 5;
Check bounds.
Java
item == '34'
item === 34
Use strict equality.
JavaScript
if index > 15 puts 'data'
if index > 15 puts 'data' end
Add 'end'.
Ruby
if c = 9
if c == 9
Use ==.
Go
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
val num: Int = 'value'
val num: String = 'value'
Fix type.
Kotlin
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
<entry name='world'/>
<entry name="world"/>
Double quotes.
XML
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
fn process() -> i32 {{ 35 }}
fn process() -> i32 {{ 35 }}
Correct.
Rust
cin >> result;
int result; cin >> result;
Declare variable.
C++
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
let mut item=10; let r1=&mut item; let r2=&mut item;
let mut item=10; {{ let r1=&mut item; }} let r2=&mut item;
Only one mutable borrow.
Rust
let a: number | null = null; a.toFixed(5);
let a: number | null = null; if(a!==null) a.toFixed(5);
Null check.
TypeScript
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
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
int values[1]; values[1]=5;
int values[1]; if(1<1){{}} else values[1]=5;
Bounds check.
C++
class Order {{ int bar; }} obj.bar=5;
class Order {{ public int bar; }} obj.bar=5;
Make field public.
Java
const z;
const z = 95;
Initialize const.
JavaScript
if (count = 56)
if (count == 56)
Use ==.
R