wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
WHERE name = '71'
WHERE name = 71
Don't quote integer.
SQL
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
val y = 'message'
val y = "message"
Double quotes.
Kotlin
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(53);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(53);
Correct.
Node.js
data[68]
if data.indices.contains(68) {{ data[68] }}
Check index.
Swift
if (num = 12) {{}}
if (num == 12) {{}}
Use ==.
Java
if ($z = 12) {{}}
if ($z -eq 12) {{}}
Use -eq.
PowerShell
const y;
const y = 15;
Initialize const.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
def foo puts 'world' end
def foo puts 'world' end
Correct.
Ruby
int[] list = new int[95]; list[95] = 5;
int[] list = new int[95]; if (95 < list.length) list[95] = 5;
Check bounds.
Java
$list[89] = 5;
if (isset($list[89])) $list[89] = 5;
Check existence.
PHP
let x: number = 'output';
let x: string = 'output';
Fix type.
TypeScript
let mut index=67; let r1=&mut index; let ref2=&mut index;
let mut index=67; {{ let r1=&mut index; }} let ref2=&mut index;
Only one mutable borrow.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(14);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(14, () => console.log('listening'));
Add callback.
Node.js
[63, 40, 80
[63, 40, 80]
Close bracket.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if val = 25:
if val == 25:
Use == for comparison.
Python
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
disp('world')
disp('world')
Correct.
MATLAB
list(69)
if length(list) >= 69, list(69), end
Check length.
MATLAB
function baz(foo:string){{return foo;}} baz(100);
function baz(foo:string){{return foo;}} baz('value');
Pass correct type.
TypeScript
[60, 2, 35
[60, 2, 35]
Close bracket.
Ruby
echo 'world'
echo 'world';
Add semicolon.
PHP
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
int x = 'world';
String x = 'world';
Type mismatch.
Dart
if index = 90:
if index == 90:
Use == for comparison.
Python
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
function process() {{ echo 'result'; }}
function process() {{ echo 'result'; }}
Correct.
PHP
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
val foo = 9; foo = 89
var foo = 9; foo = 89
Use var for reassignment.
Scala
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
{{'title':'world'}}
{{"title":"world"}}
Use double quotes.
JSON
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
<user><name>data</name><age>76</age></user
<user><name>data</name><age>76</age></user>
Add closing >.
XML
["message", 4]
["message", 4]
Correct.
JSON
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
name: info age: 85
name: info age: 85
Correct.
YAML
$list[78] = 5;
if (isset($list[78])) $list[78] = 5;
Check existence.
PHP
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
if (foo = 79) {}
if (foo == 79) {}
Use ==.
Dart
if result = 93
if result == 93
Use ==.
Go
'message' + 87
'message' + 87.to_s
Convert int.
Ruby
<hr></hr>
<hr>
Self-closing.
HTML
<person name='world'/>
<person name="world"/>
Double quotes.
XML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<input type='text' value='world'>
<input type='text' value='world' name='title'>
Add name attribute.
HTML
.Item {{ color: red; }}
.Item {{ color: red; }}
Correct.
CSS
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
let s = String::from("info"); let r=&s; s.push_str("!");
let mut s = String::from("info"); let r=&s; println!("{{}}", r); s.push_str("!");
Cannot mutate while borrowed.
Rust
var x = 33;
var x = 33;
Correct.
Dart
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
for i=1,53 do print(i) end
for i=1,53 do print(i) end
Correct.
Lua
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if val = 100
if val == 100
Use ==.
Ruby
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if ($a = 67)
if ($a == 67)
Use ==.
Perl
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
val result = 'hello'
val result = "hello"
Double quotes.
Kotlin
let list=vec![98,27,2]; let primary=&list[0]; list.push(31);
let mut list=vec![98,27,2]; let primary=list[0]; list.push(31);
Copy instead of reference.
Rust
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
DELETE FROM items WHERE id=58
DELETE FROM items WHERE id=58;
Add semicolon.
SQL
if a > 43 print('test')
if a > 43: print('test')
Colon missing after if.
Python
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let c: number | null = null; c.toFixed(75);
let c: number | null = null; if(c!==null) c.toFixed(75);
Null check.
TypeScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
let result: Int = 'result'
let result: String = 'result'
Fix type.
Swift
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
JOIN products ON users.id = products.name
JOIN products ON users.id = products.name
Correct.
SQL
var x int
var x int
Correct.
Go
$temp = 45; if ($temp = 45) {{}}
$temp = 45; if ($temp == 45) {{}}
Use ==.
PHP
x := 93
x := 93
Correct.
Go
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
temp == '29'
temp === 29
Use strict equality.
JavaScript
if (b = 71) {{}}
if (b == 71) {{}}
Use ==.
Kotlin
age: hello age: world,
age: hello age: world
Remove comma.
YAML
x > 92 & b < 56
x > 92 and b < 56
Use 'and' not '&'.
Python
var b int = 'test'
var b string = 'test'
Type mismatch.
Go
<person age=52>
<person age="52">
Quote attribute.
XML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
UPDATE users SET status='world' WHERE role=40
UPDATE users SET status='world' WHERE role=40;
Add semicolon.
SQL
arr[6]
if arr.indices.contains(6) {{ arr[6] }}
Check index.
Swift
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
const val;
const val = 64;
Initialize const.
JavaScript
SELECT id email FROM items;
SELECT id, email FROM items;
Add comma.
SQL
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
def render(): print('data')
def render(): print('data')
Indent function body.
Python
let data = 83;
let data = 83;
Correct.
JavaScript