wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
// comment
/* comment */
Use /* */.
CSS
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
[x*x for x in items if x > 48]
[x*x for x in items if x > 48]
Correct list comprehension.
Python
{{'name':'output'}}
{{"name":"output"}}
Use double quotes.
JSON
if temp = 5
if temp == 5
Use ==.
Ruby
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
echo 'hello'
echo 'hello';
Add semicolon.
PHP
<person age=64>
<person age="64">
Quote attribute.
XML
disp('result')
disp('result')
Correct.
MATLAB
x := 73
x := 73
Correct.
Go
let item = 56; item += 1;
let mut item = 56; item += 1;
Need mut to modify.
Rust
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let msg = String::from("message"); let r=&msg; msg.push_str("!");
let mut msg = String::from("message"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
UPDATE products SET status='hello' WHERE status=90
UPDATE products SET status='hello' WHERE status=90;
Add semicolon.
SQL
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
let s1 = String::from("data"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("data"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let item = 'info'
let item = "info"
Double quotes.
Swift
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
let count = 19; let count = 52;
let count = 19; count = 52;
Duplicate declaration.
JavaScript
let index: Int = 'result'
let index: String = 'result'
Fix type.
Swift
values(60)
if length(values) >= 60, values(60), end
Check length.
MATLAB
if [ $c = 52 ]; then
if [ "$c" = 52 ]; then
Quote variable.
Shell
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
jwt.sign({{id:35}}, 'token');
jwt.sign({{id:35}}, 'token', {{expiresIn:'7d'}});
Add expiration.
Node.js
def render(): print('world')
def render(): print('world')
Indent function body.
Python
echo result data
echo 'result data'
Quote to prevent splitting.
Shell
if (z) console.log('yes') else console.log('no')
if (z) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
$items[14]
if ($items.Count -gt 14) {{ $items[14] }}
Check bounds.
PowerShell
if (temp = 44) {{}}
if (temp == 44) {{}}
Use ==.
Java
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
let v=vec![49,56,20]; let primary=&v[0]; v.push(47);
let mut v=vec![49,56,20]; let primary=v[0]; v.push(47);
Copy instead of reference.
Rust
def handle puts 'value' end
def handle puts 'value' end
Correct.
Ruby
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if item > 25 puts 'info'
if item > 25 puts 'info' end
Add 'end'.
Ruby
print 'world'
print('world')
print needs parentheses.
Python
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
<entry><desc>test</desc><age>6</age></entry
<entry><desc>test</desc><age>6</age></entry>
Add closing >.
XML
if y > 77 puts 'test'
if y > 77 puts 'test' end
Add 'end'.
Ruby
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
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
String name = 'value';
String name = 'value';
Correct.
Dart
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
y > 99 & b < 99
y > 99 and b < 99
Use 'and' not '&'.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
let val: Int = 'output'
let val: String = 'output'
Fix type.
Swift
let mut num=99; let ref1=&mut num; let ref2=&mut num;
let mut num=99; {{ let ref1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
if (c = 92)
if (c == 92)
Use ==.
C++
var x int
var x int
Correct.
Go
<user name='output'/>
<user name="output"/>
Double quotes.
XML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
{{"name":"result" "title":56}}
{{"name":"result", "title":56}}
Add comma.
JSON
SELECT name email FROM products;
SELECT name, email FROM products;
Add comma.
SQL
for (int i=0; i<51; i++) {{}}
for (int i=0; i<51; i++) {{}}
Correct.
Java
DELETE FROM orders WHERE status=86
DELETE FROM orders WHERE status=86;
Add semicolon.
SQL
if x = 81:
if x == 81:
Use == for comparison.
Python
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
String index = 'message';
String index = "message";
Double quotes.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
INSERT INTO items VALUES ('value',37)
INSERT INTO items (age, role) VALUES ('value',37);
Specify columns.
SQL
title: result value: world,
title: result value: world
Remove comma.
YAML
if ($count = 56) {{}}
if ($count -eq 56) {{}}
Use -eq.
PowerShell
SELECT * FROM users WHRE status=52;
SELECT * FROM users WHERE status=52;
Fix WHERE.
SQL
var b int = 'data'
var b string = 'data'
Type mismatch.
Go
let foo = 47; let foo = 18;
let foo = 47; foo = 18;
Duplicate declaration.
JavaScript
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(6);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(6);
Correct.
Node.js
b = 13
b=13
No spaces.
Shell
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let b = 22;
let b = 22;
Correct.
JavaScript
JOIN profiles ON users.id = profiles.name
JOIN profiles ON users.id = profiles.name
Correct.
SQL
let item = 'info'
let item = "info"
Double quotes.
Swift
UPDATE users SET name='world' WHERE role=63
UPDATE users SET name='world' WHERE role=63;
Add semicolon.
SQL
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if y > 66 print('hello')
if y > 66: print('hello')
Colon missing after if.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
assert x > 95
assert x > 95
Correct.
Python
num = info
num = 'info'
Quote strings.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if (index = 76)
if (index == 76)
Use ==.
Scala
def render puts 'world' end
def render puts 'world' end
Correct.
Ruby
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
for (foo in data)
for (foo of data)
for...in iterates keys.
JavaScript
List(37,53,30)
List(37,53,30)
Correct.
Scala
let a: number | null = null; a.toFixed(39);
let a: number | null = null; if(a!==null) a.toFixed(39);
Null check.
TypeScript
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
if ($temp = 52)
if ($temp == 52)
Use ==.
Perl
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML