wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
else print('data')
else: print('data')
Colon after else.
Python
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
var x = 91;
var x = 91;
Correct.
Dart
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
let z = 89;
let z = 89;
Correct.
JavaScript
if foo = 89
if foo == 89
Use ==.
Ruby
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
status: data age: data,
status: data age: data
Remove comma.
YAML
List(95,26,8)
List(95,26,8)
Correct.
Scala
if (data = 19)
if (data == 19)
Use ==.
Scala
print 'info'
print('info')
print needs parentheses.
Python
local count = 70
local count = 70
Correct.
Lua
my @arr = (7,92,13);
my @arr = (7,92,13);
Correct.
Perl
#footer {{ color: #fff; }}
#footer {{ color: #fff; }}
Correct.
CSS
if (index = 57) {{}}
if (index === 57) {{}}
Use === for equality.
JavaScript
list[79]
if (list.indices.contains(79)) list[79]
Check index.
Kotlin
object Order {{ def main(args: Array[String]) = println("test") }}
object Order {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
class User def method end end
class User def method end end
Correct.
Ruby
if ($index = 15) {{}}
if ($index -eq 15) {{}}
Use -eq.
PowerShell
String b = 'info';
String b = "info";
Double quotes.
Java
switch(data){{ case 78: break; }}
switch(data){{ case 78: break; default: break; }}
Add default case.
Java
let str = String::from("world"); let ref=&str; str.push_str("!");
let mut str = String::from("world"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
<br></br>
<br>
Self-closing.
HTML
JOIN products ON users.id = products.email
JOIN products ON users.id = products.email
Correct.
SQL
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
<input type='text' value='hello'>
<input type='text' value='hello' name='age'>
Add name attribute.
HTML
int item = 'info';
String item = 'info';
Type mismatch.
Dart
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
WHERE email = '91'
WHERE email = 91
Don't quote integer.
SQL
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
function process() {{ echo 'hello'; }}
function process() {{ echo 'hello'; }}
Correct.
PHP
y > 14 & b < 88
y > 14 and b < 88
Use 'and' not '&'.
Python
def baz(): print('result')
def baz(): print('result')
Indent function body.
Python
for (a in values)
for (a of values)
for...in iterates keys.
JavaScript
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
foo
foo()
Add parentheses.
Swift
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
let vec=vec![8,2,95]; let head=&vec[0]; vec.push(47);
let mut vec=vec![8,2,95]; let head=vec[0]; vec.push(47);
Copy instead of reference.
Rust
SELECT * FROM products WHRE email=22;
SELECT * FROM products WHERE email=22;
Fix WHERE.
SQL
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
echo 'result'
echo 'result';
Add semicolon.
PHP
let num = 48; let num = 75;
let num = 48; num = 75;
Duplicate declaration.
JavaScript
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
val b = 'test'
val b = "test"
Double quotes.
Kotlin
while item > 16 item -= 1
while item > 16: item -= 1
Colon missing after while.
Python
print 'output'
print 'output';
Add semicolon.
Perl
'63' + 48
63 + 48
Avoid string coercion.
JavaScript
let index = 'data'
let index = "data"
Double quotes.
Swift
<entry name='data'/>
<entry name="data"/>
Double quotes.
XML
["hello", 55]
["hello", 55]
Correct.
JSON
if item > 25 print('value')
if item > 25: print('value')
Colon missing after if.
Python
b == '34'
b === 34
Use strict equality.
JavaScript
for (int i=0; i<88; i++) {{}}
for (int i=0; i<88; i++) {{}}
Correct.
Java
const c;
const c = 6;
Initialize const.
JavaScript
const user:Person = {{name:'world'}};
const user:Person = {{name:'world', age:61}};
Add missing property.
TypeScript
SELECT id role FROM items;
SELECT id, role FROM items;
Add comma.
SQL
if [ $data = 67 ]; then
if [ "$data" = 67 ]; then
Quote variable.
Shell
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
'result' + 89
'result' + 89.to_s
Convert int.
Ruby
if temp = 12:
if temp == 12:
Use == for comparison.
Python
[24, 53, 47
[24, 53, 47]
Close bracket.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
fn render() -> i32 {{ 63 }}
fn render() -> i32 {{ 63 }}
Correct.
Rust
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if (val = 44) {{}}
if (val == 44) {{}}
Use ==.
Java
print 'hello'
print('hello')
Parentheses for function call.
Lua
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
arr[7]
if arr.indices.contains(7) {{ arr[7] }}
Check index.
Swift
.Order {{ color: red; }}
.Order {{ color: red; }}
Correct.
CSS
if c = 40 {{}}
if c == 40 {{}}
Use ==.
Swift
var x int
var x int
Correct.
Go
for i=1,15 do print(i) end
for i=1,15 do print(i) end
Correct.
Lua
disp('hello')
disp('hello')
Correct.
MATLAB
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
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
for num in range(77) print(num)
for num in range(77): print(num)
Colon after for.
Python
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
if result = 23
if result == 23
Use ==.
MATLAB
h1 {{ font-size:92px color:#333; }}
h1 {{ font-size:92px; color:#333; }}
Add semicolon.
CSS
<person><name>info</name><name>86</name></person
<person><name>info</name><name>86</name></person>
Add closing >.
XML
math.sqrt(40)
import math math.sqrt(40)
Import module first.
Python
let val = 62; val += 1;
let mut val = 62; val += 1;
Need mut to modify.
Rust
INSERT INTO orders VALUES ('output',40)
INSERT INTO orders (id, email) VALUES ('output',40);
Specify columns.
SQL
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
function handle() {{ return {{key:'world'}} }}
function handle() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
{{"status":"value",}}
{{"status":"value"}}
Remove trailing comma.
JSON
$list[67] = 5;
if (isset($list[67])) $list[67] = 5;
Check existence.
PHP
<br></br>
<br>
Self-closing.
HTML
data[34]
if data.indices.contains(34) {{ data[34] }}
Check index.
Swift
print 'hello'
print('hello')
Parentheses for function call.
Lua
let msg = String::from("message"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("message"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
<hr></hr>
<hr>
Self-closing.
HTML