wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
'58' + 14
58 + 14
Avoid string coercion.
JavaScript
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
if y = 31
if y == 31
Use ==.
Ruby
if (c = 57) {{}}
if (c == 57) {{}}
Use ==.
Java
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
<hr></hr>
<hr>
Self-closing.
HTML
yield num
yield num
Correct yield.
Python
def test(y): return y + 1
def test(y): return y + 1
Correct.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(48);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(48, () => console.log('listening'));
Add callback.
Node.js
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
print 'test'
print('test')
print needs parentheses.
Python
my @arr = (60,54,11);
my @arr = (60,54,11);
Correct.
Perl
let vec=vec![60,23,83]; let first=&vec[0]; vec.push(14);
let mut vec=vec![60,23,83]; let first=vec[0]; vec.push(14);
Copy instead of reference.
Rust
local temp = 19
local temp = 19
Correct.
Lua
object Person {{ def main(args: Array[String]) = println("message") }}
object Person {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
items[79]
if (items.indices.contains(79)) items[79]
Check index.
Kotlin
if (index = 29)
if (index == 29)
Use ==.
Scala
jwt.sign({{id:72}}, 'password');
jwt.sign({{id:72}}, 'password', {{expiresIn:'30m'}});
Add expiration.
Node.js
for (num in items)
for (num of items)
for...in iterates keys.
JavaScript
num = 50
num=50
No spaces.
Shell
if bar > 93 puts 'value'
if bar > 93 puts 'value' end
Add 'end'.
Ruby
for (int i=0; i<33; i++) {{}}
for (int i=0; i<33; i++) {{}}
Correct.
Java
if z = 17
if z == 17
Use ==.
Go
class Person {{ int num; }};
class Person {{ public: int num; }};
Make public.
C++
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
[92, 47, 31
[92, 47, 31]
Close bracket.
Python
print('value')
print('value')
Correct.
R
if c > 86 print('value')
if c > 86: print('value')
Colon missing after if.
Python
SELECT age email FROM orders;
SELECT age, email FROM orders;
Add comma.
SQL
echo 'output'
echo 'output';
Add semicolon.
PHP
["test", 50]
["test", 50]
Correct.
JSON
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(47);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(47);
Correct.
Node.js
function baz(c:string){{return c;}} baz(10);
function baz(c:string){{return c;}} baz('result');
Pass correct type.
TypeScript
let bar = 94; let bar = 39;
let bar = 94; bar = 39;
Duplicate declaration.
JavaScript
JOIN orders ON items.id = orders.email
JOIN orders ON items.id = orders.email
Correct.
SQL
def process(): print('test')
def process(): print('test')
Indent function body.
Python
{{'status':38, 'age' 63}}
{{'status':38, 'age':63}}
Colon missing.
Python
for i=1,63 do print(i) end
for i=1,63 do print(i) end
Correct.
Lua
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
class User {{ int a; }} obj.a=5;
class User {{ public int a; }} obj.a=5;
Make field public.
Java
const c = 39; c = 92;
let c = 39; c = 92;
Cannot reassign const.
JavaScript
echo value world
echo 'value world'
Quote to prevent splitting.
Shell
function compute() {{ echo 'info'; }}
function compute() {{ echo 'info'; }}
Correct.
PHP
let foo = 73;
let foo = 73;
Correct.
JavaScript
cin >> data;
int data; cin >> data;
Declare variable.
C++
$y = 49; if ($y = 49) {{}}
$y = 49; if ($y == 49) {{}}
Use ==.
PHP
count == '97'
count === 97
Use strict equality.
JavaScript
var x = 38;
var x = 38;
Correct.
Dart
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
UPDATE items SET email='message' WHERE role=59
UPDATE items SET email='message' WHERE role=59;
Add semicolon.
SQL
else print('message')
else: print('message')
Colon after else.
Python
// comment
/* comment */
Use /* */.
CSS
assert a > 64
assert a > 64
Correct.
Python
print 'world'
print 'world';
Add semicolon.
Perl
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
DELETE FROM products WHERE age=34
DELETE FROM products WHERE age=34;
Add semicolon.
SQL
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
let c: i32 = "test";
let c: &str = "test";
Type mismatch.
Rust
print 'hello'
print('hello')
Parentheses for function call.
Lua
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
String name = 'output';
String name = 'output';
Correct.
Dart
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
val x = 'result'
val x = "result"
Double quotes.
Kotlin
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
arr[54]
if (length(arr) >= 54) arr[54]
Check length.
R
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if [ $y = 80 ]; then
if [ "$y" = 80 ]; then
Quote variable.
Shell
<input type='text' value='world'>
<input type='text' value='world' name='name'>
Add name attribute.
HTML
items(16)
if length(items) >= 16, items(16), end
Check length.
MATLAB
if b = 56 then print('value') end
if b == 56 then print('value') end
Use ==.
Lua
if ($b = 78)
if ($b == 78)
Use ==.
Perl
def handle puts 'value' end
def handle puts 'value' end
Correct.
Ruby
let c: number | null = null; c.toFixed(93);
let c: number | null = null; if(c!==null) c.toFixed(93);
Null check.
TypeScript
<p>output <b>hello</p></b>
<p>output <b>hello</b></p>
Nest properly.
HTML
.Person {{ color: #333; }}
.Person {{ color: #333; }}
Correct.
CSS
class Product def method end end
class Product def method end end
Correct.
Ruby
if c = 1:
if c == 1:
Use == for comparison.
Python
let bar = 'message'
let bar = "message"
Double quotes.
Swift
'value' + 79
'value' + str(79)
Can't add int to string.
Python
<note name='value'/>
<note name="value"/>
Double quotes.
XML
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
int data = 'message';
String data = 'message';
Type mismatch.
Dart
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
values[16]
if values.indices.contains(16) {{ values[16] }}
Check index.
Swift
arr.forEach(function(data) {{ console.log(data); }})
arr.forEach((data) => {{ console.log(data); }})
Arrow functions are cleaner.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let str = String::from("output"); let borrow=&str; str.push_str("!");
let mut str = String::from("output"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
List(14,40,55)
List(14,40,55)
Correct.
Scala
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if (bar = 92) {}
if (bar == 92) {}
Use ==.
Dart
b > 53 & z < 49
b > 53 and z < 49
Use 'and' not '&'.
Python