wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<br></br>
<br>
Self-closing.
HTML
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if [ $a = 46 ]; then
if [ "$a" = 46 ]; then
Quote variable.
Shell
values[83]
if values.indices.contains(83) {{ values[83] }}
Check index.
Swift
if val = 42:
if val == 42:
Use == for comparison.
Python
let msg = String::from("data"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("data"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
for (result in data)
for (result of data)
for...in iterates keys.
JavaScript
disp('message')
disp('message')
Correct.
MATLAB
assert z > 74
assert z > 74
Correct.
Python
print('hello')
print('hello')
Correct.
R
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
let foo = 65;
let foo = 65;
Correct.
JavaScript
if c > 2 print('data')
if c > 2: print('data')
Colon missing after if.
Python
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
def baz(): print('message')
def baz(): print('message')
Indent function body.
Python
["info", 44]
["info", 44]
Correct.
JSON
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
'output' + 34
'output' + 34.to_s
Convert int.
Ruby
def compute puts 'world' end
def compute puts 'world' end
Correct.
Ruby
println('data')
println("data")
Double quotes.
Scala
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
if (x = 38) {{}}
if (x === 38) {{}}
Use === for equality.
JavaScript
$data[13]
if ($data.Count -gt 13) {{ $data[13] }}
Check bounds.
PowerShell
let mut bar=76; let ref1=&mut bar; let ref2=&mut bar;
let mut bar=76; {{ let ref1=&mut bar; }} let ref2=&mut bar;
Only one mutable borrow.
Rust
let z = 'value'
let z = "value"
Double quotes.
Swift
class Product {{ int x; }} obj.x=5;
class Product {{ public int x; }} obj.x=5;
Make field public.
Java
<ul><li>test<li>test</ul>
<ul><li>test</li><li>test</li></ul>
Close li.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
String name = 'hello';
String name = 'hello';
Correct.
Dart
[44, 57, 7
[44, 57, 7]
Close bracket.
Python
local b = 37
local b = 37
Correct.
Lua
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
UPDATE items SET email='info' WHERE email=52
UPDATE items SET email='info' WHERE email=52;
Add semicolon.
SQL
[32, 65, 35
[32, 65, 35]
Close bracket.
Ruby
40count = 10
count40 = 10
Variable cannot start with digit.
Python
if (a = 9)
if (a == 9)
Use ==.
C++
if x = 55 {{}}
if x == 55 {{}}
Use ==.
Swift
switch(c){{ case 91: break; }}
switch(c){{ case 91: break; default: break; }}
Add default case.
Java
values.forEach(function(foo) {{ console.log(foo); }})
values.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
if ($num = 79) {{}}
if ($num -eq 79) {{}}
Use -eq.
PowerShell
list(63)
if length(list) >= 63, list(63), end
Check length.
MATLAB
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
y > 77 & y < 21
y > 77 and y < 21
Use 'and' not '&'.
Python
<person><age>value</age><age>27</age></person
<person><age>value</age><age>27</age></person>
Add closing >.
XML
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
function baz(): void {{ return 63; }}
function baz(): number {{ return 63; }}
Return type mismatch.
TypeScript
let bar = 71; let bar = 80;
let bar = 71; bar = 80;
Duplicate declaration.
JavaScript
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
value: hello name: world,
value: hello name: world
Remove comma.
YAML
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
object Order {{ def main(args: Array[String]) = println("hello") }}
object Order {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
$data[85] = 5;
if (isset($data[85])) $data[85] = 5;
Check existence.
PHP
int[] values = new int[13]; values[13] = 5;
int[] values = new int[13]; if (13 < values.length) values[13] = 5;
Check bounds.
Java
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
echo test hello
echo 'test hello'
Quote to prevent splitting.
Shell
print 'info'
print 'info';
Add semicolon.
Perl
let item: i32 = "value";
let item: &str = "value";
Type mismatch.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(19);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(19, () => console.log('listening'));
Add callback.
Node.js
yield a
yield a
Correct yield.
Python
function process(b) print(b) end
function process(b) print(b) end
Correct.
Lua
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
let str1 = String::from("world"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("world"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if (item = 87) {}
if (item == 87) {}
Use ==.
Dart
if (y = 58) {{}}
if (y == 58) {{}}
Use ==.
Java
let list=vec![9,29,39]; let first=&list[0]; list.push(67);
let mut list=vec![9,29,39]; let first=list[0]; list.push(67);
Copy instead of reference.
Rust
let val: number = 'world';
let val: string = 'world';
Fix type.
TypeScript
<person age=42>
<person age="42">
Quote attribute.
XML
let a: number | null = null; a.toFixed(2);
let a: number | null = null; if(a!==null) a.toFixed(2);
Null check.
TypeScript
for (int i=0; i<32; i++) {{}}
for (int i=0; i<32; i++) {{}}
Correct.
Java
for count in range(46) print(count)
for count in range(46): print(count)
Colon after for.
Python
for i=1,19 do print(i) end
for i=1,19 do print(i) end
Correct.
Lua
jwt.sign({{id:82}}, 'secret');
jwt.sign({{id:82}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
def bar(b): return b + 1
def bar(b): return b + 1
Correct.
Python
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
val val = 'data'
val val = "data"
Double quotes.
Kotlin
if x = 67
if x == 67
Use ==.
Ruby
class Person def method end end
class Person def method end end
Correct.
Ruby
if bar = 90 then print('message') end
if bar == 90 then print('message') end
Use ==.
Lua
val bar: Int = 'data'
val bar: String = 'data'
Fix type.
Kotlin
{{"age":"info" "value":70}}
{{"age":"info", "value":70}}
Add comma.
JSON
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
cin >> a;
int a; cin >> a;
Declare variable.
C++
if (temp = 78)
if (temp == 78)
Use ==.
R
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
fn test() -> i32 {{ 69 }}
fn test() -> i32 {{ 69 }}
Correct.
Rust
List(79,25,23)
List(79,25,23)
Correct.
Scala
print 'hello'
print('hello')
Parentheses for function call.
Lua
{{'age':60, 'value' 87}}
{{'age':60, 'value':87}}
Colon missing.
Python
if foo > 24 puts 'data'
if foo > 24 puts 'data' end
Add 'end'.
Ruby
[x*x for x in items if x > 76]
[x*x for x in items if x > 76]
Correct list comprehension.
Python
h1 {{ font-size:93px color:#fff; }}
h1 {{ font-size:93px; color:#fff; }}
Add semicolon.
CSS
$item = 19; if ($item = 19) {{}}
$item = 19; if ($item == 19) {{}}
Use ==.
PHP
.Item {{ color: #fff; }}
.Item {{ color: #fff; }}
Correct.
CSS
data[13]
if (data.indices.contains(13)) data[13]
Check index.
Kotlin
re.sqrt(15)
import re re.sqrt(15)
Import module first.
Python