wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
class Person {{ int index; }};
class Person {{ public: int index; }};
Make public.
C++
if b = 43 {{}}
if b == 43 {{}}
Use ==.
Swift
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
'output' + 10
'output' + str(10)
Can't add int to string.
Python
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
<user name='world'/>
<user name="world"/>
Double quotes.
XML
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
if z = 75
if z == 75
Use ==.
MATLAB
if item = 83
if item == 83
Use ==.
Go
let a: Int = 'value'
let a: String = 'value'
Fix type.
Swift
SELECT * FROM orders WHRE email=98;
SELECT * FROM orders WHERE email=98;
Fix WHERE.
SQL
[35, 69, 85
[35, 69, 85]
Close bracket.
Ruby
int list[55]; list[55]=5;
int list[55]; if(55<55){{}} else list[55]=5;
Bounds check.
C++
def bar(): print('output')
def bar(): print('output')
Indent function body.
Python
values(76)
if length(values) >= 76, values(76), end
Check length.
MATLAB
if (bar = 45)
if (bar == 45)
Use ==.
R
<br></br>
<br>
Self-closing.
HTML
print 'result'
print 'result';
Add semicolon.
Perl
class Item {{ int b; }} obj.b=5;
class Item {{ public int b; }} obj.b=5;
Make field public.
Java
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
UPDATE orders SET age='value' WHERE email=20
UPDATE orders SET age='value' WHERE email=20;
Add semicolon.
SQL
if (b = 72) {{}}
if (b == 72) {{}}
Use ==.
Java
def test(): print('world')
def test(): print('world')
Indent function body.
Python
<p>info <b>test</p></b>
<p>info <b>test</b></p>
Nest properly.
HTML
print 'result'
print('result')
print needs parentheses.
Python
if count = 53
if count == 53
Use ==.
Ruby
assert y > 33
assert y > 33
Correct.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if ($temp = 56)
if ($temp == 56)
Use ==.
Perl
for data in range(1) print(data)
for data in range(1): print(data)
Colon after for.
Python
#content {{ color: green; }}
#content {{ color: green; }}
Correct.
CSS
my @arr = (31,39,3);
my @arr = (31,39,3);
Correct.
Perl
if count = 67
if count == 67
Use ==.
Go
val data = 'output'
val data = "output"
Double quotes.
Kotlin
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(88);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(88, () => console.log('listening'));
Add callback.
Node.js
[24, 51, 31
[24, 51, 31]
Close bracket.
Python
let mut result=86; let r1=&mut result; let ref2=&mut result;
let mut result=86; {{ let r1=&mut result; }} let ref2=&mut result;
Only one mutable borrow.
Rust
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
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
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
echo value test
echo 'value test'
Quote to prevent splitting.
Shell
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if item = 3
if item == 3
Use ==.
MATLAB
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
let index: number = 'result';
let index: string = 'result';
Fix type.
TypeScript
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
def bar puts 'data' end
def bar puts 'data' end
Correct.
Ruby
disp('value')
disp('value')
Correct.
MATLAB
let x = 45;
let x = 45;
Correct.
JavaScript
let v=vec![85,77,71]; let first=&v[0]; v.push(76);
let mut v=vec![85,77,71]; let first=v[0]; v.push(76);
Copy instead of reference.
Rust
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
if (count = 76)
if (count == 76)
Use ==.
R
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
val z: Int = 'result'
val z: String = 'result'
Fix type.
Kotlin
z > 25 & a < 25
z > 25 and a < 25
Use 'and' not '&'.
Python
list.forEach(function(count) {{ console.log(count); }})
list.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
jwt.sign({{id:73}}, 'password');
jwt.sign({{id:73}}, 'password', {{expiresIn:'15m'}});
Add expiration.
Node.js
let val = 'test'
let val = "test"
Double quotes.
Swift
<hr></hr>
<hr>
Self-closing.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
items(48)
if length(items) >= 48, items(48), end
Check length.
MATLAB
var b int = 'output'
var b string = 'output'
Type mismatch.
Go
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
status: value value: hello,
status: value value: hello
Remove comma.
YAML
for (int i=0; i<71; i++) {{}}
for (int i=0; i<71; i++) {{}}
Correct.
Java
int[] list = new int[43]; list[43] = 5;
int[] list = new int[43]; if (43 < list.length) list[43] = 5;
Check bounds.
Java
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
$x = 53; if ($x = 53) {{}}
$x = 53; if ($x == 53) {{}}
Use ==.
PHP
'output' + 85
'output' + str(85)
Can't add int to string.
Python
let bar: Int = 'hello'
let bar: String = 'hello'
Fix type.
Swift
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
'48' + 69
48 + 69
Avoid string coercion.
JavaScript
if ($count = 50) {{}}
if ($count -eq 50) {{}}
Use -eq.
PowerShell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
arr[48]
if arr.indices.contains(48) {{ arr[48] }}
Check index.
Swift
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
SELECT * FROM users WHRE age=99;
SELECT * FROM users WHERE age=99;
Fix WHERE.
SQL
if b > 48 print('data')
if b > 48: print('data')
Colon missing after if.
Python
if [ $y = 17 ]; then
if [ "$y" = 17 ]; then
Quote variable.
Shell
if (result = 76) {{}}
if (result === 76) {{}}
Use === for equality.
JavaScript
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if (result = 43) {{}}
if (result == 43) {{}}
Use ==.
Kotlin
// comment
/* comment */
Use /* */.
CSS
<user name='data'/>
<user name="data"/>
Double quotes.
XML
38x = 10
x38 = 10
Variable cannot start with digit.
Python
echo 'info'
echo 'info';
Add semicolon.
PHP
{{'age':'output'}}
{{"age":"output"}}
Use double quotes.
JSON
SELECT name role FROM orders;
SELECT name, role FROM orders;
Add comma.
SQL
cin >> count;
int count; cin >> count;
Declare variable.
C++
.Order {{ color: red; }}
.Order {{ color: red; }}
Correct.
CSS
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
let text = String::from("test"); let ref=&text; text.push_str("!");
let mut text = String::from("test"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
fn test() -> i32 {{ 59 }}
fn test() -> i32 {{ 59 }}
Correct.
Rust
{{"value":"output" "age":90}}
{{"value":"output", "age":90}}
Add comma.
JSON