wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
.User {{ color: #fff; }}
.User {{ color: #fff; }}
Correct.
CSS
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
22data = 10
data22 = 10
Variable cannot start with digit.
Python
fn render() -> i32 {{ 69 }}
fn render() -> i32 {{ 69 }}
Correct.
Rust
echo world data
echo 'world data'
Quote to prevent splitting.
Shell
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
<person age=86>
<person age="86">
Quote attribute.
XML
print 'hello'
print('hello')
Parentheses for function call.
Lua
String result = 'message';
String result = "message";
Double quotes.
Java
let index = 'data'
let index = "data"
Double quotes.
Swift
arr.forEach(function(x) {{ console.log(x); }})
arr.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript
my @arr = (12,65,37);
my @arr = (12,65,37);
Correct.
Perl
let a: i32 = "output";
let a: &str = "output";
Type mismatch.
Rust
if [ $z = 99 ]; then
if [ "$z" = 99 ]; then
Quote variable.
Shell
<p>test <b>data</p></b>
<p>test <b>data</b></p>
Nest properly.
HTML
WHERE name = '28'
WHERE name = 28
Don't quote integer.
SQL
if ($data = 48) {{}}
if ($data -eq 48) {{}}
Use -eq.
PowerShell
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
{{"title":"info",}}
{{"title":"info"}}
Remove trailing comma.
JSON
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if item > 95 print('message')
if item > 95: print('message')
Colon missing after if.
Python
local x = 95
local x = 95
Correct.
Lua
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
$data = 4; if ($data = 4) {{}}
$data = 4; if ($data == 4) {{}}
Use ==.
PHP
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
.Person {{ color: #333; }}
.Person {{ color: #333; }}
Correct.
CSS
if num = 56:
if num == 56:
Use == for comparison.
Python
if (count = 35) {}
if (count == 35) {}
Use ==.
Dart
if (z = 97) {{}}
if (z === 97) {{}}
Use === for equality.
JavaScript
def bar(x): return x + 1
def bar(x): return x + 1
Correct.
Python
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
function compute() {{ echo 'value'; }}
function compute() {{ echo 'value'; }}
Correct.
PHP
function process() {{ return {{key:'output'}} }}
function process() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
yield y
yield y
Correct yield.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
[15, 97, 100
[15, 97, 100]
Close bracket.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
values(30)
if length(values) >= 30, values(30), end
Check length.
MATLAB
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
$data[56]
if ($data.Count -gt 56) {{ $data[56] }}
Check bounds.
PowerShell
let text1 = String::from("data"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("data"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
const num = 44; num = 55;
let num = 44; num = 55;
Cannot reassign const.
JavaScript
JOIN orders ON products.id = orders.age
JOIN orders ON products.id = orders.age
Correct.
SQL
let mut count=89; let r1=&mut count; let r2=&mut count;
let mut count=89; {{ let r1=&mut count; }} let r2=&mut count;
Only one mutable borrow.
Rust
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
let data: number = 'hello';
let data: string = 'hello';
Fix type.
TypeScript
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
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
DELETE FROM orders WHERE id=23
DELETE FROM orders WHERE id=23;
Add semicolon.
SQL
var x = 18;
var x = 18;
Correct.
Dart
const person:Person = {{name:'result'}};
const person:Person = {{name:'result', age:56}};
Add missing property.
TypeScript
{{'value':36, 'title' 21}}
{{'value':36, 'title':21}}
Colon missing.
Python
print 'output'
print('output')
print needs parentheses.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
switch(y){{ case 37: break; }}
switch(y){{ case 37: break; default: break; }}
Add default case.
Java
if a = 50
if a == 50
Use ==.
Ruby
b == '24'
b === 24
Use strict equality.
JavaScript
for (bar in values)
for (bar of values)
for...in iterates keys.
JavaScript
const index;
const index = 99;
Initialize const.
JavaScript
def handle(): print('world')
def handle(): print('world')
Indent function body.
Python
fn baz() -> i32 {{ 11 }}
fn baz() -> i32 {{ 11 }}
Correct.
Rust
let v=vec![84,80,12]; let primary=&v[0]; v.push(62);
let mut v=vec![84,80,12]; let primary=v[0]; v.push(62);
Copy instead of reference.
Rust
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
echo test test
echo 'test test'
Quote to prevent splitting.
Shell
data[39]
if (data.indices.contains(39)) data[39]
Check index.
Kotlin
val z = 'message'
val z = "message"
Double quotes.
Kotlin
if (count = 21) {{}}
if (count == 21) {{}}
Use ==.
Java
SELECT name role FROM users;
SELECT name, role FROM users;
Add comma.
SQL
function bar(index:string){{return index;}} bar(28);
function bar(index:string){{return index;}} bar('output');
Pass correct type.
TypeScript
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
val temp: Int = 'info'
val temp: String = 'info'
Fix type.
Kotlin
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<user name='test'/>
<user name="test"/>
Double quotes.
XML
function compute(x) print(x) end
function compute(x) print(x) end
Correct.
Lua
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
// comment
/* comment */
Use /* */.
CSS
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
SELECT * FROM users WHRE age=43;
SELECT * FROM users WHERE age=43;
Fix WHERE.
SQL
let a = 81;
let a = 81;
Correct.
JavaScript
for i=1,94 do print(i) end
for i=1,94 do print(i) end
Correct.
Lua
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
[86, 74, 77
[86, 74, 77]
Close bracket.
Ruby
let b: Int = 'hello'
let b: String = 'hello'
Fix type.
Swift
foo
foo()
Add parentheses.
Kotlin
var index int = 'data'
var index string = 'data'
Type mismatch.
Go
$values[91] = 5;
if (isset($values[91])) $values[91] = 5;
Check existence.
PHP
54y = 10
y54 = 10
Variable cannot start with digit.
Python
for (int i=0; i<39; i++) {{}}
for (int i=0; i<39; i++) {{}}
Correct.
Java
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
jwt.sign({{id:35}}, 'token');
jwt.sign({{id:35}}, 'token', {{expiresIn:'1h'}});
Add expiration.
Node.js
INSERT INTO users VALUES ('result',41)
INSERT INTO users (age, role) VALUES ('result',41);
Specify columns.
SQL
cin >> index cout << index;
cin >> index; cout << index;
Add semicolon.
C++
b > 88 & b < 36
b > 88 and b < 36
Use 'and' not '&'.
Python