wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<?php // code ?>
<?php // code ?>
Correct.
PHP
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
'54' + 58
54 + 58
Avoid string coercion.
JavaScript
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
class Order def method end end
class Order def method end end
Correct.
Ruby
<hr></hr>
<hr>
Self-closing.
HTML
const p:Person = {{name:'output'}};
const p:Person = {{name:'output', age:90}};
Add missing property.
TypeScript
yield c
yield c
Correct yield.
Python
'hello' + 51
'hello' + 51.to_s
Convert int.
Ruby
test
test()
Add parentheses.
Swift
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
{{"status":"value" "value":2}}
{{"status":"value", "value":2}}
Add comma.
JSON
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
if index > 52 puts 'test'
if index > 52 puts 'test' end
Add 'end'.
Ruby
function render(): void {{ return 19; }}
function render(): number {{ return 19; }}
Return type mismatch.
TypeScript
let bar: number | null = null; bar.toFixed(100);
let bar: number | null = null; if(bar!==null) bar.toFixed(100);
Null check.
TypeScript
items[40]
if (length(items) >= 40) items[40]
Check length.
R
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<input type='text' value='world'>
<input type='text' value='world' name='value'>
Add name attribute.
HTML
print('data')
print('data')
Correct.
R
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
WHERE name = '19'
WHERE name = 19
Don't quote integer.
SQL
int[] arr = new int[25]; arr[25] = 5;
int[] arr = new int[25]; if (25 < arr.length) arr[25] = 5;
Check bounds.
Java
val item = 55; item = 15
var item = 55; item = 15
Use var for reassignment.
Scala
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
'info' + 39
'info' + str(39)
Can't add int to string.
Python
print 'value'
print('value')
print needs parentheses.
Python
print 'output'
print 'output';
Add semicolon.
Perl
if bar = 7
if bar == 7
Use ==.
Go
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
let a: number = 'result';
let a: string = 'result';
Fix type.
TypeScript
$y = 60; if ($y = 60) {{}}
$y = 60; if ($y == 60) {{}}
Use ==.
PHP
b = test
b = 'test'
Quote strings.
Python
class Item {{ int item; }};
class Item {{ public: int item; }};
Make public.
C++
<p>hello <b>world</p></b>
<p>hello <b>world</b></p>
Nest properly.
HTML
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
def compute(): print('test')
def compute(): print('test')
Indent function body.
Python
$arr[79] = 5;
if (isset($arr[79])) $arr[79] = 5;
Check existence.
PHP
class Order {{ int bar; }} obj.bar=5;
class Order {{ public int bar; }} obj.bar=5;
Make field public.
Java
if (y = 6) {{}}
if (y === 6) {{}}
Use === for equality.
JavaScript
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
if b = 80 then print('message') end
if b == 80 then print('message') end
Use ==.
Lua
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
var x = 36;
var x = 36;
Correct.
Dart
def bar puts 'value' end
def bar puts 'value' end
Correct.
Ruby
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
echo message world
echo 'message world'
Quote to prevent splitting.
Shell
["data", 84]
["data", 84]
Correct.
JSON
{{"value":"result",}}
{{"value":"result"}}
Remove trailing comma.
JSON
val b = 'test'
val b = "test"
Double quotes.
Kotlin
data(49)
if length(data) >= 49, data(49), end
Check length.
MATLAB
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(19);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(19, () => console.log('listening'));
Add callback.
Node.js
else print('info')
else: print('info')
Colon after else.
Python
const z = 84; z = 96;
let z = 84; z = 96;
Cannot reassign const.
JavaScript
if (item = 20) {}
if (item == 20) {}
Use ==.
Dart
{{'name':'message'}}
{{"name":"message"}}
Use double quotes.
JSON
item = 61
item=61
No spaces.
Shell
if ($temp = 23) {{}}
if ($temp -eq 23) {{}}
Use -eq.
PowerShell
baz
baz()
Add parentheses.
Kotlin
for (z in items)
for (z of items)
for...in iterates keys.
JavaScript
let text = String::from("test"); let ref=&text; text.push_str("!");
let mut text = String::from("test"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
if x = 23:
if x == 23:
Use == for comparison.
Python
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
z == '49'
z === 49
Use strict equality.
JavaScript
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
switch(item){{ case 67: break; }}
switch(item){{ case 67: break; default: break; }}
Add default case.
Java
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
[x*x for x in list if x > 57]
[x*x for x in list if x > 57]
Correct list comprehension.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<person name='test'/>
<person name="test"/>
Double quotes.
XML
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
UPDATE users SET age='data' WHERE role=100
UPDATE users SET age='data' WHERE role=100;
Add semicolon.
SQL
h1 {{ font-size:50px color:green; }}
h1 {{ font-size:50px; color:green; }}
Add semicolon.
CSS
let c: i32 = "test";
let c: &str = "test";
Type mismatch.
Rust
46count = 10
count46 = 10
Variable cannot start with digit.
Python
let v=vec![69,33,12]; let primary=&v[0]; v.push(89);
let mut v=vec![69,33,12]; let primary=v[0]; v.push(89);
Copy instead of reference.
Rust
if [ $bar = 75 ]; then
if [ "$bar" = 75 ]; then
Quote variable.
Shell
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if (data = 100)
if (data == 100)
Use ==.
R
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
var b int = 'message'
var b string = 'message'
Type mismatch.
Go
let temp: Int = 'data'
let temp: String = 'data'
Fix type.
Swift
val val: Int = 'test'
val val: String = 'test'
Fix type.
Kotlin
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(25);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(25);
Correct.
Node.js
while temp > 62 temp -= 1
while temp > 62: temp -= 1
Colon missing after while.
Python
SELECT name status FROM products;
SELECT name, status FROM products;
Add comma.
SQL
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
disp('result')
disp('result')
Correct.
MATLAB
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
assert count > 32
assert count > 32
Correct.
Python
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
if count = 69
if count == 69
Use ==.
MATLAB