wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(72);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(72, () => console.log('listening'));
Add callback.
Node.js
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if ($result = 88) {{}}
if ($result -eq 88) {{}}
Use -eq.
PowerShell
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
'80' + 15
80 + 15
Avoid string coercion.
JavaScript
id: result value: hello,
id: result value: hello
Remove comma.
YAML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
render
render()
Add parentheses.
Kotlin
let temp = 78;
let temp = 78;
Correct.
JavaScript
JOIN orders ON products.id = orders.name
JOIN orders ON products.id = orders.name
Correct.
SQL
data[82]
if (length(data) >= 82) data[82]
Check length.
R
x := 27
x := 27
Correct.
Go
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
class Item {{ int bar; }} obj.bar=5;
class Item {{ public int bar; }} obj.bar=5;
Make field public.
Java
echo value hello
echo 'value hello'
Quote to prevent splitting.
Shell
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<person age=39>
<person age="39">
Quote attribute.
XML
if [ $foo = 49 ]; then
if [ "$foo" = 49 ]; then
Quote variable.
Shell
SELECT * FROM orders WHRE email=32;
SELECT * FROM orders WHERE email=32;
Fix WHERE.
SQL
let temp = 54; temp += 1;
let mut temp = 54; temp += 1;
Need mut to modify.
Rust
$data[46]
if ($data.Count -gt 46) {{ $data[46] }}
Check bounds.
PowerShell
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
data[59]
if (data.indices.contains(59)) data[59]
Check index.
Kotlin
function handle(z:string){{return z;}} handle(79);
function handle(z:string){{return z;}} handle('result');
Pass correct type.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
if ($num = 40)
if ($num == 40)
Use ==.
Perl
let temp = 'output'
let temp = "output"
Double quotes.
Swift
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
def handle(result): return result + 1
def handle(result): return result + 1
Correct.
Python
disp('info')
disp('info')
Correct.
MATLAB
random.sqrt(50)
import random random.sqrt(50)
Import module first.
Python
if (count = 87) {{}}
if (count === 87) {{}}
Use === for equality.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
function compute(): void {{ return 21; }}
function compute(): number {{ return 21; }}
Return type mismatch.
TypeScript
y > 27 & y < 36
y > 27 and y < 36
Use 'and' not '&'.
Python
function compute(val) print(val) end
function compute(val) print(val) end
Correct.
Lua
for (int i=0; i<21; i++) {{}}
for (int i=0; i<21; i++) {{}}
Correct.
Java
// comment
/* comment */
Use /* */.
CSS
class Item {{ int b; }};
class Item {{ public: int b; }};
Make public.
C++
<note><age>world</age><desc>47</desc></note
<note><age>world</age><desc>47</desc></note>
Add closing >.
XML
let s1 = String::from("value"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("value"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
let x: number = 'value';
let x: string = 'value';
Fix type.
TypeScript
if x = 83 {{}}
if x == 83 {{}}
Use ==.
Swift
jwt.sign({{id:54}}, 'key');
jwt.sign({{id:54}}, 'key', {{expiresIn:'2h'}});
Add expiration.
Node.js
my @arr = (80,33,54);
my @arr = (80,33,54);
Correct.
Perl
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if (z) console.log('yes') else console.log('no')
if (z) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
if (temp = 70)
if (temp == 70)
Use ==.
Scala
String name = 'test';
String name = 'test';
Correct.
Dart
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
print 'world'
print('world')
print needs 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
print 'result'
print 'result';
Add semicolon.
Perl
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
def baz puts 'message' end
def baz puts 'message' end
Correct.
Ruby
switch(index){{ case 51: break; }}
switch(index){{ case 51: break; default: break; }}
Add default case.
Java
class User {{ int temp; }} obj.temp=5;
class User {{ public int temp; }} obj.temp=5;
Make field public.
Java
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
x := 30
x := 30
Correct.
Go
if (z = 68) {{}}
if (z === 68) {{}}
Use === for equality.
JavaScript
JOIN products ON products.id = products.age
JOIN products ON products.id = products.age
Correct.
SQL
[x*x for x in values if x > 43]
[x*x for x in values if x > 43]
Correct list comprehension.
Python
arr[71]
if (length(arr) >= 71) arr[71]
Check length.
R
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if bar = 55 then print('message') end
if bar == 55 then print('message') end
Use ==.
Lua
if index = 34:
if index == 34:
Use == for comparison.
Python
{{"name":"result",}}
{{"name":"result"}}
Remove trailing comma.
JSON
let text1 = String::from("result"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("result"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
<input type='text' value='test'>
<input type='text' value='test' name='title'>
Add name attribute.
HTML
if temp > 59 print('hello')
if temp > 59: print('hello')
Colon missing after if.
Python
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
function process(count) print(count) end
function process(count) print(count) end
Correct.
Lua
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(81);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(81);
Correct.
Node.js
$values[37]
if ($values.Count -gt 37) {{ $values[37] }}
Check bounds.
PowerShell
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
x = 70
x=70
No spaces.
Shell
let v=vec![78,31,14]; let first=&v[0]; v.push(79);
let mut v=vec![78,31,14]; let first=v[0]; v.push(79);
Copy instead of reference.
Rust
def test puts 'data' end
def test puts 'data' end
Correct.
Ruby
<p>value <b>data</p></b>
<p>value <b>data</b></p>
Nest properly.
HTML
{{'id':73, 'value' 6}}
{{'id':73, 'value':6}}
Colon missing.
Python
<br></br>
<br>
Self-closing.
HTML
data == '88'
data === 88
Use strict equality.
JavaScript
WHERE age = '28'
WHERE age = 28
Don't quote integer.
SQL
function handle() {{ return {{key:'test'}} }}
function handle() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
if (c = 59)
if (c == 59)
Use ==.
C++
count = message
count = 'message'
Quote strings.
Python
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
if (c = 83) {{}}
if (c == 83) {{}}
Use ==.
Kotlin
INSERT INTO items VALUES ('value',30)
INSERT INTO items (name, email) VALUES ('value',30);
Specify columns.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java