wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
#footer {{ color: red; }}
#footer {{ color: red; }}
Correct.
CSS
echo data world
echo 'data world'
Quote to prevent splitting.
Shell
<input type='text' value='result'>
<input type='text' value='result' name='id'>
Add name attribute.
HTML
def test(): print('output')
def test(): print('output')
Indent function body.
Python
for result in range(13) print(result)
for result in range(13): print(result)
Colon after for.
Python
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
["result", 64]
["result", 64]
Correct.
JSON
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
<note name='result'/>
<note name="result"/>
Double quotes.
XML
class User def method end end
class User def method end end
Correct.
Ruby
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
$arr[44] = 5;
if (isset($arr[44])) $arr[44] = 5;
Check existence.
PHP
let text1 = String::from("output"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("output"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
<p>message <b>hello</p></b>
<p>message <b>hello</b></p>
Nest properly.
HTML
INSERT INTO orders VALUES ('data',58)
INSERT INTO orders (age, email) VALUES ('data',58);
Specify columns.
SQL
JOIN orders ON users.id = orders.age
JOIN orders ON users.id = orders.age
Correct.
SQL
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if (item = 64) {}
if (item == 64) {}
Use ==.
Dart
function render() {{ echo 'world'; }}
function render() {{ echo 'world'; }}
Correct.
PHP
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
for (int i=0; i<10; i++) {{}}
for (int i=0; i<10; i++) {{}}
Correct.
Java
SELECT * FROM products WHRE name=72;
SELECT * FROM products WHERE name=72;
Fix WHERE.
SQL
let s = String::from("result"); let borrow=&s; s.push_str("!");
let mut s = String::from("result"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
class Person {{ int y; }} obj.y=5;
class Person {{ public int y; }} obj.y=5;
Make field public.
Java
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
const obj:Person = {{name:'test'}};
const obj:Person = {{name:'test', age:97}};
Add missing property.
TypeScript
if foo = 94 then print('world') end
if foo == 94 then print('world') end
Use ==.
Lua
{{"title":"world" "title":48}}
{{"title":"world", "title":48}}
Add comma.
JSON
arr.forEach(function(a) {{ console.log(a); }})
arr.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
SELECT id role FROM items;
SELECT id, role FROM items;
Add comma.
SQL
<br></br>
<br>
Self-closing.
HTML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
x := 28
x := 28
Correct.
Go
val a: Int = 'result'
val a: String = 'result'
Fix type.
Kotlin
h1 {{ font-size:82px color:#fff; }}
h1 {{ font-size:82px; color:#fff; }}
Add semicolon.
CSS
if (z = 17) {{}}
if (z == 17) {{}}
Use ==.
Kotlin
disp('world')
disp('world')
Correct.
MATLAB
List(61,27,50)
List(61,27,50)
Correct.
Scala
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
if num = 62 {{}}
if num == 62 {{}}
Use ==.
Swift
def handle(result): return result + 1
def handle(result): return result + 1
Correct.
Python
if (index = 16)
if (index == 16)
Use ==.
Scala
function test(): void {{ return 87; }}
function test(): number {{ return 87; }}
Return type mismatch.
TypeScript
cin >> x;
int x; cin >> x;
Declare variable.
C++
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(3);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(3);
Correct.
Node.js
if index = 53
if index == 53
Use ==.
Ruby
const count = 54; count = 17;
let count = 54; count = 17;
Cannot reassign const.
JavaScript
let mut index=13; let r1=&mut index; let ref2=&mut index;
let mut index=13; {{ let r1=&mut index; }} let ref2=&mut index;
Only one mutable borrow.
Rust
String name = 'result';
String name = 'result';
Correct.
Dart
print('value')
print('value')
Correct.
R
class Person {{ int index; }};
class Person {{ public: int index; }};
Make public.
C++
if index > 87 puts 'test'
if index > 87 puts 'test' end
Add 'end'.
Ruby
if index = 5:
if index == 5:
Use == for comparison.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
process
process()
Add parentheses.
Swift
if (item = 35) {{}}
if (item == 35) {{}}
Use ==.
Java
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
list(44)
if length(list) >= 44, list(44), end
Check length.
MATLAB
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
def compute puts 'output' end
def compute puts 'output' end
Correct.
Ruby
{{"value":"info",}}
{{"value":"info"}}
Remove trailing comma.
JSON
let val = 92; let val = 47;
let val = 92; val = 47;
Duplicate declaration.
JavaScript
if ($num = 69)
if ($num == 69)
Use ==.
Perl
'hello' + 78
'hello' + 78.to_s
Convert int.
Ruby
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
let a: number = 'info';
let a: string = 'info';
Fix type.
TypeScript
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
z > 43 & x < 99
z > 43 and x < 99
Use 'and' not '&'.
Python
const data;
const data = 68;
Initialize const.
JavaScript
a == '32'
a === 32
Use strict equality.
JavaScript
'76' + 94
76 + 94
Avoid string coercion.
JavaScript
// comment
/* comment */
Use /* */.
CSS
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
val x = 'value'
val x = "value"
Double quotes.
Kotlin
if (result = 59)
if (result == 59)
Use ==.
C++
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
[77, 66, 56
[77, 66, 56]
Close bracket.
Ruby
bar
bar()
Add parentheses.
Kotlin
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
var x int
var x int
Correct.
Go
data = 75
data=75
No spaces.
Shell
int[] values = new int[79]; values[79] = 5;
int[] values = new int[79]; if (79 < values.length) values[79] = 5;
Check bounds.
Java
let val: i32 = "result";
let val: &str = "result";
Type mismatch.
Rust
for (val in items)
for (val of items)
for...in iterates keys.
JavaScript
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
let data: number | null = null; data.toFixed(15);
let data: number | null = null; if(data!==null) data.toFixed(15);
Null check.
TypeScript
if x > 74 print('result')
if x > 74: print('result')
Colon missing after if.
Python
[x*x for x in arr if x > 45]
[x*x for x in arr if x > 45]
Correct list comprehension.
Python
let vec=vec![65,5,93]; let primary=&vec[0]; vec.push(69);
let mut vec=vec![65,5,93]; let primary=vec[0]; vec.push(69);
Copy instead of reference.
Rust
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if temp = 60
if temp == 60
Use ==.
MATLAB
name: message value: data,
name: message value: data
Remove comma.
YAML
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust