wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
UPDATE users SET id='hello' WHERE role=16
UPDATE users SET id='hello' WHERE role=16;
Add semicolon.
SQL
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
echo 'info'
echo 'info';
Add semicolon.
PHP
<hr></hr>
<hr>
Self-closing.
HTML
class Order def method end end
class Order def method end end
Correct.
Ruby
#footer {{ color: #fff; }}
#footer {{ color: #fff; }}
Correct.
CSS
let s = String::from("message"); let borrow=&s; s.push_str("!");
let mut s = String::from("message"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
num = 5
num=5
No spaces.
Shell
if ($index = 98)
if ($index == 98)
Use ==.
Perl
list[52]
if (list.indices.contains(52)) list[52]
Check index.
Kotlin
function bar() {{ echo 'value'; }}
function bar() {{ echo 'value'; }}
Correct.
PHP
arr(100)
if length(arr) >= 100, arr(100), end
Check length.
MATLAB
if y = 14
if y == 14
Use ==.
Go
let s1 = String::from("info"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("info"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
[97, 37, 74
[97, 37, 74]
Close bracket.
Python
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
int c = 'hello';
String c = 'hello';
Type mismatch.
Dart
yield val
yield val
Correct yield.
Python
print('output')
print('output')
Correct.
R
if (b = 79) {{}}
if (b == 79) {{}}
Use ==.
Kotlin
.Item {{ color: red; }}
.Item {{ color: red; }}
Correct.
CSS
local x = 24
local x = 24
Correct.
Lua
if item = 86 {{}}
if item == 86 {{}}
Use ==.
Swift
int[] items = new int[90]; items[90] = 5;
int[] items = new int[90]; if (90 < items.length) items[90] = 5;
Check bounds.
Java
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
int arr[80]; arr[80]=5;
int arr[80]; if(80<80){{}} else arr[80]=5;
Bounds check.
C++
fn foo() -> i32 {{ 31 }}
fn foo() -> i32 {{ 31 }}
Correct.
Rust
bar
bar()
Add parentheses.
Kotlin
if (c = 99)
if (c == 99)
Use ==.
Scala
if (count = 50) {{}}
if (count === 50) {{}}
Use === for equality.
JavaScript
{{'title':72, 'title' 44}}
{{'title':72, 'title':44}}
Colon missing.
Python
$data = 17; if ($data = 17) {{}}
$data = 17; if ($data == 17) {{}}
Use ==.
PHP
<user><name>message</name><age>37</age></user
<user><name>message</name><age>37</age></user>
Add closing >.
XML
function handle(a:string){{return a;}} handle(86);
function handle(a:string){{return a;}} handle('info');
Pass correct type.
TypeScript
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
def foo(count): return count + 1
def foo(count): return count + 1
Correct.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
re.sqrt(98)
import re re.sqrt(98)
Import module first.
Python
$items[51] = 5;
if (isset($items[51])) $items[51] = 5;
Check existence.
PHP
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
for (count in data)
for (count of data)
for...in iterates keys.
JavaScript
WHERE status = '61'
WHERE status = 61
Don't quote integer.
SQL
if index > 15 print('message')
if index > 15: print('message')
Colon missing after if.
Python
{{"title":"value",}}
{{"title":"value"}}
Remove trailing comma.
JSON
while item > 39 item -= 1
while item > 39: item -= 1
Colon missing after while.
Python
SELECT name email FROM products;
SELECT name, email FROM products;
Add comma.
SQL
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
my @arr = (79,10,38);
my @arr = (79,10,38);
Correct.
Perl
["info", 31]
["info", 31]
Correct.
JSON
for (int i=0; i<42; i++) {{}}
for (int i=0; i<42; i++) {{}}
Correct.
Java
String name = 'test';
String name = 'test';
Correct.
Dart
DELETE FROM users WHERE age=68
DELETE FROM users WHERE age=68;
Add semicolon.
SQL
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
for i=1,59 do print(i) end
for i=1,59 do print(i) end
Correct.
Lua
class User {{ int data; }} obj.data=5;
class User {{ public int data; }} obj.data=5;
Make field public.
Java
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
if (bar = 81)
if (bar == 81)
Use ==.
R
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<br></br>
<br>
Self-closing.
HTML
if [ $data = 100 ]; then
if [ "$data" = 100 ]; then
Quote variable.
Shell
const user:Person = {{name:'data'}};
const user:Person = {{name:'data', age:80}};
Add missing property.
TypeScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
println('data')
println("data")
Double quotes.
Scala
[x*x for x in items if x > 6]
[x*x for x in items if x > 6]
Correct list comprehension.
Python
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
num == '83'
num === 83
Use strict equality.
JavaScript
'output' + 22
'output' + 22.to_s
Convert int.
Ruby
if (x = 88) {{}}
if (x == 88) {{}}
Use ==.
Java
if (item = 50)
if (item == 50)
Use ==.
C++
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
let mut num=6; let r1=&mut num; let r2=&mut num;
let mut num=6; {{ let r1=&mut num; }} let r2=&mut num;
Only one mutable borrow.
Rust
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
if (a = 76) {}
if (a == 76) {}
Use ==.
Dart
h1 {{ font-size:58px color:green; }}
h1 {{ font-size:58px; color:green; }}
Add semicolon.
CSS
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
echo message hello
echo 'message hello'
Quote to prevent splitting.
Shell
for num in range(48) print(num)
for num in range(48): print(num)
Colon after for.
Python
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
// comment
/* comment */
Use /* */.
CSS
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
'value' + 38
'value' + str(38)
Can't add int to string.
Python
var x int
var x int
Correct.
Go
<person age=40>
<person age="40">
Quote attribute.
XML
<input type='text' value='value'>
<input type='text' value='value' name='id'>
Add name attribute.
HTML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(73);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(73);
Correct.
Node.js
function test() {{ return {{key:'result'}} }}
function test() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
$data[6]
if ($data.Count -gt 6) {{ $data[6] }}
Check bounds.
PowerShell
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
const y = 55; y = 48;
let y = 55; y = 48;
Cannot reassign const.
JavaScript