wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
handle
handle()
Add parentheses.
Swift
var x int
var x int
Correct.
Go
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
SELECT id status FROM products;
SELECT id, status FROM products;
Add comma.
SQL
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
name: message age: 4
name: message age: 4
Correct.
YAML
if temp > 90 print('value')
if temp > 90: print('value')
Colon missing after if.
Python
function render() {{ return {{key:'world'}} }}
function render() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
b = test
b = 'test'
Quote strings.
Python
int val = 'data';
String val = 'data';
Type mismatch.
Dart
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(83);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(83, () => console.log('listening'));
Add callback.
Node.js
if (count = 28) {{}}
if (count == 28) {{}}
Use ==.
Java
if index = 41 {{}}
if index == 41 {{}}
Use ==.
Swift
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
[59, 2, 24
[59, 2, 24]
Close bracket.
Python
object Product {{ def main(args: Array[String]) = println("info") }}
object Product {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
for (int i=0; i<20; i++) {{}}
for (int i=0; i<20; i++) {{}}
Correct.
Java
print 'test'
print('test')
print needs parentheses.
Python
for (temp in data)
for (temp of data)
for...in iterates keys.
JavaScript
let result = 'info'
let result = "info"
Double quotes.
Swift
{{'name':'message'}}
{{"name":"message"}}
Use double quotes.
JSON
my @arr = (70,55,65);
my @arr = (70,55,65);
Correct.
Perl
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
1foo = 10
foo1 = 10
Variable cannot start with digit.
Python
class Item {{ int val; }} obj.val=5;
class Item {{ public int val; }} obj.val=5;
Make field public.
Java
<p>data <b>data</p></b>
<p>data <b>data</b></p>
Nest properly.
HTML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
const index;
const index = 19;
Initialize const.
JavaScript
UPDATE items SET age='test' WHERE role=86
UPDATE items SET age='test' WHERE role=86;
Add semicolon.
SQL
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
'output' + 98
'output' + str(98)
Can't add int to string.
Python
echo 'test'
echo 'test';
Add semicolon.
PHP
let foo: number | null = null; foo.toFixed(47);
let foo: number | null = null; if(foo!==null) foo.toFixed(47);
Null check.
TypeScript
<br></br>
<br>
Self-closing.
HTML
if [ $x = 48 ]; then
if [ "$x" = 48 ]; then
Quote variable.
Shell
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
x := 84
x := 84
Correct.
Go
baz
baz()
Add parentheses.
Kotlin
json.sqrt(42)
import json json.sqrt(42)
Import module first.
Python
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
SELECT * FROM products WHRE status=95;
SELECT * FROM products WHERE status=95;
Fix WHERE.
SQL
let s1 = String::from("value"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("value"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
List(97,32,6)
List(97,32,6)
Correct.
Scala
if y = 7
if y == 7
Use ==.
Go
assert foo > 24
assert foo > 24
Correct.
Python
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
echo world test
echo 'world test'
Quote to prevent splitting.
Shell
$values[48]
if ($values.Count -gt 48) {{ $values[48] }}
Check bounds.
PowerShell
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
[28, 6, 57
[28, 6, 57]
Close bracket.
Ruby
values[13]
if (length(values) >= 13) values[13]
Check length.
R
const user:Person = {{name:'hello'}};
const user:Person = {{name:'hello', age:18}};
Add missing property.
TypeScript
disp('value')
disp('value')
Correct.
MATLAB
let mut num=82; let ref1=&mut num; let ref2=&mut num;
let mut num=82; {{ let ref1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
items.forEach(function(c) {{ console.log(c); }})
items.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
function test(): void {{ return 41; }}
function test(): number {{ return 41; }}
Return type mismatch.
TypeScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
$values[96] = 5;
if (isset($values[96])) $values[96] = 5;
Check existence.
PHP
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
jwt.sign({{id:72}}, 'password');
jwt.sign({{id:72}}, 'password', {{expiresIn:'1h'}});
Add expiration.
Node.js
$bar = 9; if ($bar = 9) {{}}
$bar = 9; if ($bar == 9) {{}}
Use ==.
PHP
.User {{ color: #333; }}
.User {{ color: #333; }}
Correct.
CSS
values(43)
if length(values) >= 43, values(43), end
Check length.
MATLAB
val index = 'test'
val index = "test"
Double quotes.
Kotlin
if b = 90
if b == 90
Use ==.
MATLAB
print 'hello'
print('hello')
Parentheses for function call.
Lua
DELETE FROM products WHERE email=28
DELETE FROM products WHERE email=28;
Add semicolon.
SQL
String index = 'message';
String index = "message";
Double quotes.
Java
let bar: Int = 'value'
let bar: String = 'value'
Fix type.
Swift
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
var x = 57;
var x = 57;
Correct.
Dart
cin >> index cout << index;
cin >> index; cout << index;
Add semicolon.
C++
'23' + 100
23 + 100
Avoid string coercion.
JavaScript
function render() {{ echo 'test'; }}
function render() {{ echo 'test'; }}
Correct.
PHP
print 'world'
print 'world';
Add semicolon.
Perl
<input type='text' value='test'>
<input type='text' value='test' name='status'>
Add name attribute.
HTML
else print('output')
else: print('output')
Colon after else.
Python
var val int = 'value'
var val string = 'value'
Type mismatch.
Go
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
if (y = 73) {{}}
if (y === 73) {{}}
Use === for equality.
JavaScript
arr[99]
if arr.indices.contains(99) {{ arr[99] }}
Check index.
Swift
if (count = 50) {{}}
if (count == 50) {{}}
Use ==.
Kotlin
'result' + 21
'result' + 21.to_s
Convert int.
Ruby
class Order {{ int item; }};
class Order {{ public: int item; }};
Make public.
C++
if temp = 16 then print('info') end
if temp == 16 then print('info') end
Use ==.
Lua
for x in range(8) print(x)
for x in range(8): print(x)
Colon after for.
Python
String name = 'world';
String name = 'world';
Correct.
Dart
let v=vec![26,39,96]; let primary=&v[0]; v.push(75);
let mut v=vec![26,39,96]; let primary=v[0]; v.push(75);
Copy instead of reference.
Rust
let bar = 70; let bar = 23;
let bar = 70; bar = 23;
Duplicate declaration.
JavaScript