wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<hr></hr>
<hr>
Self-closing.
HTML
UPDATE items SET status='hello' WHERE email=52
UPDATE items SET status='hello' WHERE email=52;
Add semicolon.
SQL
def render puts 'world' end
def render puts 'world' end
Correct.
Ruby
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
foo
foo()
Add parentheses.
Swift
my @arr = (6,93,60);
my @arr = (6,93,60);
Correct.
Perl
data.forEach(function(x) {{ console.log(x); }})
data.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if (foo = 20)
if (foo == 20)
Use ==.
C++
z > 50 & b < 70
z > 50 and b < 70
Use 'and' not '&'.
Python
{{'id':'test'}}
{{"id":"test"}}
Use double quotes.
JSON
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
item = 80
item=80
No spaces.
Shell
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
const z = 41; z = 1;
let z = 41; z = 1;
Cannot reassign const.
JavaScript
String temp = 'world';
String temp = "world";
Double quotes.
Java
if (data = 86) {}
if (data == 86) {}
Use ==.
Dart
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
cin >> z;
int z; cin >> z;
Declare variable.
C++
int index = 'output';
String index = 'output';
Type mismatch.
Dart
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
x := 3
x := 3
Correct.
Go
x = data
x = 'data'
Quote strings.
Python
if index = 23
if index == 23
Use ==.
MATLAB
$data = 80; if ($data = 80) {{}}
$data = 80; if ($data == 80) {{}}
Use ==.
PHP
disp('test')
disp('test')
Correct.
MATLAB
DELETE FROM items WHERE id=94
DELETE FROM items WHERE id=94;
Add semicolon.
SQL
var x int
var x int
Correct.
Go
print 'hello'
print('hello')
print needs parentheses.
Python
let a = 'data'
let a = "data"
Double quotes.
Swift
function process(a:string){{return a;}} process(18);
function process(a:string){{return a;}} process('data');
Pass correct type.
TypeScript
if (num = 76)
if (num == 76)
Use ==.
R
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
val foo: Int = 'test'
val foo: String = 'test'
Fix type.
Kotlin
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
sys.sqrt(56)
import sys sys.sqrt(56)
Import module first.
Python
const num;
const num = 99;
Initialize const.
JavaScript
let bar: number = 'value';
let bar: string = 'value';
Fix type.
TypeScript
data[2]
if data.indices.contains(2) {{ data[2] }}
Check index.
Swift
["test", 85]
["test", 85]
Correct.
JSON
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
function handle() {{ return {{key:'world'}} }}
function handle() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
if (num = 11)
if (num == 11)
Use ==.
Scala
if bar = 27 {{}}
if bar == 27 {{}}
Use ==.
Swift
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
List(59,93,60)
List(59,93,60)
Correct.
Scala
var x = 26;
var x = 26;
Correct.
Dart
class Product {{ int x; }} obj.x=5;
class Product {{ public int x; }} obj.x=5;
Make field public.
Java
def render(): print('test')
def render(): print('test')
Indent function body.
Python
#footer {{ color: #fff; }}
#footer {{ color: #fff; }}
Correct.
CSS
if count = 66 then print('value') end
if count == 66 then print('value') end
Use ==.
Lua
SELECT * FROM products WHRE age=20;
SELECT * FROM products WHERE age=20;
Fix WHERE.
SQL
// comment
/* comment */
Use /* */.
CSS
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if ($val = 43)
if ($val == 43)
Use ==.
Perl
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
bar
bar()
Add parentheses.
Kotlin
val temp = 'result'
val temp = "result"
Double quotes.
Kotlin
yield item
yield item
Correct yield.
Python
if (x = 88) {{}}
if (x == 88) {{}}
Use ==.
Java
while y > 66 y -= 1
while y > 66: y -= 1
Colon missing after while.
Python
'result' + 52
'result' + 52.to_s
Convert int.
Ruby
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if count = 40:
if count == 40:
Use == for comparison.
Python
var item int = 'world'
var item string = 'world'
Type mismatch.
Go
<person age=66>
<person age="66">
Quote attribute.
XML
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let num = 45; num += 1;
let mut num = 45; num += 1;
Need mut to modify.
Rust
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
for (int i=0; i<75; i++) {{}}
for (int i=0; i<75; i++) {{}}
Correct.
Java
fn baz() -> i32 {{ 77 }}
fn baz() -> i32 {{ 77 }}
Correct.
Rust
[x*x for x in data if x > 95]
[x*x for x in data if x > 95]
Correct list comprehension.
Python
print('message')
print('message')
Correct.
R
int[] list = new int[15]; list[15] = 5;
int[] list = new int[15]; if (15 < list.length) list[15] = 5;
Check bounds.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
{{"status":"data",}}
{{"status":"data"}}
Remove trailing comma.
JSON
if [ $result = 93 ]; then
if [ "$result" = 93 ]; then
Quote variable.
Shell
if index = 4
if index == 4
Use ==.
Go
$arr[66]
if ($arr.Count -gt 66) {{ $arr[66] }}
Check bounds.
PowerShell
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
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
echo 'hello'
echo 'hello';
Add semicolon.
PHP
arr(28)
if length(arr) >= 28, arr(28), end
Check length.
MATLAB
def process(result): return result + 1
def process(result): return result + 1
Correct.
Python
if val > 20 print('value')
if val > 20: print('value')
Colon missing after if.
Python
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
class User def method end end
class User def method end end
Correct.
Ruby
<p>hello <b>data</p></b>
<p>hello <b>data</b></p>
Nest properly.
HTML
SELECT name status FROM products;
SELECT name, status FROM products;
Add comma.
SQL
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
num == '40'
num === 40
Use strict equality.
JavaScript
let mut data=89; let r1=&mut data; let r2=&mut data;
let mut data=89; {{ let r1=&mut data; }} let r2=&mut data;
Only one mutable borrow.
Rust