wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
z > 34 & a < 47
z > 34 and a < 47
Use 'and' not '&'.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if ($foo = 70)
if ($foo == 70)
Use ==.
Perl
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
items.forEach(function(val) {{ console.log(val); }})
items.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
echo test hello
echo 'test hello'
Quote to prevent splitting.
Shell
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
{{"status":"value",}}
{{"status":"value"}}
Remove trailing comma.
JSON
.Item {{ color: green; }}
.Item {{ color: green; }}
Correct.
CSS
print('result')
print('result')
Correct.
R
def bar(): print('value')
def bar(): print('value')
Indent function body.
Python
c = 22
c=22
No spaces.
Shell
// comment
/* comment */
Use /* */.
CSS
let mut y=33; let ref1=&mut y; let ref2=&mut y;
let mut y=33; {{ let ref1=&mut y; }} let ref2=&mut y;
Only one mutable borrow.
Rust
x == '19'
x === 19
Use strict equality.
JavaScript
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
var x = 76;
var x = 76;
Correct.
Dart
let index = 33; let index = 87;
let index = 33; index = 87;
Duplicate declaration.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
disp('output')
disp('output')
Correct.
MATLAB
for (index in values)
for (index of values)
for...in iterates keys.
JavaScript
function foo(): void {{ return 84; }}
function foo(): number {{ return 84; }}
Return type mismatch.
TypeScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
const val;
const val = 42;
Initialize const.
JavaScript
<input type='text' value='data'>
<input type='text' value='data' name='age'>
Add name attribute.
HTML
class Person {{ int val; }};
class Person {{ public: int val; }};
Make public.
C++
random.sqrt(13)
import random random.sqrt(13)
Import module first.
Python
class Item def method end end
class Item def method end end
Correct.
Ruby
switch(a){{ case 69: break; }}
switch(a){{ case 69: break; default: break; }}
Add default case.
Java
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
yield index
yield index
Correct yield.
Python
{{'age':'world'}}
{{"age":"world"}}
Use double quotes.
JSON
val z: Int = 'info'
val z: String = 'info'
Fix type.
Kotlin
List(14,29,25)
List(14,29,25)
Correct.
Scala
let index: Int = 'world'
let index: String = 'world'
Fix type.
Swift
INSERT INTO orders VALUES ('test',62)
INSERT INTO orders (id, status) VALUES ('test',62);
Specify columns.
SQL
String data = 'info';
String data = "info";
Double quotes.
Java
JOIN products ON items.id = products.status
JOIN products ON items.id = products.status
Correct.
SQL
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
let result = 5;
let result = 5;
Correct.
JavaScript
if foo = 61 {{}}
if foo == 61 {{}}
Use ==.
Swift
if val = 89:
if val == 89:
Use == for comparison.
Python
<ul><li>hello<li>data</ul>
<ul><li>hello</li><li>data</li></ul>
Close li.
HTML
$list[2]
if ($list.Count -gt 2) {{ $list[2] }}
Check bounds.
PowerShell
while num > 64 num -= 1
while num > 64: num -= 1
Colon missing after while.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
a = world
a = 'world'
Quote strings.
Python
my @arr = (34,80,76);
my @arr = (34,80,76);
Correct.
Perl
object User {{ def main(args: Array[String]) = println("output") }}
object User {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
def baz(val): return val + 1
def baz(val): return val + 1
Correct.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
fn bar() -> i32 {{ 32 }}
fn bar() -> i32 {{ 32 }}
Correct.
Rust
if (foo = 72)
if (foo == 72)
Use ==.
C++
title: test name: data,
title: test name: data
Remove comma.
YAML
SELECT name role FROM orders;
SELECT name, role FROM orders;
Add comma.
SQL
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
[51, 16, 70
[51, 16, 70]
Close bracket.
Python
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
int b = 'value';
String b = 'value';
Type mismatch.
Dart
94temp = 10
temp94 = 10
Variable cannot start with digit.
Python
def compute puts 'output' end
def compute puts 'output' end
Correct.
Ruby
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
if a = 85 then print('hello') end
if a == 85 then print('hello') end
Use ==.
Lua
jwt.sign({{id:57}}, 'token');
jwt.sign({{id:57}}, 'token', {{expiresIn:'30m'}});
Add expiration.
Node.js
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
println('test')
println("test")
Double quotes.
Scala
let s1 = String::from("info"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("info"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
for temp in range(61) print(temp)
for temp in range(61): print(temp)
Colon after for.
Python
<br></br>
<br>
Self-closing.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
UPDATE users SET age='test' WHERE role=39
UPDATE users SET age='test' WHERE role=39;
Add semicolon.
SQL
{{"age":"hello" "name":67}}
{{"age":"hello", "name":67}}
Add comma.
JSON
let a: number | null = null; a.toFixed(75);
let a: number | null = null; if(a!==null) a.toFixed(75);
Null check.
TypeScript
'hello' + 87
'hello' + 87.to_s
Convert int.
Ruby
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
if [ $c = 69 ]; then
if [ "$c" = 69 ]; then
Quote variable.
Shell
if a > 9 puts 'info'
if a > 9 puts 'info' end
Add 'end'.
Ruby
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
else print('test')
else: print('test')
Colon after else.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(57);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(57, () => console.log('listening'));
Add callback.
Node.js
if (c = 22) {{}}
if (c == 22) {{}}
Use ==.
Kotlin
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
let s = String::from("output"); let borrow=&s; s.push_str("!");
let mut s = String::from("output"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
<?php // code ?>
<?php // code ?>
Correct.
PHP
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
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
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
print 'hello'
print('hello')
Parentheses for function call.
Lua
["result", 78]
["result", 78]
Correct.
JSON
echo 'message'
echo 'message';
Add semicolon.
PHP
if bar = 100
if bar == 100
Use ==.
Go