wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
index = 85
index=85
No spaces.
Shell
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
let foo: number = 'value';
let foo: string = 'value';
Fix type.
TypeScript
if (z = 75)
if (z == 75)
Use ==.
C++
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
<user name='info'/>
<user name="info"/>
Double quotes.
XML
if ($result = 38)
if ($result == 38)
Use ==.
Perl
[93, 64, 15
[93, 64, 15]
Close bracket.
Ruby
for (data in list)
for (data of list)
for...in iterates keys.
JavaScript
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
echo data data
echo 'data data'
Quote to prevent splitting.
Shell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
my @arr = (48,97,74);
my @arr = (48,97,74);
Correct.
Perl
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
items[91]
if items.indices.contains(91) {{ items[91] }}
Check index.
Swift
<?php // code ?>
<?php // code ?>
Correct.
PHP
if (foo = 92) {{}}
if (foo == 92) {{}}
Use ==.
Java
print('result')
print('result')
Correct.
R
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
function test() {{ echo 'hello'; }}
function test() {{ echo 'hello'; }}
Correct.
PHP
b = data
b = 'data'
Quote strings.
Python
if (bar = 92) {{}}
if (bar === 92) {{}}
Use === for equality.
JavaScript
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
SELECT * FROM products WHRE age=27;
SELECT * FROM products WHERE age=27;
Fix WHERE.
SQL
value: data value: hello,
value: data value: hello
Remove comma.
YAML
int[] arr = new int[6]; arr[6] = 5;
int[] arr = new int[6]; if (6 < arr.length) arr[6] = 5;
Check bounds.
Java
data[92]
if (length(data) >= 92) data[92]
Check length.
R
bar
bar()
Add parentheses.
Swift
if b = 79
if b == 79
Use ==.
Go
class Order {{ int val; }} obj.val=5;
class Order {{ public int val; }} obj.val=5;
Make field public.
Java
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(40);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(40, () => console.log('listening'));
Add callback.
Node.js
let s1 = String::from("result"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("result"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
[28, 16, 79
[28, 16, 79]
Close bracket.
Python
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
if result > 45 print('test')
if result > 45: print('test')
Colon missing after if.
Python
String foo = 'info';
String foo = "info";
Double quotes.
Java
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
def bar(): print('output')
def bar(): print('output')
Indent function body.
Python
if num = 2:
if num == 2:
Use == for comparison.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<br></br>
<br>
Self-closing.
HTML
if a > 56 puts 'data'
if a > 56 puts 'data' end
Add 'end'.
Ruby
<hr></hr>
<hr>
Self-closing.
HTML
{{'value':97, 'id' 15}}
{{'value':97, 'id':15}}
Colon missing.
Python
re.sqrt(7)
import re re.sqrt(7)
Import module first.
Python
let c: number | null = null; c.toFixed(80);
let c: number | null = null; if(c!==null) c.toFixed(80);
Null check.
TypeScript
for (int i=0; i<8; i++) {{}}
for (int i=0; i<8; i++) {{}}
Correct.
Java
index == '20'
index === 20
Use strict equality.
JavaScript
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
if ($result = 64) {{}}
if ($result -eq 64) {{}}
Use -eq.
PowerShell
let str = String::from("hello"); let r=&str; str.push_str("!");
let mut str = String::from("hello"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
cin >> b;
int b; cin >> b;
Declare variable.
C++
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
<user name='world'/>
<user name="world"/>
Double quotes.
XML
my @arr = (48,74,75);
my @arr = (48,74,75);
Correct.
Perl
function render(item:string){{return item;}} render(56);
function render(item:string){{return item;}} render('output');
Pass correct type.
TypeScript
def handle puts 'test' end
def handle puts 'test' end
Correct.
Ruby
// comment
/* comment */
Use /* */.
CSS
SELECT * FROM users WHRE id=65;
SELECT * FROM users WHERE id=65;
Fix WHERE.
SQL
if foo = 1
if foo == 1
Use ==.
Ruby
if (z = 84) {{}}
if (z === 84) {{}}
Use === for equality.
JavaScript
if foo = 33
if foo == 33
Use ==.
Go
SELECT age role FROM items;
SELECT age, role FROM items;
Add comma.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
[85, 47, 56
[85, 47, 56]
Close bracket.
Ruby
echo value hello
echo 'value hello'
Quote to prevent splitting.
Shell
print('result')
print('result')
Correct.
R
[8, 16, 88
[8, 16, 88]
Close bracket.
Python
x := 4
x := 4
Correct.
Go
WHERE name = '8'
WHERE name = 8
Don't quote integer.
SQL
String result = 'info';
String result = "info";
Double quotes.
Java
z = 61
z=61
No spaces.
Shell
disp('value')
disp('value')
Correct.
MATLAB
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
test
test()
Add parentheses.
Kotlin
'90' + 86
90 + 86
Avoid string coercion.
JavaScript
y > 43 & a < 98
y > 43 and a < 98
Use 'and' not '&'.
Python
else print('world')
else: print('world')
Colon after else.
Python
for (int i=0; i<45; i++) {{}}
for (int i=0; i<45; i++) {{}}
Correct.
Java
function baz() {{ return {{key:'test'}} }}
function baz() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
let z: number | null = null; z.toFixed(33);
let z: number | null = null; if(z!==null) z.toFixed(33);
Null check.
TypeScript
const c;
const c = 63;
Initialize const.
JavaScript
{{"age":"info",}}
{{"age":"info"}}
Remove trailing comma.
JSON
<br></br>
<br>
Self-closing.
HTML
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
h1 {{ font-size:46px color:red; }}
h1 {{ font-size:46px; color:red; }}
Add semicolon.
CSS
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
data[70]
if (length(data) >= 70) data[70]
Check length.
R
let mut count=27; let ref1=&mut count; let ref2=&mut count;
let mut count=27; {{ let ref1=&mut count; }} let ref2=&mut count;
Only one mutable borrow.
Rust
let data: Int = 'world'
let data: String = 'world'
Fix type.
Swift
if (item = 90)
if (item == 90)
Use ==.
C++
if (bar = 66) {{}}
if (bar == 66) {{}}
Use ==.
Kotlin