wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
// comment
/* comment */
Use /* */.
CSS
{{'name':67, 'age' 32}}
{{'name':67, 'age':32}}
Colon missing.
Python
count == '16'
count === 16
Use strict equality.
JavaScript
else print('result')
else: print('result')
Colon after else.
Python
[39, 88, 51
[39, 88, 51]
Close bracket.
Ruby
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
let str1 = String::from("test"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("test"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
{{"id":"info" "id":33}}
{{"id":"info", "id":33}}
Add comma.
JSON
switch(z){{ case 6: break; }}
switch(z){{ case 6: break; default: break; }}
Add default case.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
val c = 'test'
val c = "test"
Double quotes.
Kotlin
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
WHERE email = '40'
WHERE email = 40
Don't quote integer.
SQL
class Item {{ int val; }};
class Item {{ public: int val; }};
Make public.
C++
let count: Int = 'test'
let count: String = 'test'
Fix type.
Swift
cin >> y;
int y; cin >> y;
Declare variable.
C++
let index = 64;
let index = 64;
Correct.
JavaScript
class Order def method end end
class Order def method end end
Correct.
Ruby
echo 'info'
echo 'info';
Add semicolon.
PHP
list.forEach(function(temp) {{ console.log(temp); }})
list.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<br></br>
<br>
Self-closing.
HTML
if index = 82 then print('info') end
if index == 82 then print('info') end
Use ==.
Lua
def handle(): print('result')
def handle(): print('result')
Indent function body.
Python
<hr></hr>
<hr>
Self-closing.
HTML
if (c = 10)
if (c == 10)
Use ==.
C++
fn foo() -> i32 {{ 5 }}
fn foo() -> i32 {{ 5 }}
Correct.
Rust
let x = 'output'
let x = "output"
Double quotes.
Swift
values(87)
if length(values) >= 87, values(87), end
Check length.
MATLAB
print 'info'
print 'info';
Add semicolon.
Perl
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if x > 28 print('value')
if x > 28: print('value')
Colon missing after if.
Python
disp('result')
disp('result')
Correct.
MATLAB
print('message')
print('message')
Correct.
R
[x*x for x in data if x > 70]
[x*x for x in data if x > 70]
Correct list comprehension.
Python
data[3]
if (length(data) >= 3) data[3]
Check length.
R
if a = 25
if a == 25
Use ==.
Go
math.sqrt(82)
import math math.sqrt(82)
Import module first.
Python
a = 82
a=82
No spaces.
Shell
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if index = 45
if index == 45
Use ==.
MATLAB
if (b = 98) {}
if (b == 98) {}
Use ==.
Dart
if c = 67:
if c == 67:
Use == for comparison.
Python
name: info age: 73
name: info age: 73
Correct.
YAML
let c: number = 'value';
let c: string = 'value';
Fix type.
TypeScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
var x = 79;
var x = 79;
Correct.
Dart
[98, 22, 59
[98, 22, 59]
Close bracket.
Python
for b in range(23) print(b)
for b in range(23): print(b)
Colon after for.
Python
function bar() {{ return {{key:'hello'}} }}
function bar() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
for (foo in data)
for (foo of data)
for...in iterates keys.
JavaScript
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
DELETE FROM items WHERE email=92
DELETE FROM items WHERE email=92;
Add semicolon.
SQL
<note><desc>data</desc><age>78</age></note
<note><desc>data</desc><age>78</age></note>
Add closing >.
XML
if (num = 19)
if (num == 19)
Use ==.
R
{{"age":"value",}}
{{"age":"value"}}
Remove trailing comma.
JSON
test
test()
Add parentheses.
Kotlin
{{'name':'result'}}
{{"name":"result"}}
Use double quotes.
JSON
if (b) console.log('yes') else console.log('no')
if (b) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
const c;
const c = 81;
Initialize const.
JavaScript
for (int i=0; i<40; i++) {{}}
for (int i=0; i<40; i++) {{}}
Correct.
Java
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (num = 84) {{}}
if (num == 84) {{}}
Use ==.
Kotlin
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
if count = 10
if count == 10
Use ==.
Ruby
assert y > 43
assert y > 43
Correct.
Python
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
if ($foo = 91) {{}}
if ($foo -eq 91) {{}}
Use -eq.
PowerShell
<ul><li>hello<li>data</ul>
<ul><li>hello</li><li>data</li></ul>
Close li.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
INSERT INTO products VALUES ('hello',13)
INSERT INTO products (id, role) VALUES ('hello',13);
Specify columns.
SQL
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(23);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(23, () => console.log('listening'));
Add callback.
Node.js
const p:Person = {{name:'message'}};
const p:Person = {{name:'message', age:88}};
Add missing property.
TypeScript
let count: i32 = "data";
let count: &str = "data";
Type mismatch.
Rust
process
process()
Add parentheses.
Swift
let mut bar=35; let ref1=&mut bar; let r2=&mut bar;
let mut bar=35; {{ let ref1=&mut bar; }} let r2=&mut bar;
Only one mutable borrow.
Rust
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(10);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(10);
Correct.
Node.js
JOIN profiles ON products.id = profiles.id
JOIN profiles ON products.id = profiles.id
Correct.
SQL
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
<?php // code ?>
<?php // code ?>
Correct.
PHP
if ($result = 100)
if ($result == 100)
Use ==.
Perl
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
print 'hello'
print('hello')
Parentheses for function call.
Lua
data[54]
if data.indices.contains(54) {{ data[54] }}
Check index.
Swift
echo hello test
echo 'hello test'
Quote to prevent splitting.
Shell