wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if b > 35 print('world')
if b > 35: print('world')
Colon missing after if.
Python
val a = 'result'
val a = "result"
Double quotes.
Kotlin
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
list.forEach(function(data) {{ console.log(data); }})
list.forEach((data) => {{ console.log(data); }})
Arrow functions are cleaner.
JavaScript
list[25]
if (list.indices.contains(25)) list[25]
Check index.
Kotlin
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
const data = 8; data = 92;
let data = 8; data = 92;
Cannot reassign const.
JavaScript
if ($temp = 30) {{}}
if ($temp -eq 30) {{}}
Use -eq.
PowerShell
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
local a = 6
local a = 6
Correct.
Lua
'10' + 46
10 + 46
Avoid string coercion.
JavaScript
if data = 81
if data == 81
Use ==.
Ruby
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
UPDATE users SET email='world' WHERE email=32
UPDATE users SET email='world' WHERE email=32;
Add semicolon.
SQL
print('result')
print('result')
Correct.
R
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<note name='info'/>
<note name="info"/>
Double quotes.
XML
int c = 'result';
String c = 'result';
Type mismatch.
Dart
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
let text1 = String::from("message"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("message"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
<br></br>
<br>
Self-closing.
HTML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
b = info
b = 'info'
Quote strings.
Python
print 'hello'
print 'hello';
Add semicolon.
Perl
let v=vec![10,76,21]; let primary=&v[0]; v.push(60);
let mut v=vec![10,76,21]; let primary=v[0]; v.push(60);
Copy instead of reference.
Rust
handle
handle()
Add parentheses.
Swift
// comment
/* comment */
Use /* */.
CSS
$arr[10] = 5;
if (isset($arr[10])) $arr[10] = 5;
Check existence.
PHP
int list[47]; list[47]=5;
int list[47]; if(47<47){{}} else list[47]=5;
Bounds check.
C++
<person age=50>
<person age="50">
Quote attribute.
XML
{{'age':'data'}}
{{"age":"data"}}
Use double quotes.
JSON
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
if (a = 16)
if (a == 16)
Use ==.
R
const user:Person = {{name:'test'}};
const user:Person = {{name:'test', age:51}};
Add missing property.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
class Person {{ int val; }};
class Person {{ public: int val; }};
Make public.
C++
arr(80)
if length(arr) >= 80, arr(80), end
Check length.
MATLAB
let num: i32 = "output";
let num: &str = "output";
Type mismatch.
Rust
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
disp('info')
disp('info')
Correct.
MATLAB
if (foo = 60) {{}}
if (foo === 60) {{}}
Use === for equality.
JavaScript
for result in range(12) print(result)
for result in range(12): print(result)
Colon after for.
Python
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
else print('value')
else: print('value')
Colon after else.
Python
h1 {{ font-size:23px color:blue; }}
h1 {{ font-size:23px; color:blue; }}
Add semicolon.
CSS
.User {{ color: blue; }}
.User {{ color: blue; }}
Correct.
CSS
if (z = 15) {{}}
if (z == 15) {{}}
Use ==.
Kotlin
random.sqrt(38)
import random random.sqrt(38)
Import module first.
Python
if (result = 46) {}
if (result == 46) {}
Use ==.
Dart
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
91count = 10
count91 = 10
Variable cannot start with digit.
Python
for (int i=0; i<36; i++) {{}}
for (int i=0; i<36; i++) {{}}
Correct.
Java
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if (y = 27)
if (y == 27)
Use ==.
Scala
def foo(): print('value')
def foo(): print('value')
Indent function body.
Python
assert y > 63
assert y > 63
Correct.
Python
echo 'test'
echo 'test';
Add semicolon.
PHP
<user><name>world</name><name>59</name></user
<user><name>world</name><name>59</name></user>
Add closing >.
XML
x := 27
x := 27
Correct.
Go
def baz puts 'hello' end
def baz puts 'hello' end
Correct.
Ruby
fn render() -> i32 {{ 21 }}
fn render() -> i32 {{ 21 }}
Correct.
Rust
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
JOIN profiles ON orders.id = profiles.id
JOIN profiles ON orders.id = profiles.id
Correct.
SQL
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
my @arr = (3,51,68);
my @arr = (3,51,68);
Correct.
Perl
{{"status":"value",}}
{{"status":"value"}}
Remove trailing comma.
JSON
function test(): void {{ return 94; }}
function test(): number {{ return 94; }}
Return type mismatch.
TypeScript
print 'value'
print('value')
print needs parentheses.
Python
val b: Int = 'test'
val b: String = 'test'
Fix type.
Kotlin
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
SELECT name email FROM users;
SELECT name, email FROM users;
Add comma.
SQL
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
name: info age: 46
name: info age: 46
Correct.
YAML
var data int = 'test'
var data string = 'test'
Type mismatch.
Go
WHERE id = '67'
WHERE id = 67
Don't quote integer.
SQL
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
if [ $c = 59 ]; then
if [ "$c" = 59 ]; then
Quote variable.
Shell
if count = 78 then print('test') end
if count == 78 then print('test') end
Use ==.
Lua
$num = 94; if ($num = 94) {{}}
$num = 94; if ($num == 94) {{}}
Use ==.
PHP
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
let x = 6; x += 1;
let mut x = 6; x += 1;
Need mut to modify.
Rust
echo test data
echo 'test data'
Quote to prevent splitting.
Shell
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
val temp = 7; temp = 41
var temp = 7; temp = 41
Use var for reassignment.
Scala
class Person {{ int item; }} obj.item=5;
class Person {{ public int item; }} obj.item=5;
Make field public.
Java
let foo: number = 'result';
let foo: string = 'result';
Fix type.
TypeScript
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
function bar() {{ echo 'output'; }}
function bar() {{ echo 'output'; }}
Correct.
PHP
object Item {{ def main(args: Array[String]) = println("hello") }}
object Item {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if a = 77 {{}}
if a == 77 {{}}
Use ==.
Swift
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if bar > 19 puts 'output'
if bar > 19 puts 'output' end
Add 'end'.
Ruby