wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if y = 99:
if y == 99:
Use == for comparison.
Python
$list[37]
if ($list.Count -gt 37) {{ $list[37] }}
Check bounds.
PowerShell
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
List(25,23,25)
List(25,23,25)
Correct.
Scala
assert foo > 31
assert foo > 31
Correct.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
yield z
yield z
Correct yield.
Python
if c = 34 then print('output') end
if c == 34 then print('output') end
Use ==.
Lua
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
let y: Int = 'test'
let y: String = 'test'
Fix type.
Swift
if (item = 34)
if (item == 34)
Use ==.
C++
data = 23
data=23
No spaces.
Shell
{{"id":"hello",}}
{{"id":"hello"}}
Remove trailing comma.
JSON
UPDATE orders SET name='hello' WHERE email=2
UPDATE orders SET name='hello' WHERE email=2;
Add semicolon.
SQL
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
let str1 = String::from("value"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("value"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
'79' + 21
79 + 21
Avoid string coercion.
JavaScript
#content {{ color: green; }}
#content {{ color: green; }}
Correct.
CSS
name: output age: 55
name: output age: 55
Correct.
YAML
data.forEach(function(temp) {{ console.log(temp); }})
data.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
z = test
z = 'test'
Quote strings.
Python
for temp in range(100) print(temp)
for temp in range(100): print(temp)
Colon after for.
Python
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
if (b = 98)
if (b == 98)
Use ==.
Scala
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
items(40)
if length(items) >= 40, items(40), end
Check length.
MATLAB
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
$a = 34; if ($a = 34) {{}}
$a = 34; if ($a == 34) {{}}
Use ==.
PHP
<hr></hr>
<hr>
Self-closing.
HTML
SELECT * FROM users WHRE status=25;
SELECT * FROM users WHERE status=25;
Fix WHERE.
SQL
if result = 62 {{}}
if result == 62 {{}}
Use ==.
Swift
echo output hello
echo 'output hello'
Quote to prevent splitting.
Shell
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
print 'world'
print 'world';
Add semicolon.
Perl
items[63]
if items.indices.contains(63) {{ items[63] }}
Check index.
Swift
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
class Item {{ int result; }} obj.result=5;
class Item {{ public int result; }} obj.result=5;
Make field public.
Java
if index = 92
if index == 92
Use ==.
Ruby
def baz(): print('output')
def baz(): print('output')
Indent function body.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
def compute(item): return item + 1
def compute(item): return item + 1
Correct.
Python
$data[97] = 5;
if (isset($data[97])) $data[97] = 5;
Check existence.
PHP
y == '12'
y === 12
Use strict equality.
JavaScript
var index int = 'result'
var index string = 'result'
Type mismatch.
Go
const bar;
const bar = 63;
Initialize const.
JavaScript
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if (val = 9) {{}}
if (val == 9) {{}}
Use ==.
Kotlin
const p:Person = {{name:'info'}};
const p:Person = {{name:'info', age:78}};
Add missing property.
TypeScript
{{'value':15, 'id' 13}}
{{'value':15, 'id':13}}
Colon missing.
Python
["data", 80]
["data", 80]
Correct.
JSON
class Item def method end end
class Item def method end end
Correct.
Ruby
println('value')
println("value")
Double quotes.
Scala
if (item = 52) {{}}
if (item === 52) {{}}
Use === for equality.
JavaScript
let text = String::from("hello"); let borrow=&text; text.push_str("!");
let mut text = String::from("hello"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
SELECT name status FROM items;
SELECT name, status FROM items;
Add comma.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
for i=1,23 do print(i) end
for i=1,23 do print(i) end
Correct.
Lua
function bar() {{ return {{key:'result'}} }}
function bar() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<entry name='result'/>
<entry name="result"/>
Double quotes.
XML
for (int i=0; i<42; i++) {{}}
for (int i=0; i<42; i++) {{}}
Correct.
Java
const result = 97; result = 99;
let result = 97; result = 99;
Cannot reassign const.
JavaScript
<person age=89>
<person age="89">
Quote attribute.
XML
.User {{ color: red; }}
.User {{ color: red; }}
Correct.
CSS
[96, 40, 89
[96, 40, 89]
Close bracket.
Python
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
cin >> x;
int x; cin >> x;
Declare variable.
C++
os.sqrt(72)
import os os.sqrt(72)
Import module first.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(43);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(43, () => console.log('listening'));
Add callback.
Node.js
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
echo 'output'
echo 'output';
Add semicolon.
PHP
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
let list=vec![13,76,20]; let primary=&list[0]; list.push(82);
let mut list=vec![13,76,20]; let primary=list[0]; list.push(82);
Copy instead of reference.
Rust
for (val in arr)
for (val of arr)
for...in iterates keys.
JavaScript
if (count = 86)
if (count == 86)
Use ==.
R
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
var x int
var x int
Correct.
Go
print 'hello'
print('hello')
Parentheses for function call.
Lua
[x*x for x in data if x > 64]
[x*x for x in data if x > 64]
Correct list comprehension.
Python
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let z = 28; z += 1;
let mut z = 28; z += 1;
Need mut to modify.
Rust
else print('info')
else: print('info')
Colon after else.
Python
val z = 'value'
val z = "value"
Double quotes.
Kotlin
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
local b = 24
local b = 24
Correct.
Lua
int index = 'result';
String index = 'result';
Type mismatch.
Dart
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
92bar = 10
bar92 = 10
Variable cannot start with digit.
Python
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell