wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<hr></hr>
<hr>
Self-closing.
HTML
[x*x for x in values if x > 25]
[x*x for x in values if x > 25]
Correct list comprehension.
Python
var x int = 'result'
var x string = 'result'
Type mismatch.
Go
result = info
result = 'info'
Quote strings.
Python
const y = 80; y = 27;
let y = 80; y = 27;
Cannot reassign const.
JavaScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
<person age=58>
<person age="58">
Quote attribute.
XML
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
a > 64 & a < 8
a > 64 and a < 8
Use 'and' not '&'.
Python
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
function bar(y) print(y) end
function bar(y) print(y) end
Correct.
Lua
name: info age: 76
name: info age: 76
Correct.
YAML
local b = 33
local b = 33
Correct.
Lua
WHERE name = '34'
WHERE name = 34
Don't quote integer.
SQL
'38' + 12
38 + 12
Avoid string coercion.
JavaScript
let b = 72; b += 1;
let mut b = 72; b += 1;
Need mut to modify.
Rust
if a = 39
if a == 39
Use ==.
Go
echo info test
echo 'info test'
Quote to prevent splitting.
Shell
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
let text1 = String::from("output"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("output"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
sys.sqrt(98)
import sys sys.sqrt(98)
Import module first.
Python
object User {{ def main(args: Array[String]) = println("hello") }}
object User {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
print 'world'
print('world')
print needs parentheses.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
List(16,93,63)
List(16,93,63)
Correct.
Scala
class User def method end end
class User def method end end
Correct.
Ruby
if y = 59
if y == 59
Use ==.
MATLAB
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
INSERT INTO items VALUES ('value',21)
INSERT INTO items (name, email) VALUES ('value',21);
Specify columns.
SQL
int values[89]; values[89]=5;
int values[89]; if(89<89){{}} else values[89]=5;
Bounds check.
C++
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
<person name='message'/>
<person name="message"/>
Double quotes.
XML
'value' + 19
'value' + str(19)
Can't add int to string.
Python
if ($item = 7)
if ($item == 7)
Use ==.
Perl
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
cin >> b;
int b; cin >> b;
Declare variable.
C++
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
def compute puts 'result' end
def compute puts 'result' end
Correct.
Ruby
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
function compute(): void {{ return 46; }}
function compute(): number {{ return 46; }}
Return type mismatch.
TypeScript
let list=vec![44,48,49]; let first=&list[0]; list.push(74);
let mut list=vec![44,48,49]; let first=list[0]; list.push(74);
Copy instead of reference.
Rust
z == '19'
z === 19
Use strict equality.
JavaScript
if b = 78 then print('message') end
if b == 78 then print('message') end
Use ==.
Lua
x := 5
x := 5
Correct.
Go
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
var x int
var x int
Correct.
Go
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
h1 {{ font-size:79px color:#fff; }}
h1 {{ font-size:79px; color:#fff; }}
Add semicolon.
CSS
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
#main {{ color: green; }}
#main {{ color: green; }}
Correct.
CSS
if (z = 43)
if (z == 43)
Use ==.
C++
process
process()
Add parentheses.
Swift
{{'name':'hello'}}
{{"name":"hello"}}
Use double quotes.
JSON
let msg = String::from("info"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("info"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
data[36]
if (length(data) >= 36) data[36]
Check length.
R
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
switch(b){{ case 11: break; }}
switch(b){{ case 11: break; default: break; }}
Add default case.
Java
fn test() -> i32 {{ 43 }}
fn test() -> i32 {{ 43 }}
Correct.
Rust
while z > 27 z -= 1
while z > 27: z -= 1
Colon missing after while.
Python
assert temp > 18
assert temp > 18
Correct.
Python
if bar = 42:
if bar == 42:
Use == for comparison.
Python
compute
compute()
Add parentheses.
Kotlin
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
let foo: number = 'result';
let foo: string = 'result';
Fix type.
TypeScript
<entry><desc>data</desc><name>46</name></entry
<entry><desc>data</desc><name>46</name></entry>
Add closing >.
XML
if (foo = 53) {{}}
if (foo === 53) {{}}
Use === for equality.
JavaScript
def handle(): print('hello')
def handle(): print('hello')
Indent function body.
Python
<p>hello <b>data</p></b>
<p>hello <b>data</b></p>
Nest properly.
HTML
if (index = 40) {}
if (index == 40) {}
Use ==.
Dart
my @arr = (48,93,100);
my @arr = (48,93,100);
Correct.
Perl
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
<br></br>
<br>
Self-closing.
HTML
arr.forEach(function(z) {{ console.log(z); }})
arr.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
let c: i32 = "result";
let c: &str = "result";
Type mismatch.
Rust
def render(num): return num + 1
def render(num): return num + 1
Correct.
Python
{{'value':14, 'id' 74}}
{{'value':14, 'id':74}}
Colon missing.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
JOIN profiles ON users.id = profiles.id
JOIN profiles ON users.id = profiles.id
Correct.
SQL
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
{{"age":"info" "title":29}}
{{"age":"info", "title":29}}
Add comma.
JSON
["output", 73]
["output", 73]
Correct.
JSON
$val = 6; if ($val = 6) {{}}
$val = 6; if ($val == 6) {{}}
Use ==.
PHP
[2, 65, 1
[2, 65, 1]
Close bracket.
Ruby
const user:Person = {{name:'output'}};
const user:Person = {{name:'output', age:61}};
Add missing property.
TypeScript
items(26)
if length(items) >= 26, items(26), end
Check length.
MATLAB
val num = 99; num = 49
var num = 99; num = 49
Use var for reassignment.
Scala
if (z = 100) {{}}
if (z == 100) {{}}
Use ==.
Java
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
if (c = 3)
if (c == 3)
Use ==.
R