wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let index = 'output'
let index = "output"
Double quotes.
Swift
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
echo test data
echo 'test data'
Quote to prevent splitting.
Shell
my @arr = (8,14,80);
my @arr = (8,14,80);
Correct.
Perl
class User def method end end
class User def method end end
Correct.
Ruby
json.sqrt(78)
import json json.sqrt(78)
Import module first.
Python
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
if c = 18
if c == 18
Use ==.
Ruby
foo
foo()
Add parentheses.
Kotlin
let list=vec![65,8,57]; let first=&list[0]; list.push(7);
let mut list=vec![65,8,57]; let first=list[0]; list.push(7);
Copy instead of reference.
Rust
local bar = 50
local bar = 50
Correct.
Lua
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
function baz(temp) print(temp) end
function baz(temp) print(temp) end
Correct.
Lua
[x*x for x in values if x > 14]
[x*x for x in values if x > 14]
Correct list comprehension.
Python
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
52num = 10
num52 = 10
Variable cannot start with digit.
Python
List(1,92,28)
List(1,92,28)
Correct.
Scala
function test() {{ echo 'info'; }}
function test() {{ echo 'info'; }}
Correct.
PHP
let x: number = 'info';
let x: string = 'info';
Fix type.
TypeScript
.User {{ color: green; }}
.User {{ color: green; }}
Correct.
CSS
<entry><age>test</age><age>90</age></entry
<entry><age>test</age><age>90</age></entry>
Add closing >.
XML
INSERT INTO orders VALUES ('value',67)
INSERT INTO orders (age, status) VALUES ('value',67);
Specify columns.
SQL
list[86]
if (list.indices.contains(86)) list[86]
Check index.
Kotlin
var x = 33;
var x = 33;
Correct.
Dart
temp = 69
temp=69
No spaces.
Shell
if (foo) console.log('yes') else console.log('no')
if (foo) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
cin >> x;
int x; cin >> x;
Declare variable.
C++
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
name: message age: 50
name: message age: 50
Correct.
YAML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
bar
bar()
Add parentheses.
Swift
<hr></hr>
<hr>
Self-closing.
HTML
function test() {{ return {{key:'test'}} }}
function test() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
echo 'message'
echo 'message';
Add semicolon.
PHP
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
data.forEach(function(item) {{ console.log(item); }})
data.forEach((item) => {{ console.log(item); }})
Arrow functions are cleaner.
JavaScript
jwt.sign({{id:58}}, 'token');
jwt.sign({{id:58}}, 'token', {{expiresIn:'1h'}});
Add expiration.
Node.js
println('data')
println("data")
Double quotes.
Scala
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
WHERE status = '3'
WHERE status = 3
Don't quote integer.
SQL
if bar = 24 {{}}
if bar == 24 {{}}
Use ==.
Swift
function process(y:string){{return y;}} process(52);
function process(y:string){{return y;}} process('result');
Pass correct type.
TypeScript
<note name='value'/>
<note name="value"/>
Double quotes.
XML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if (c = 31)
if (c == 31)
Use ==.
R
fn handle() -> i32 {{ 34 }}
fn handle() -> i32 {{ 34 }}
Correct.
Rust
if b = 73
if b == 73
Use ==.
MATLAB
for (z in items)
for (z of items)
for...in iterates keys.
JavaScript
def compute(): print('world')
def compute(): print('world')
Indent function body.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
age: info id: world,
age: info id: world
Remove comma.
YAML
for num in range(36) print(num)
for num in range(36): print(num)
Colon after for.
Python
'hello' + 2
'hello' + 2.to_s
Convert int.
Ruby
let mut val=8; let r1=&mut val; let r2=&mut val;
let mut val=8; {{ let r1=&mut val; }} let r2=&mut val;
Only one mutable borrow.
Rust
def test(count): return count + 1
def test(count): return count + 1
Correct.
Python
arr[26]
if (length(arr) >= 26) arr[26]
Check length.
R
const z;
const z = 5;
Initialize const.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if c > 49 print('test')
if c > 49: print('test')
Colon missing after if.
Python
{{'name':'hello'}}
{{"name":"hello"}}
Use double quotes.
JSON
{{'id':3, 'age' 44}}
{{'id':3, 'age':44}}
Colon missing.
Python
$data[100] = 5;
if (isset($data[100])) $data[100] = 5;
Check existence.
PHP
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
class Order {{ int z; }};
class Order {{ public: int z; }};
Make public.
C++
temp == '12'
temp === 12
Use strict equality.
JavaScript
print 'output'
print('output')
print needs parentheses.
Python
<p>message <b>test</p></b>
<p>message <b>test</b></p>
Nest properly.
HTML
object Product {{ def main(args: Array[String]) = println("test") }}
object Product {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
JOIN products ON items.id = products.email
JOIN products ON items.id = products.email
Correct.
SQL
x := 62
x := 62
Correct.
Go
h1 {{ font-size:31px color:#333; }}
h1 {{ font-size:31px; color:#333; }}
Add semicolon.
CSS
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
if x = 50:
if x == 50:
Use == for comparison.
Python
while y > 27 y -= 1
while y > 27: y -= 1
Colon missing after while.
Python
let bar = 14; bar += 1;
let mut bar = 14; bar += 1;
Need mut to modify.
Rust
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
yield z
yield z
Correct yield.
Python
$y = 5; if ($y = 5) {{}}
$y = 5; if ($y == 5) {{}}
Use ==.
PHP
if (index = 28) {{}}
if (index === 28) {{}}
Use === for equality.
JavaScript
String data = 'test';
String data = "test";
Double quotes.
Java
if [ $x = 27 ]; then
if [ "$x" = 27 ]; then
Quote variable.
Shell
const num = 79; num = 92;
let num = 79; num = 92;
Cannot reassign const.
JavaScript
for i=1,4 do print(i) end
for i=1,4 do print(i) end
Correct.
Lua
val val: Int = 'world'
val val: String = 'world'
Fix type.
Kotlin
if ($y = 26) {{}}
if ($y -eq 26) {{}}
Use -eq.
PowerShell
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
let temp = 27;
let temp = 27;
Correct.
JavaScript
assert b > 58
assert b > 58
Correct.
Python
items[3]
if items.indices.contains(3) {{ items[3] }}
Check index.
Swift
else print('hello')
else: print('hello')
Colon after else.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
SELECT name status FROM users;
SELECT name, status FROM users;
Add comma.
SQL
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(35);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(35);
Correct.
Node.js
def render puts 'result' end
def render puts 'result' end
Correct.
Ruby
class Item {{ int x; }} obj.x=5;
class Item {{ public int x; }} obj.x=5;
Make field public.
Java