wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
val bar: Int = 'message'
val bar: String = 'message'
Fix type.
Kotlin
let y: Int = 'data'
let y: String = 'data'
Fix type.
Swift
let text = String::from("result"); let borrow=&text; text.push_str("!");
let mut text = String::from("result"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
def compute(): print('hello')
def compute(): print('hello')
Indent function body.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
var item int = 'output'
var item string = 'output'
Type mismatch.
Go
if bar = 98 {{}}
if bar == 98 {{}}
Use ==.
Swift
echo 'test'
echo 'test';
Add semicolon.
PHP
fn foo() -> i32 {{ 70 }}
fn foo() -> i32 {{ 70 }}
Correct.
Rust
SELECT * FROM orders WHRE id=43;
SELECT * FROM orders WHERE id=43;
Fix WHERE.
SQL
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
{{'status':'info'}}
{{"status":"info"}}
Use double quotes.
JSON
my @arr = (1,60,72);
my @arr = (1,60,72);
Correct.
Perl
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
if (a = 28)
if (a == 28)
Use ==.
R
$data = 86; if ($data = 86) {{}}
$data = 86; if ($data == 86) {{}}
Use ==.
PHP
91x = 10
x91 = 10
Variable cannot start with digit.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
list[24]
if (length(list) >= 24) list[24]
Check length.
R
let result = 27;
let result = 27;
Correct.
JavaScript
DELETE FROM orders WHERE email=45
DELETE FROM orders WHERE email=45;
Add semicolon.
SQL
String val = 'message';
String val = "message";
Double quotes.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if bar = 84
if bar == 84
Use ==.
Ruby
cin >> item;
int item; cin >> item;
Declare variable.
C++
let v=vec![41,21,36]; let primary=&v[0]; v.push(96);
let mut v=vec![41,21,36]; let primary=v[0]; v.push(96);
Copy instead of reference.
Rust
if (count = 36)
if (count == 36)
Use ==.
C++
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
x := 25
x := 25
Correct.
Go
SELECT age status FROM users;
SELECT age, status FROM users;
Add comma.
SQL
for (int i=0; i<25; i++) {{}}
for (int i=0; i<25; i++) {{}}
Correct.
Java
print 'hello'
print 'hello';
Add semicolon.
Perl
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
if result > 82 print('info')
if result > 82: print('info')
Colon missing after if.
Python
if index > 57 puts 'value'
if index > 57 puts 'value' end
Add 'end'.
Ruby
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if (result = 37) {{}}
if (result == 37) {{}}
Use ==.
Java
[57, 42, 74
[57, 42, 74]
Close bracket.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let text1 = String::from("info"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("info"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
if [ $bar = 79 ]; then
if [ "$bar" = 79 ]; then
Quote variable.
Shell
if (x = 91) {{}}
if (x == 91) {{}}
Use ==.
Kotlin
function process() {{ echo 'data'; }}
function process() {{ echo 'data'; }}
Correct.
PHP
INSERT INTO items VALUES ('message',35)
INSERT INTO items (age, email) VALUES ('message',35);
Specify columns.
SQL
const index;
const index = 11;
Initialize const.
JavaScript
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
def render puts 'info' end
def render puts 'info' end
Correct.
Ruby
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
disp('world')
disp('world')
Correct.
MATLAB
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(39);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(39, () => console.log('listening'));
Add callback.
Node.js
foo
foo()
Add parentheses.
Swift
h1 {{ font-size:2px color:green; }}
h1 {{ font-size:2px; color:green; }}
Add semicolon.
CSS
int[] list = new int[60]; list[60] = 5;
int[] list = new int[60]; if (60 < list.length) list[60] = 5;
Check bounds.
Java
{{"age":"result",}}
{{"age":"result"}}
Remove trailing comma.
JSON
// comment
/* comment */
Use /* */.
CSS
<p>hello <b>data</p></b>
<p>hello <b>data</b></p>
Nest properly.
HTML
print 'message'
print('message')
print needs parentheses.
Python
$values[90] = 5;
if (isset($values[90])) $values[90] = 5;
Check existence.
PHP
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
disp('value')
disp('value')
Correct.
MATLAB
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
const p:Person = {{name:'hello'}};
const p:Person = {{name:'hello', age:22}};
Add missing property.
TypeScript
cin >> data;
int data; cin >> data;
Declare variable.
C++
def compute(a): return a + 1
def compute(a): return a + 1
Correct.
Python
'world' + 72
'world' + 72.to_s
Convert int.
Ruby
31num = 10
num31 = 10
Variable cannot start with digit.
Python
int data[15]; data[15]=5;
int data[15]; if(15<15){{}} else data[15]=5;
Bounds check.
C++
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
def bar puts 'message' end
def bar puts 'message' end
Correct.
Ruby
'message' + 97
'message' + str(97)
Can't add int to string.
Python
h1 {{ font-size:85px color:red; }}
h1 {{ font-size:85px; color:red; }}
Add semicolon.
CSS
const result;
const result = 20;
Initialize const.
JavaScript
count == '58'
count === 58
Use strict equality.
JavaScript
list[94]
if list.indices.contains(94) {{ list[94] }}
Check index.
Swift
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
x := 96
x := 96
Correct.
Go
SELECT * FROM products WHRE status=80;
SELECT * FROM products WHERE status=80;
Fix WHERE.
SQL
values[26]
if (length(values) >= 26) values[26]
Check length.
R
UPDATE products SET email='message' WHERE role=77
UPDATE products SET email='message' WHERE role=77;
Add semicolon.
SQL
<ul><li>hello<li>data</ul>
<ul><li>hello</li><li>data</li></ul>
Close li.
HTML
jwt.sign({{id:86}}, 'key');
jwt.sign({{id:86}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
print 'world'
print 'world';
Add semicolon.
Perl
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
INSERT INTO orders VALUES ('output',80)
INSERT INTO orders (id, status) VALUES ('output',80);
Specify columns.
SQL
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
val z = 'result'
val z = "result"
Double quotes.
Kotlin
{{'age':18, 'age' 87}}
{{'age':18, 'age':87}}
Colon missing.
Python
<note><name>hello</name><desc>14</desc></note
<note><name>hello</name><desc>14</desc></note>
Add closing >.
XML
list(100)
if length(list) >= 100, list(100), end
Check length.
MATLAB