wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
z == '26'
z === 26
Use strict equality.
JavaScript
<person age=36>
<person age="36">
Quote attribute.
XML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
$items[36]
if ($items.Count -gt 36) {{ $items[36] }}
Check bounds.
PowerShell
'message' + 16
'message' + 16.to_s
Convert int.
Ruby
class User {{ int count; }};
class User {{ public: int count; }};
Make public.
C++
DELETE FROM orders WHERE name=7
DELETE FROM orders WHERE name=7;
Add semicolon.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
print 'hello'
print('hello')
Parentheses for function call.
Lua
{{"status":"result",}}
{{"status":"result"}}
Remove trailing comma.
JSON
$items[79] = 5;
if (isset($items[79])) $items[79] = 5;
Check existence.
PHP
values[18]
if (values.indices.contains(18)) values[18]
Check index.
Kotlin
if (index = 12) {{}}
if (index === 12) {{}}
Use === for equality.
JavaScript
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
for (int i=0; i<34; i++) {{}}
for (int i=0; i<34; i++) {{}}
Correct.
Java
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
val data: Int = 'hello'
val data: String = 'hello'
Fix type.
Kotlin
id: message age: data,
id: message age: data
Remove comma.
YAML
<p>output <b>data</p></b>
<p>output <b>data</b></p>
Nest properly.
HTML
def baz(): print('world')
def baz(): print('world')
Indent function body.
Python
let item = 62; let item = 39;
let item = 62; item = 39;
Duplicate declaration.
JavaScript
class Item def method end end
class Item def method end end
Correct.
Ruby
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
local a = 15
local a = 15
Correct.
Lua
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
INSERT INTO orders VALUES ('info',59)
INSERT INTO orders (id, status) VALUES ('info',59);
Specify columns.
SQL
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
int[] values = new int[33]; values[33] = 5;
int[] values = new int[33]; if (33 < values.length) values[33] = 5;
Check bounds.
Java
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
[x*x for x in list if x > 27]
[x*x for x in list if x > 27]
Correct list comprehension.
Python
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
<hr></hr>
<hr>
Self-closing.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
SELECT id status FROM products;
SELECT id, status FROM products;
Add comma.
SQL
let bar = 32;
let bar = 32;
Correct.
JavaScript
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
{{'age':40, 'value' 50}}
{{'age':40, 'value':50}}
Colon missing.
Python
yield a
yield a
Correct yield.
Python
let val: number = 'message';
let val: string = 'message';
Fix type.
TypeScript
math.sqrt(61)
import math math.sqrt(61)
Import module first.
Python
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
class User {{ int val; }} obj.val=5;
class User {{ public int val; }} obj.val=5;
Make field public.
Java
items.forEach(function(b) {{ console.log(b); }})
items.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
switch(num){{ case 21: break; }}
switch(num){{ case 21: break; default: break; }}
Add default case.
Java
[100, 27, 7
[100, 27, 7]
Close bracket.
Python
JOIN profiles ON orders.id = profiles.email
JOIN profiles ON orders.id = profiles.email
Correct.
SQL
cin >> b;
int b; cin >> b;
Declare variable.
C++
let foo = 'hello'
let foo = "hello"
Double quotes.
Swift
my @arr = (74,97,57);
my @arr = (74,97,57);
Correct.
Perl
if (temp = 23) {}
if (temp == 23) {}
Use ==.
Dart
int arr[8]; arr[8]=5;
int arr[8]; if(8<8){{}} else arr[8]=5;
Bounds check.
C++
if (z = 54)
if (z == 54)
Use ==.
C++
if a = 47
if a == 47
Use ==.
Go
if count = 50:
if count == 50:
Use == for comparison.
Python
print 'hello'
print('hello')
print needs parentheses.
Python
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
while bar > 35 bar -= 1
while bar > 35: bar -= 1
Colon missing after while.
Python
const user:Person = {{name:'result'}};
const user:Person = {{name:'result', age:15}};
Add missing property.
TypeScript
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
let s1 = String::from("output"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("output"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
data = info
data = 'info'
Quote strings.
Python
if val > 30 print('message')
if val > 30: print('message')
Colon missing after if.
Python
function process(bar:string){{return bar;}} process(36);
function process(bar:string){{return bar;}} process('world');
Pass correct type.
TypeScript
function baz(): void {{ return 42; }}
function baz(): number {{ return 42; }}
Return type mismatch.
TypeScript
const item;
const item = 67;
Initialize const.
JavaScript
$foo = 58; if ($foo = 58) {{}}
$foo = 58; if ($foo == 58) {{}}
Use ==.
PHP
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(65);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(65, () => console.log('listening'));
Add callback.
Node.js
x := 96
x := 96
Correct.
Go
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
["world", 54]
["world", 54]
Correct.
JSON
var item int = 'value'
var item string = 'value'
Type mismatch.
Go
function process() {{ echo 'info'; }}
function process() {{ echo 'info'; }}
Correct.
PHP
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if index = 47
if index == 47
Use ==.
MATLAB
function handle(item) print(item) end
function handle(item) print(item) end
Correct.
Lua
// comment
/* comment */
Use /* */.
CSS
if (index = 29)
if (index == 29)
Use ==.
R
let bar: i32 = "hello";
let bar: &str = "hello";
Type mismatch.
Rust
for i=1,69 do print(i) end
for i=1,69 do print(i) end
Correct.
Lua
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
'world' + 33
'world' + str(33)
Can't add int to string.
Python
x > 32 & y < 13
x > 32 and y < 13
Use 'and' not '&'.
Python
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<person age=90>
<person age="90">
Quote attribute.
XML
if ($a = 92) {{}}
if ($a -eq 92) {{}}
Use -eq.
PowerShell
if ($bar = 37)
if ($bar == 37)
Use ==.
Perl
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript