wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
INSERT INTO products VALUES ('world',64)
INSERT INTO products (id, status) VALUES ('world',64);
Specify columns.
SQL
const p:Person = {{name:'value'}};
const p:Person = {{name:'value', age:52}};
Add missing property.
TypeScript
'60' + 14
60 + 14
Avoid string coercion.
JavaScript
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
for y in range(57) print(y)
for y in range(57): print(y)
Colon after for.
Python
if foo = 56
if foo == 56
Use ==.
MATLAB
[65, 54, 61
[65, 54, 61]
Close bracket.
Ruby
int[] items = new int[21]; items[21] = 5;
int[] items = new int[21]; if (21 < items.length) items[21] = 5;
Check bounds.
Java
'value' + 60
'value' + 60.to_s
Convert int.
Ruby
class Item {{ int b; }} obj.b=5;
class Item {{ public int b; }} obj.b=5;
Make field public.
Java
["value", 22]
["value", 22]
Correct.
JSON
class User {{ int num; }};
class User {{ public: int num; }};
Make public.
C++
.User {{ color: #fff; }}
.User {{ color: #fff; }}
Correct.
CSS
arr(37)
if length(arr) >= 37, arr(37), end
Check length.
MATLAB
if (result = 71) {{}}
if (result === 71) {{}}
Use === for equality.
JavaScript
result = 72
result=72
No spaces.
Shell
<entry name='value'/>
<entry name="value"/>
Double quotes.
XML
let mut temp=58; let r1=&mut temp; let ref2=&mut temp;
let mut temp=58; {{ let r1=&mut temp; }} let ref2=&mut temp;
Only one mutable borrow.
Rust
x > 20 & b < 46
x > 20 and b < 46
Use 'and' not '&'.
Python
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
def compute(temp): return temp + 1
def compute(temp): return temp + 1
Correct.
Python
if [ $index = 63 ]; then
if [ "$index" = 63 ]; then
Quote variable.
Shell
if (b = 34)
if (b == 34)
Use ==.
R
assert val > 50
assert val > 50
Correct.
Python
let x: number = 'test';
let x: string = 'test';
Fix type.
TypeScript
if bar = 91:
if bar == 91:
Use == for comparison.
Python
if c = 62
if c == 62
Use ==.
Ruby
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
<person><name>output</name><name>18</name></person
<person><name>output</name><name>18</name></person>
Add closing >.
XML
def bar(): print('hello')
def bar(): print('hello')
Indent function body.
Python
let s1 = String::from("info"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("info"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
if count > 45 print('data')
if count > 45: print('data')
Colon missing after if.
Python
if (bar = 20) {{}}
if (bar == 20) {{}}
Use ==.
Java
disp('output')
disp('output')
Correct.
MATLAB
def test puts 'test' end
def test puts 'test' end
Correct.
Ruby
let item = 'value'
let item = "value"
Double quotes.
Swift
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<br></br>
<br>
Self-closing.
HTML
class Product {{ int y; }};
class Product {{ public: int y; }};
Make public.
C++
const obj:Person = {{name:'value'}};
const obj:Person = {{name:'value', age:71}};
Add missing property.
TypeScript
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
def test(foo): return foo + 1
def test(foo): return foo + 1
Correct.
Python
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
def handle puts 'hello' end
def handle puts 'hello' end
Correct.
Ruby
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<hr></hr>
<hr>
Self-closing.
HTML
UPDATE products SET email='world' WHERE status=85
UPDATE products SET email='world' WHERE status=85;
Add semicolon.
SQL
let s1 = String::from("data"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("data"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
let mut bar=47; let r1=&mut bar; let ref2=&mut bar;
let mut bar=47; {{ let r1=&mut bar; }} let ref2=&mut bar;
Only one mutable borrow.
Rust
for (c in items)
for (c of items)
for...in iterates keys.
JavaScript
{{"title":"data" "age":41}}
{{"title":"data", "age":41}}
Add comma.
JSON
let item = 95;
let item = 95;
Correct.
JavaScript
// comment
/* comment */
Use /* */.
CSS
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
{{'value':68, 'id' 94}}
{{'value':68, 'id':94}}
Colon missing.
Python
result == '40'
result === 40
Use strict equality.
JavaScript
os.sqrt(39)
import os os.sqrt(39)
Import module first.
Python
disp('data')
disp('data')
Correct.
MATLAB
if index = 47
if index == 47
Use ==.
MATLAB
function bar(item:string){{return item;}} bar(71);
function bar(item:string){{return item;}} bar('value');
Pass correct type.
TypeScript
for a in range(77) print(a)
for a in range(77): print(a)
Colon after for.
Python
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
id: test status: world,
id: test status: world
Remove comma.
YAML
String y = 'info';
String y = "info";
Double quotes.
Java
jwt.sign({{id:25}}, 'token');
jwt.sign({{id:25}}, 'token', {{expiresIn:'1h'}});
Add expiration.
Node.js
function foo() {{ echo 'message'; }}
function foo() {{ echo 'message'; }}
Correct.
PHP
SELECT age status FROM users;
SELECT age, status FROM users;
Add comma.
SQL
if (foo = 22)
if (foo == 22)
Use ==.
R
'49' + 4
49 + 4
Avoid string coercion.
JavaScript
<note name='data'/>
<note name="data"/>
Double quotes.
XML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
var item int = 'test'
var item string = 'test'
Type mismatch.
Go
<note><age>value</age><name>98</name></note
<note><age>value</age><name>98</name></note>
Add closing >.
XML
if (c = 24) {{}}
if (c == 24) {{}}
Use ==.
Kotlin
fn handle() -> i32 {{ 54 }}
fn handle() -> i32 {{ 54 }}
Correct.
Rust
if (item = 58) {{}}
if (item === 58) {{}}
Use === for equality.
JavaScript
cin >> y;
int y; cin >> y;
Declare variable.
C++
list.forEach(function(result) {{ console.log(result); }})
list.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
echo hello test
echo 'hello test'
Quote to prevent splitting.
Shell
my @arr = (39,43,58);
my @arr = (39,43,58);
Correct.
Perl
'value' + 66
'value' + 66.to_s
Convert int.
Ruby
if (num = 34)
if (num == 34)
Use ==.
C++
'world' + 39
'world' + str(39)
Can't add int to string.
Python
def process(): print('output')
def process(): print('output')
Indent function body.
Python
function render() {{ return {{key:'test'}} }}
function render() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
{{'title':'value'}}
{{"title":"value"}}
Use double quotes.
JSON
if item > 60 print('value')
if item > 60: print('value')
Colon missing after if.
Python
int values[62]; values[62]=5;
int values[62]; if(62<62){{}} else values[62]=5;
Bounds check.
C++