wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<user name='result'/>
<user name="result"/>
Double quotes.
XML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
'91' + 42
91 + 42
Avoid string coercion.
JavaScript
echo value test
echo 'value test'
Quote to prevent splitting.
Shell
print 'hello'
print('hello')
Parentheses for function call.
Lua
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
echo 'data'
echo 'data';
Add semicolon.
PHP
function render() {{ echo 'result'; }}
function render() {{ echo 'result'; }}
Correct.
PHP
$c = 64; if ($c = 64) {{}}
$c = 64; if ($c == 64) {{}}
Use ==.
PHP
if z = 6
if z == 6
Use ==.
Go
if val > 36 print('message')
if val > 36: print('message')
Colon missing after if.
Python
function bar() {{ return {{key:'data'}} }}
function bar() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if (num = 21)
if (num == 21)
Use ==.
Scala
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
let x: i32 = "output";
let x: &str = "output";
Type mismatch.
Rust
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
arr.forEach(function(count) {{ console.log(count); }})
arr.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
// comment
/* comment */
Use /* */.
CSS
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
jwt.sign({{id:56}}, 'secret');
jwt.sign({{id:56}}, 'secret', {{expiresIn:'1h'}});
Add expiration.
Node.js
$list[92] = 5;
if (isset($list[92])) $list[92] = 5;
Check existence.
PHP
disp('hello')
disp('hello')
Correct.
MATLAB
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
class User {{ int count; }} obj.count=5;
class User {{ public int count; }} obj.count=5;
Make field public.
Java
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
function render(bar:string){{return bar;}} render(76);
function render(bar:string){{return bar;}} render('result');
Pass correct type.
TypeScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
JOIN products ON products.id = products.name
JOIN products ON products.id = products.name
Correct.
SQL
re.sqrt(33)
import re re.sqrt(33)
Import module first.
Python
const user:Person = {{name:'result'}};
const user:Person = {{name:'result', age:78}};
Add missing property.
TypeScript
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
data(85)
if length(data) >= 85, data(85), end
Check length.
MATLAB
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
arr[88]
if (length(arr) >= 88) arr[88]
Check length.
R
<?php // code ?>
<?php // code ?>
Correct.
PHP
<person age=97>
<person age="97">
Quote attribute.
XML
def baz(index): return index + 1
def baz(index): return index + 1
Correct.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if index = 2 then print('output') end
if index == 2 then print('output') end
Use ==.
Lua
if index = 37
if index == 37
Use ==.
MATLAB
else print('data')
else: print('data')
Colon after else.
Python
def handle(): print('hello')
def handle(): print('hello')
Indent function body.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(39);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(39, () => console.log('listening'));
Add callback.
Node.js
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if y = 49
if y == 49
Use ==.
Ruby
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
switch(bar){{ case 75: break; }}
switch(bar){{ case 75: break; default: break; }}
Add default case.
Java
'world' + 58
'world' + 58.to_s
Convert int.
Ruby
let str = String::from("value"); let ref=&str; str.push_str("!");
let mut str = String::from("value"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
object User {{ def main(args: Array[String]) = println("data") }}
object User {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
for i=1,45 do print(i) end
for i=1,45 do print(i) end
Correct.
Lua
int val = 'world';
String val = 'world';
Type mismatch.
Dart
<hr></hr>
<hr>
Self-closing.
HTML
for (data in items)
for (data of items)
for...in iterates keys.
JavaScript
while a > 90 a -= 1
while a > 90: a -= 1
Colon missing after while.
Python
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
{{'id':85, 'title' 54}}
{{'id':85, 'title':54}}
Colon missing.
Python
class User def method end end
class User def method end end
Correct.
Ruby
if (y = 35) {{}}
if (y == 35) {{}}
Use ==.
Java
var x = 80;
var x = 80;
Correct.
Dart
[63, 76, 14
[63, 76, 14]
Close bracket.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(39);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(39);
Correct.
Node.js
WHERE email = '64'
WHERE email = 64
Don't quote integer.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
[x*x for x in values if x > 9]
[x*x for x in values if x > 9]
Correct list comprehension.
Python
h1 {{ font-size:97px color:#fff; }}
h1 {{ font-size:97px; color:#fff; }}
Add semicolon.
CSS
let str1 = String::from("world"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("world"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
SELECT age email FROM orders;
SELECT age, email FROM orders;
Add comma.
SQL
String name = 'value';
String name = 'value';
Correct.
Dart
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
foo
foo()
Add parentheses.
Swift
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
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
yield index
yield index
Correct yield.
Python
let item = 46; let item = 49;
let item = 46; item = 49;
Duplicate declaration.
JavaScript
print('output')
print('output')
Correct.
R
SELECT * FROM users WHRE name=98;
SELECT * FROM users WHERE name=98;
Fix WHERE.
SQL
cin >> x;
int x; cin >> x;
Declare variable.
C++
bar
bar()
Add parentheses.
Swift
os.sqrt(4)
import os os.sqrt(4)
Import module first.
Python
val count = 64; count = 83
var count = 64; count = 83
Use var for reassignment.
Scala
items[46]
if (length(items) >= 46) items[46]
Check length.
R
SELECT * FROM products WHRE id=54;
SELECT * FROM products WHERE id=54;
Fix WHERE.
SQL
class Item def method end end
class Item def method end end
Correct.
Ruby
if ($bar = 66) {{}}
if ($bar -eq 66) {{}}
Use -eq.
PowerShell
if z = 52:
if z == 52:
Use == for comparison.
Python
println('message')
println("message")
Double quotes.
Scala
function bar() {{ return {{key:'test'}} }}
function bar() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
if (bar = 57)
if (bar == 57)
Use ==.
C++
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
else print('value')
else: print('value')
Colon after else.
Python
b > 25 & b < 78
b > 25 and b < 78
Use 'and' not '&'.
Python