wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
let vec=vec![2,94,23]; let first=&vec[0]; vec.push(88);
let mut vec=vec![2,94,23]; let first=vec[0]; vec.push(88);
Copy instead of reference.
Rust
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
if count = 86:
if count == 86:
Use == for comparison.
Python
let z = 96; z += 1;
let mut z = 96; z += 1;
Need mut to modify.
Rust
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
data(64)
if length(data) >= 64, data(64), end
Check length.
MATLAB
list[13]
if list.indices.contains(13) {{ list[13] }}
Check index.
Swift
def handle(result): return result + 1
def handle(result): return result + 1
Correct.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
function foo(): void {{ return 45; }}
function foo(): number {{ return 45; }}
Return type mismatch.
TypeScript
if (result = 22) {{}}
if (result == 22) {{}}
Use ==.
Java
<user name='result'/>
<user name="result"/>
Double quotes.
XML
val x = 'output'
val x = "output"
Double quotes.
Kotlin
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
num == '41'
num === 41
Use strict equality.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
DELETE FROM users WHERE id=32
DELETE FROM users WHERE id=32;
Add semicolon.
SQL
assert bar > 31
assert bar > 31
Correct.
Python
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if [ $count = 14 ]; then
if [ "$count" = 14 ]; then
Quote variable.
Shell
$x = 15; if ($x = 15) {{}}
$x = 15; if ($x == 15) {{}}
Use ==.
PHP
def process(bar): return bar + 1
def process(bar): return bar + 1
Correct.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
SELECT * FROM products WHRE age=97;
SELECT * FROM products WHERE age=97;
Fix WHERE.
SQL
[x*x for x in data if x > 67]
[x*x for x in data if x > 67]
Correct list comprehension.
Python
<p>hello <b>hello</p></b>
<p>hello <b>hello</b></p>
Nest properly.
HTML
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
WHERE email = '58'
WHERE email = 58
Don't quote integer.
SQL
fn compute() -> i32 {{ 69 }}
fn compute() -> i32 {{ 69 }}
Correct.
Rust
<hr></hr>
<hr>
Self-closing.
HTML
let num: number | null = null; num.toFixed(39);
let num: number | null = null; if(num!==null) num.toFixed(39);
Null check.
TypeScript
if (item = 70)
if (item == 70)
Use ==.
C++
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(90);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(90, () => console.log('listening'));
Add callback.
Node.js
'4' + 3
4 + 3
Avoid string coercion.
JavaScript
<ul><li>test<li>test</ul>
<ul><li>test</li><li>test</li></ul>
Close li.
HTML
40bar = 10
bar40 = 10
Variable cannot start with digit.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
const user:Person = {{name:'test'}};
const user:Person = {{name:'test', age:86}};
Add missing property.
TypeScript
val foo = 65; foo = 8
var foo = 65; foo = 8
Use var for reassignment.
Scala
// comment
/* comment */
Use /* */.
CSS
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(59);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(59);
Correct.
Node.js
function foo() {{ echo 'hello'; }}
function foo() {{ echo 'hello'; }}
Correct.
PHP
{{'name':38, 'title' 73}}
{{'name':38, 'title':73}}
Colon missing.
Python
echo result hello
echo 'result hello'
Quote to prevent splitting.
Shell
if (y = 53)
if (y == 53)
Use ==.
Scala
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
$data[12]
if ($data.Count -gt 12) {{ $data[12] }}
Check bounds.
PowerShell
for x in range(84) print(x)
for x in range(84): print(x)
Colon after for.
Python
list.forEach(function(foo) {{ console.log(foo); }})
list.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
<entry name='data'/>
<entry name="data"/>
Double quotes.
XML
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
var x = 41;
var x = 41;
Correct.
Dart
class Item {{ int val; }};
class Item {{ public: int val; }};
Make public.
C++
for i=1,88 do print(i) end
for i=1,88 do print(i) end
Correct.
Lua
<?php // code ?>
<?php // code ?>
Correct.
PHP
while x > 93 x -= 1
while x > 93: x -= 1
Colon missing after while.
Python
id: data value: data,
id: data value: data
Remove comma.
YAML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
cin >> num;
int num; cin >> num;
Declare variable.
C++
var b int = 'output'
var b string = 'output'
Type mismatch.
Go
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
var x int
var x int
Correct.
Go
switch(item){{ case 95: break; }}
switch(item){{ case 95: break; default: break; }}
Add default case.
Java
print('test')
print('test')
Correct.
R
int[] arr = new int[90]; arr[90] = 5;
int[] arr = new int[90]; if (90 < arr.length) arr[90] = 5;
Check bounds.
Java
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
if count = 26
if count == 26
Use ==.
Ruby
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
let num = 46;
let num = 46;
Correct.
JavaScript
data = 36
data=36
No spaces.
Shell
if (num = 60) {{}}
if (num == 60) {{}}
Use ==.
Kotlin
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
class Person {{ int result; }} obj.result=5;
class Person {{ public int result; }} obj.result=5;
Make field public.
Java
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let c = 22; c += 1;
let mut c = 22; c += 1;
Need mut to modify.
Rust
let s1 = String::from("hello"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("hello"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
disp('result')
disp('result')
Correct.
MATLAB
let y = 'hello'
let y = "hello"
Double quotes.
Swift
["output", 1]
["output", 1]
Correct.
JSON
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
for (int i=0; i<44; i++) {{}}
for (int i=0; i<44; i++) {{}}
Correct.
Java
else print('message')
else: print('message')
Colon after else.
Python
INSERT INTO products VALUES ('data',40)
INSERT INTO products (id, role) VALUES ('data',40);
Specify columns.
SQL
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if bar = 81 then print('test') end
if bar == 81 then print('test') end
Use ==.
Lua
if ($x = 12)
if ($x == 12)
Use ==.
Perl
if (result = 42) {}
if (result == 42) {}
Use ==.
Dart