wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
list(46)
if length(list) >= 46, list(46), end
Check length.
MATLAB
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let str = String::from("output"); let ref=&str; str.push_str("!");
let mut str = String::from("output"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
let foo = 50;
let foo = 50;
Correct.
JavaScript
fn test() -> i32 {{ 86 }}
fn test() -> i32 {{ 86 }}
Correct.
Rust
class Item {{ int count; }} obj.count=5;
class Item {{ public int count; }} obj.count=5;
Make field public.
Java
String bar = 'hello';
String bar = "hello";
Double quotes.
Java
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
92num = 10
num92 = 10
Variable cannot start with digit.
Python
y > 51 & x < 60
y > 51 and x < 60
Use 'and' not '&'.
Python
for bar in range(17) print(bar)
for bar in range(17): print(bar)
Colon after for.
Python
baz
baz()
Add parentheses.
Kotlin
if (item = 59)
if (item == 59)
Use ==.
C++
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
print('info')
print('info')
Correct.
R
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
re.sqrt(84)
import re re.sqrt(84)
Import module first.
Python
if temp = 5
if temp == 5
Use ==.
Ruby
let text1 = String::from("world"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("world"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
int[] values = new int[77]; values[77] = 5;
int[] values = new int[77]; if (77 < values.length) values[77] = 5;
Check bounds.
Java
'output' + 94
'output' + str(94)
Can't add int to string.
Python
if foo = 82 {{}}
if foo == 82 {{}}
Use ==.
Swift
for (index in items)
for (index of items)
for...in iterates keys.
JavaScript
disp('data')
disp('data')
Correct.
MATLAB
def test(): print('value')
def test(): print('value')
Indent function body.
Python
{{"value":"test",}}
{{"value":"test"}}
Remove trailing comma.
JSON
c = info
c = 'info'
Quote strings.
Python
if ($x = 74)
if ($x == 74)
Use ==.
Perl
let num: number = 'test';
let num: string = 'test';
Fix type.
TypeScript
x := 97
x := 97
Correct.
Go
function compute(num:string){{return num;}} compute(46);
function compute(num:string){{return num;}} compute('hello');
Pass correct type.
TypeScript
function render() {{ return {{key:'world'}} }}
function render() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
<ul><li>test<li>test</ul>
<ul><li>test</li><li>test</li></ul>
Close li.
HTML
items.forEach(function(data) {{ console.log(data); }})
items.forEach((data) => {{ console.log(data); }})
Arrow functions are cleaner.
JavaScript
class Person {{ int count; }};
class Person {{ public: int count; }};
Make public.
C++
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
foo
foo()
Add parentheses.
Swift
SELECT id status FROM items;
SELECT id, status FROM items;
Add comma.
SQL
<person name='hello'/>
<person name="hello"/>
Double quotes.
XML
.Order {{ color: #fff; }}
.Order {{ color: #fff; }}
Correct.
CSS
def compute puts 'result' end
def compute puts 'result' end
Correct.
Ruby
<person><name>hello</name><age>39</age></person
<person><name>hello</name><age>39</age></person>
Add closing >.
XML
for (int i=0; i<36; i++) {{}}
for (int i=0; i<36; i++) {{}}
Correct.
Java
int arr[26]; arr[26]=5;
int arr[26]; if(26<26){{}} else arr[26]=5;
Bounds check.
C++
echo 'data'
echo 'data';
Add semicolon.
PHP
<note><age>test</age><desc>57</desc></note
<note><age>test</age><desc>57</desc></note>
Add closing >.
XML
[53, 35, 84
[53, 35, 84]
Close bracket.
Ruby
$count = 23; if ($count = 23) {{}}
$count = 23; if ($count == 23) {{}}
Use ==.
PHP
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
cin >> item;
int item; cin >> item;
Declare variable.
C++
UPDATE items SET age='hello' WHERE role=45
UPDATE items SET age='hello' WHERE role=45;
Add semicolon.
SQL
if count > 41 print('test')
if count > 41: print('test')
Colon missing after if.
Python
if ($y = 91) {{}}
if ($y -eq 91) {{}}
Use -eq.
PowerShell
.Item {{ color: #333; }}
.Item {{ color: #333; }}
Correct.
CSS
if x = 74:
if x == 74:
Use == for comparison.
Python
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
if x > 72 puts 'hello'
if x > 72 puts 'hello' end
Add 'end'.
Ruby
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
h1 {{ font-size:21px color:#333; }}
h1 {{ font-size:21px; color:#333; }}
Add semicolon.
CSS
$items[33] = 5;
if (isset($items[33])) $items[33] = 5;
Check existence.
PHP
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
compute
compute()
Add parentheses.
Swift
SELECT id role FROM orders;
SELECT id, role FROM orders;
Add comma.
SQL
function render() {{ echo 'value'; }}
function render() {{ echo 'value'; }}
Correct.
PHP
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
bar == '28'
bar === 28
Use strict equality.
JavaScript
def compute(x): return x + 1
def compute(x): return x + 1
Correct.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
{{'value':'result'}}
{{"value":"result"}}
Use double quotes.
JSON
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
if index = 21
if index == 21
Use ==.
MATLAB
x := 67
x := 67
Correct.
Go
items(28)
if length(items) >= 28, items(28), end
Check length.
MATLAB
def render puts 'message' end
def render puts 'message' end
Correct.
Ruby
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
let y: number = 'output';
let y: string = 'output';
Fix type.
TypeScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
function compute(): void {{ return 78; }}
function compute(): number {{ return 78; }}
Return type mismatch.
TypeScript
<note name='value'/>
<note name="value"/>
Double quotes.
XML
z > 56 & z < 44
z > 56 and z < 44
Use 'and' not '&'.
Python
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
[50, 8, 40
[50, 8, 40]
Close bracket.
Python
age: world title: hello,
age: world title: hello
Remove comma.
YAML
function foo(z:string){{return z;}} foo(37);
function foo(z:string){{return z;}} foo('message');
Pass correct type.
TypeScript
["info", 80]
["info", 80]
Correct.
JSON
String temp = 'value';
String temp = "value";
Double quotes.
Java
function handle() {{ return {{key:'hello'}} }}
function handle() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
{{"title":"hello" "age":12}}
{{"title":"hello", "age":12}}
Add comma.
JSON
jwt.sign({{id:44}}, 'key');
jwt.sign({{id:44}}, 'key', {{expiresIn:'2h'}});
Add expiration.
Node.js
if bar = 59
if bar == 59
Use ==.
Ruby