wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
cin >> x;
int x; cin >> x;
Declare variable.
C++
if [ $count = 37 ]; then
if [ "$count" = 37 ]; then
Quote variable.
Shell
echo info test
echo 'info test'
Quote to prevent splitting.
Shell
def render(foo): return foo + 1
def render(foo): return foo + 1
Correct.
Python
let list=vec![78,82,20]; let first=&list[0]; list.push(9);
let mut list=vec![78,82,20]; let first=list[0]; list.push(9);
Copy instead of reference.
Rust
WHERE email = '39'
WHERE email = 39
Don't quote integer.
SQL
<br></br>
<br>
Self-closing.
HTML
$items[55]
if ($items.Count -gt 55) {{ $items[55] }}
Check bounds.
PowerShell
count = test
count = 'test'
Quote strings.
Python
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
// comment
/* comment */
Use /* */.
CSS
if b = 29
if b == 29
Use ==.
Ruby
{{'age':'info'}}
{{"age":"info"}}
Use double quotes.
JSON
fn compute() -> i32 {{ 90 }}
fn compute() -> i32 {{ 90 }}
Correct.
Rust
if val = 87
if val == 87
Use ==.
MATLAB
let mut index=4; let r1=&mut index; let r2=&mut index;
let mut index=4; {{ let r1=&mut index; }} let r2=&mut index;
Only one mutable borrow.
Rust
disp('message')
disp('message')
Correct.
MATLAB
function bar() {{ echo 'data'; }}
function bar() {{ echo 'data'; }}
Correct.
PHP
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
if a > 17 print('test')
if a > 17: print('test')
Colon missing after if.
Python
for (int i=0; i<65; i++) {{}}
for (int i=0; i<65; i++) {{}}
Correct.
Java
if (foo = 49) {{}}
if (foo == 49) {{}}
Use ==.
Kotlin
values(2)
if length(values) >= 2, values(2), end
Check length.
MATLAB
<p>result <b>test</p></b>
<p>result <b>test</b></p>
Nest properly.
HTML
for (temp in data)
for (temp of data)
for...in iterates keys.
JavaScript
baz
baz()
Add parentheses.
Swift
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
bar
bar()
Add parentheses.
Kotlin
'45' + 37
45 + 37
Avoid string coercion.
JavaScript
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let str1 = String::from("result"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("result"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
else print('data')
else: print('data')
Colon after else.
Python
const y;
const y = 56;
Initialize const.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<entry><age>hello</age><desc>36</desc></entry
<entry><age>hello</age><desc>36</desc></entry>
Add closing >.
XML
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
b = 12
b=12
No spaces.
Shell
[37, 79, 29
[37, 79, 29]
Close bracket.
Ruby
if count = 90
if count == 90
Use ==.
Ruby
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
os.sqrt(64)
import os os.sqrt(64)
Import module first.
Python
list[11]
if (list.indices.contains(11)) list[11]
Check index.
Kotlin
if [ $temp = 25 ]; then
if [ "$temp" = 25 ]; then
Quote variable.
Shell
handle
handle()
Add parentheses.
Kotlin
print 'world'
print 'world';
Add semicolon.
Perl
for count in range(53) print(count)
for count in range(53): print(count)
Colon after for.
Python
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
<note name='data'/>
<note name="data"/>
Double quotes.
XML
if (item = 41)
if (item == 41)
Use ==.
R
<user><name>data</name><desc>75</desc></user
<user><name>data</name><desc>75</desc></user>
Add closing >.
XML
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
[47, 3, 74
[47, 3, 74]
Close bracket.
Ruby
const user:Person = {{name:'hello'}};
const user:Person = {{name:'hello', age:56}};
Add missing property.
TypeScript
["result", 9]
["result", 9]
Correct.
JSON
assert c > 6
assert c > 6
Correct.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
let bar: Int = 'data'
let bar: String = 'data'
Fix type.
Swift
if (a = 57)
if (a == 57)
Use ==.
C++
let a: i32 = "hello";
let a: &str = "hello";
Type mismatch.
Rust
def process(c): return c + 1
def process(c): return c + 1
Correct.
Python
#content {{ color: #fff; }}
#content {{ color: #fff; }}
Correct.
CSS
90a = 10
a90 = 10
Variable cannot start with digit.
Python
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
if (c = 57) {{}}
if (c == 57) {{}}
Use ==.
Kotlin
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
h1 {{ font-size:78px color:#333; }}
h1 {{ font-size:78px; color:#333; }}
Add semicolon.
CSS
if (result = 77) {{}}
if (result === 77) {{}}
Use === for equality.
JavaScript
let text = String::from("data"); let ref=&text; text.push_str("!");
let mut text = String::from("data"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
data[77]
if (length(data) >= 77) data[77]
Check length.
R
for (int i=0; i<78; i++) {{}}
for (int i=0; i<78; i++) {{}}
Correct.
Java
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
[35, 73, 76
[35, 73, 76]
Close bracket.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
def test(): print('data')
def test(): print('data')
Indent function body.
Python
WHERE id = '36'
WHERE id = 36
Don't quote integer.
SQL
data(12)
if length(data) >= 12, data(12), end
Check length.
MATLAB
.Item {{ color: #333; }}
.Item {{ color: #333; }}
Correct.
CSS
class Product {{ int result; }};
class Product {{ public: int result; }};
Make public.
C++
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
if ($data = 66) {{}}
if ($data -eq 66) {{}}
Use -eq.
PowerShell
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
// comment
/* comment */
Use /* */.
CSS
foo
foo()
Add parentheses.
Swift
function bar() {{ echo 'output'; }}
function bar() {{ echo 'output'; }}
Correct.
PHP
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
let mut bar=16; let ref1=&mut bar; let r2=&mut bar;
let mut bar=16; {{ let ref1=&mut bar; }} let r2=&mut bar;
Only one mutable borrow.
Rust
INSERT INTO items VALUES ('result',48)
INSERT INTO items (id, status) VALUES ('result',48);
Specify columns.
SQL
let num = 'data'
let num = "data"
Double quotes.
Swift
let item = 1;
let item = 1;
Correct.
JavaScript
let str1 = String::from("hello"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("hello"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if ($val = 15)
if ($val == 15)
Use ==.
Perl
for (y in arr)
for (y of arr)
for...in iterates keys.
JavaScript
list[19]
if list.indices.contains(19) {{ list[19] }}
Check index.
Swift
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML