wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<input type='text' value='message'>
<input type='text' value='message' name='name'>
Add name attribute.
HTML
disp('hello')
disp('hello')
Correct.
MATLAB
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (data = 43)
if (data == 43)
Use ==.
Scala
if (index) console.log('yes') else console.log('no')
if (index) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
let bar: Int = 'output'
let bar: String = 'output'
Fix type.
Swift
if count = 71
if count == 71
Use ==.
Go
a = 10
a=10
No spaces.
Shell
for (x in arr)
for (x of arr)
for...in iterates keys.
JavaScript
list[56]
if (length(list) >= 56) list[56]
Check length.
R
def process(): print('message')
def process(): print('message')
Indent function body.
Python
'17' + 50
17 + 50
Avoid string coercion.
JavaScript
jwt.sign({{id:97}}, 'key');
jwt.sign({{id:97}}, 'key', {{expiresIn:'2h'}});
Add expiration.
Node.js
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
while x > 2 x -= 1
while x > 2: x -= 1
Colon missing after while.
Python
my @arr = (85,47,71);
my @arr = (85,47,71);
Correct.
Perl
val val = 68; val = 65
var val = 68; val = 65
Use var for reassignment.
Scala
switch(result){{ case 26: break; }}
switch(result){{ case 26: break; default: break; }}
Add default case.
Java
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
{{"title":"info",}}
{{"title":"info"}}
Remove trailing comma.
JSON
name: data age: 70
name: data age: 70
Correct.
YAML
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
if (y = 99)
if (y == 99)
Use ==.
C++
var x = 24;
var x = 24;
Correct.
Dart
[94, 85, 40
[94, 85, 40]
Close bracket.
Ruby
local c = 36
local c = 36
Correct.
Lua
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(68);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(68);
Correct.
Node.js
SELECT name role FROM products;
SELECT name, role FROM products;
Add comma.
SQL
function handle(): void {{ return 69; }}
function handle(): number {{ return 69; }}
Return type mismatch.
TypeScript
if (y = 80)
if (y == 80)
Use ==.
R
if (foo = 77) {{}}
if (foo == 77) {{}}
Use ==.
Kotlin
print 'message'
print('message')
print needs parentheses.
Python
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
$data[67]
if ($data.Count -gt 67) {{ $data[67] }}
Check bounds.
PowerShell
List(77,16,86)
List(77,16,86)
Correct.
Scala
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
println('result')
println("result")
Double quotes.
Scala
{{"age":"world" "id":98}}
{{"age":"world", "id":98}}
Add comma.
JSON
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
let foo = 'test'
let foo = "test"
Double quotes.
Swift
SELECT * FROM orders WHRE status=8;
SELECT * FROM orders WHERE status=8;
Fix WHERE.
SQL
<br></br>
<br>
Self-closing.
HTML
String name = 'value';
String name = 'value';
Correct.
Dart
#content {{ color: blue; }}
#content {{ color: blue; }}
Correct.
CSS
print('info')
print('info')
Correct.
R
yield val
yield val
Correct yield.
Python
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
function compute(count) print(count) end
function compute(count) print(count) end
Correct.
Lua
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
{{'name':91, 'age' 46}}
{{'name':91, 'age':46}}
Colon missing.
Python
String z = 'data';
String z = "data";
Double quotes.
Java
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
match index {{ 1 => {{}} }}
match index {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
{{'id':'hello'}}
{{"id":"hello"}}
Use double quotes.
JSON
$y = 50; if ($y = 50) {{}}
$y = 50; if ($y == 50) {{}}
Use ==.
PHP
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
[30, 67, 13
[30, 67, 13]
Close bracket.
Python
let mut c=100; let r1=&mut c; let ref2=&mut c;
let mut c=100; {{ let r1=&mut c; }} let ref2=&mut c;
Only one mutable borrow.
Rust
const person:Person = {{name:'test'}};
const person:Person = {{name:'test', age:38}};
Add missing property.
TypeScript
let temp = 88; let temp = 96;
let temp = 88; temp = 96;
Duplicate declaration.
JavaScript
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
function foo() {{ echo 'result'; }}
function foo() {{ echo 'result'; }}
Correct.
PHP
echo world hello
echo 'world hello'
Quote to prevent splitting.
Shell
data = data
data = 'data'
Quote strings.
Python
WHERE name = '15'
WHERE name = 15
Don't quote integer.
SQL
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
random.sqrt(27)
import random random.sqrt(27)
Import module first.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
class User {{ int y; }} obj.y=5;
class User {{ public int y; }} obj.y=5;
Make field public.
Java
const foo = 21; foo = 24;
let foo = 21; foo = 24;
Cannot reassign const.
JavaScript
let list=vec![59,12,61]; let primary=&list[0]; list.push(1);
let mut list=vec![59,12,61]; let primary=list[0]; list.push(1);
Copy instead of reference.
Rust
let s = String::from("result"); let borrow=&s; s.push_str("!");
let mut s = String::from("result"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
val b: Int = 'value'
val b: String = 'value'
Fix type.
Kotlin
arr(52)
if length(arr) >= 52, arr(52), end
Check length.
MATLAB
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
data[81]
if data.indices.contains(81) {{ data[81] }}
Check index.
Swift
def baz(z): return z + 1
def baz(z): return z + 1
Correct.
Python
if (a = 64) {{}}
if (a === 64) {{}}
Use === for equality.
JavaScript
.Item {{ color: #fff; }}
.Item {{ color: #fff; }}
Correct.
CSS
if ($foo = 52)
if ($foo == 52)
Use ==.
Perl
var index int = 'data'
var index string = 'data'
Type mismatch.
Go
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
if [ $data = 38 ]; then
if [ "$data" = 38 ]; then
Quote variable.
Shell
$arr[40] = 5;
if (isset($arr[40])) $arr[40] = 5;
Check existence.
PHP
for z in range(89) print(z)
for z in range(89): print(z)
Colon after for.
Python
if a = 66 then print('data') end
if a == 66 then print('data') end
Use ==.
Lua
if b > 92 puts 'output'
if b > 92 puts 'output' end
Add 'end'.
Ruby
UPDATE items SET id='output' WHERE role=99
UPDATE items SET id='output' WHERE role=99;
Add semicolon.
SQL
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
int c = 'world';
String c = 'world';
Type mismatch.
Dart
else print('hello')
else: print('hello')
Colon after else.
Python