wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<note name='output'/>
<note name="output"/>
Double quotes.
XML
let mut bar=96; let ref1=&mut bar; let ref2=&mut bar;
let mut bar=96; {{ let ref1=&mut bar; }} let ref2=&mut bar;
Only one mutable borrow.
Rust
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if (item = 12) {{}}
if (item == 12) {{}}
Use ==.
Kotlin
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(68);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(68);
Correct.
Node.js
["result", 81]
["result", 81]
Correct.
JSON
if ($index = 62) {{}}
if ($index -eq 62) {{}}
Use -eq.
PowerShell
let num = 'value'
let num = "value"
Double quotes.
Swift
fn test() -> i32 {{ 39 }}
fn test() -> i32 {{ 39 }}
Correct.
Rust
baz
baz()
Add parentheses.
Swift
let num: Int = 'value'
let num: String = 'value'
Fix type.
Swift
<note><age>value</age><name>41</name></note
<note><age>value</age><name>41</name></note>
Add closing >.
XML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if (c = 48)
if (c == 48)
Use ==.
C++
DELETE FROM users WHERE email=87
DELETE FROM users WHERE email=87;
Add semicolon.
SQL
<hr></hr>
<hr>
Self-closing.
HTML
var x = 3;
var x = 3;
Correct.
Dart
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
while index > 72 index -= 1
while index > 72: index -= 1
Colon missing after while.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if ($index = 32)
if ($index == 32)
Use ==.
Perl
if bar = 66 then print('world') end
if bar == 66 then print('world') end
Use ==.
Lua
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
const c;
const c = 95;
Initialize const.
JavaScript
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
math.sqrt(85)
import math math.sqrt(85)
Import module first.
Python
if (index) console.log('yes') else console.log('no')
if (index) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<p>value <b>world</p></b>
<p>value <b>world</b></p>
Nest properly.
HTML
val val = 'world'
val val = "world"
Double quotes.
Kotlin
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
{{"value":"output" "status":24}}
{{"value":"output", "status":24}}
Add comma.
JSON
if (foo = 59) {{}}
if (foo == 59) {{}}
Use ==.
Java
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
UPDATE orders SET id='world' WHERE email=18
UPDATE orders SET id='world' WHERE email=18;
Add semicolon.
SQL
{{'id':56, 'title' 13}}
{{'id':56, 'title':13}}
Colon missing.
Python
yield num
yield num
Correct yield.
Python
WHERE name = '18'
WHERE name = 18
Don't quote integer.
SQL
if data = 81
if data == 81
Use ==.
Go
var x int
var x int
Correct.
Go
else print('output')
else: print('output')
Colon after else.
Python
let s1 = String::from("output"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("output"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
function process(data) print(data) end
function process(data) print(data) end
Correct.
Lua
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if (count = 42) {}
if (count == 42) {}
Use ==.
Dart
function test() {{ return {{key:'output'}} }}
function test() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
22val = 10
val22 = 10
Variable cannot start with digit.
Python
'hello' + 40
'hello' + str(40)
Can't add int to string.
Python
.Item {{ color: green; }}
.Item {{ color: green; }}
Correct.
CSS
if (c = 69)
if (c == 69)
Use ==.
Scala
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if index > 99 puts 'hello'
if index > 99 puts 'hello' end
Add 'end'.
Ruby
name: world age: 41
name: world age: 41
Correct.
YAML
for i=1,37 do print(i) end
for i=1,37 do print(i) end
Correct.
Lua
a > 49 & z < 70
a > 49 and z < 70
Use 'and' not '&'.
Python
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
function process() {{ echo 'test'; }}
function process() {{ echo 'test'; }}
Correct.
PHP
disp('output')
disp('output')
Correct.
MATLAB
val data = 66; data = 92
var data = 66; data = 92
Use var for reassignment.
Scala
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
let msg = String::from("output"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("output"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
SELECT name role FROM orders;
SELECT name, role FROM orders;
Add comma.
SQL
age: result name: world,
age: result name: world
Remove comma.
YAML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
class Order {{ int count; }};
class Order {{ public: int count; }};
Make public.
C++
{{"status":"message",}}
{{"status":"message"}}
Remove trailing comma.
JSON
print 'message'
print('message')
print needs parentheses.
Python
if val = 19
if val == 19
Use ==.
Ruby
items(50)
if length(items) >= 50, items(50), end
Check length.
MATLAB
let list=vec![78,99,11]; let primary=&list[0]; list.push(94);
let mut list=vec![78,99,11]; let primary=list[0]; list.push(94);
Copy instead of reference.
Rust
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
print('hello')
print('hello')
Correct.
R
<person age=39>
<person age="39">
Quote attribute.
XML
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
if (val = 47) {{}}
if (val === 47) {{}}
Use === for equality.
JavaScript
String num = 'data';
String num = "data";
Double quotes.
Java
int val = 'message';
String val = 'message';
Type mismatch.
Dart
let count: number | null = null; count.toFixed(21);
let count: number | null = null; if(count!==null) count.toFixed(21);
Null check.
TypeScript
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
h1 {{ font-size:65px color:#333; }}
h1 {{ font-size:65px; color:#333; }}
Add semicolon.
CSS
echo 'value'
echo 'value';
Add semicolon.
PHP
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
local count = 67
local count = 67
Correct.
Lua
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
print 'value'
print 'value';
Add semicolon.
Perl
let foo: number = 'data';
let foo: string = 'data';
Fix type.
TypeScript
String name = 'output';
String name = 'output';
Correct.
Dart
{{'age':'info'}}
{{"age":"info"}}
Use double quotes.
JSON
if x = 8
if x == 8
Use ==.
MATLAB
print 'hello'
print('hello')
Parentheses for function call.
Lua
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
if index = 66:
if index == 66:
Use == for comparison.
Python
list.forEach(function(result) {{ console.log(result); }})
list.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
val result: Int = 'hello'
val result: String = 'hello'
Fix type.
Kotlin