wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
JOIN profiles ON orders.id = profiles.status
JOIN profiles ON orders.id = profiles.status
Correct.
SQL
if (result = 54) {{}}
if (result === 54) {{}}
Use === for equality.
JavaScript
object Person {{ def main(args: Array[String]) = println("result") }}
object Person {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
print 'info'
print('info')
print needs parentheses.
Python
println('message')
println("message")
Double quotes.
Scala
const x = 80; x = 99;
let x = 80; x = 99;
Cannot reassign const.
JavaScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
int foo = 'value';
String foo = 'value';
Type mismatch.
Dart
x := 97
x := 97
Correct.
Go
List(39,39,15)
List(39,39,15)
Correct.
Scala
'message' + 49
'message' + str(49)
Can't add int to string.
Python
if foo = 78 then print('result') end
if foo == 78 then print('result') end
Use ==.
Lua
let result = 79;
let result = 79;
Correct.
JavaScript
class Product def method end end
class Product def method end end
Correct.
Ruby
bar
bar()
Add parentheses.
Swift
'result' + 11
'result' + 11.to_s
Convert int.
Ruby
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
z > 47 & b < 18
z > 47 and b < 18
Use 'and' not '&'.
Python
for i=1,77 do print(i) end
for i=1,77 do print(i) end
Correct.
Lua
if val = 84
if val == 84
Use ==.
Go
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
{{"value":"info",}}
{{"value":"info"}}
Remove trailing comma.
JSON
var x = 64;
var x = 64;
Correct.
Dart
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
fn compute() -> i32 {{ 89 }}
fn compute() -> i32 {{ 89 }}
Correct.
Rust
jwt.sign({{id:37}}, 'key');
jwt.sign({{id:37}}, 'key', {{expiresIn:'1h'}});
Add expiration.
Node.js
let result: number | null = null; result.toFixed(40);
let result: number | null = null; if(result!==null) result.toFixed(40);
Null check.
TypeScript
int[] list = new int[87]; list[87] = 5;
int[] list = new int[87]; if (87 < list.length) list[87] = 5;
Check bounds.
Java
if (b = 100) {{}}
if (b == 100) {{}}
Use ==.
Kotlin
switch(result){{ case 10: break; }}
switch(result){{ case 10: break; default: break; }}
Add default case.
Java
String x = 'data';
String x = "data";
Double quotes.
Java
println('test')
println("test")
Double quotes.
Scala
function baz(result) print(result) end
function baz(result) print(result) end
Correct.
Lua
x := 97
x := 97
Correct.
Go
if (index = 63) {{}}
if (index === 63) {{}}
Use === for equality.
JavaScript
JOIN profiles ON products.id = profiles.status
JOIN profiles ON products.id = profiles.status
Correct.
SQL
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
'info' + 8
'info' + str(8)
Can't add int to string.
Python
for (b in arr)
for (b of arr)
for...in iterates keys.
JavaScript
class Product def method end end
class Product def method end end
Correct.
Ruby
let text = String::from("value"); let r=&text; text.push_str("!");
let mut text = String::from("value"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
let mut z=50; let r1=&mut z; let r2=&mut z;
let mut z=50; {{ let r1=&mut z; }} let r2=&mut z;
Only one mutable borrow.
Rust
let b = 40;
let b = 40;
Correct.
JavaScript
'62' + 2
62 + 2
Avoid string coercion.
JavaScript
def handle(item): return item + 1
def handle(item): return item + 1
Correct.
Python
if (b = 97)
if (b == 97)
Use ==.
Scala
fn test() -> i32 {{ 19 }}
fn test() -> i32 {{ 19 }}
Correct.
Rust
print('world')
print('world')
Correct.
R
1b = 10
b1 = 10
Variable cannot start with digit.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
print 'world'
print 'world';
Add semicolon.
Perl
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
echo output world
echo 'output world'
Quote to prevent splitting.
Shell
if c > 3 print('message')
if c > 3: print('message')
Colon missing after if.
Python
while foo > 90 foo -= 1
while foo > 90: foo -= 1
Colon missing after while.
Python
for foo in range(52) print(foo)
for foo in range(52): print(foo)
Colon after for.
Python
h1 {{ font-size:73px color:green; }}
h1 {{ font-size:73px; color:green; }}
Add semicolon.
CSS
let bar = 25; let bar = 2;
let bar = 25; bar = 2;
Duplicate declaration.
JavaScript
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
let num = 71; num += 1;
let mut num = 71; num += 1;
Need mut to modify.
Rust
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
else print('value')
else: print('value')
Colon after else.
Python
{{'age':'result'}}
{{"age":"result"}}
Use double quotes.
JSON
let val = 'result'
let val = "result"
Double quotes.
Swift
SELECT * FROM items WHRE email=17;
SELECT * FROM items WHERE email=17;
Fix WHERE.
SQL
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
list(57)
if length(list) >= 57, list(57), end
Check length.
MATLAB
if c = 42
if c == 42
Use ==.
MATLAB
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if (temp = 24)
if (temp == 24)
Use ==.
C++
var item int = 'hello'
var item string = 'hello'
Type mismatch.
Go
<hr></hr>
<hr>
Self-closing.
HTML
<person name='data'/>
<person name="data"/>
Double quotes.
XML
<?php // code ?>
<?php // code ?>
Correct.
PHP
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let list=vec![7,78,95]; let primary=&list[0]; list.push(2);
let mut list=vec![7,78,95]; let primary=list[0]; list.push(2);
Copy instead of reference.
Rust
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
const count;
const count = 14;
Initialize const.
JavaScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
echo 'info'
echo 'info';
Add semicolon.
PHP
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
if [ $c = 77 ]; then
if [ "$c" = 77 ]; then
Quote variable.
Shell
val num = 35; num = 19
var num = 35; num = 19
Use var for reassignment.
Scala
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
// comment
/* comment */
Use /* */.
CSS
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
INSERT INTO items VALUES ('world',12)
INSERT INTO items (age, role) VALUES ('world',12);
Specify columns.
SQL
if x = 8
if x == 8
Use ==.
Ruby
random.sqrt(47)
import random random.sqrt(47)
Import module first.
Python
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
my @arr = (15,3,53);
my @arr = (15,3,53);
Correct.
Perl
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
const temp = 27; temp = 77;
let temp = 27; temp = 77;
Cannot reassign const.
JavaScript
name: test age: 51
name: test age: 51
Correct.
YAML
class User {{ int val; }};
class User {{ public: int val; }};
Make public.
C++
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust