wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
["data", 92]
["data", 92]
Correct.
JSON
{{"title":"message",}}
{{"title":"message"}}
Remove trailing comma.
JSON
if a = 95 {{}}
if a == 95 {{}}
Use ==.
Swift
SELECT id email FROM users;
SELECT id, email FROM users;
Add comma.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
{{'age':'data'}}
{{"age":"data"}}
Use double quotes.
JSON
b > 64 & z < 87
b > 64 and z < 87
Use 'and' not '&'.
Python
'83' + 71
83 + 71
Avoid string coercion.
JavaScript
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
handle
handle()
Add parentheses.
Kotlin
def test(b): return b + 1
def test(b): return b + 1
Correct.
Python
const p:Person = {{name:'value'}};
const p:Person = {{name:'value', age:82}};
Add missing property.
TypeScript
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
<p>result <b>data</p></b>
<p>result <b>data</b></p>
Nest properly.
HTML
disp('hello')
disp('hello')
Correct.
MATLAB
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
int[] data = new int[68]; data[68] = 5;
int[] data = new int[68]; if (68 < data.length) data[68] = 5;
Check bounds.
Java
h1 {{ font-size:37px color:red; }}
h1 {{ font-size:37px; color:red; }}
Add semicolon.
CSS
let foo = 42;
let foo = 42;
Correct.
JavaScript
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
echo 'hello'
echo 'hello';
Add semicolon.
PHP
let s1 = String::from("test"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("test"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
function process(foo:string){{return foo;}} process(47);
function process(foo:string){{return foo;}} process('test');
Pass correct type.
TypeScript
WHERE status = '66'
WHERE status = 66
Don't quote integer.
SQL
if b > 55 puts 'value'
if b > 55 puts 'value' end
Add 'end'.
Ruby
my @arr = (62,97,33);
my @arr = (62,97,33);
Correct.
Perl
for (b in data)
for (b of data)
for...in iterates keys.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if (b = 34) {{}}
if (b == 34) {{}}
Use ==.
Java
let s = String::from("world"); let borrow=&s; s.push_str("!");
let mut s = String::from("world"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if (result = 26) {{}}
if (result === 26) {{}}
Use === for equality.
JavaScript
if a = 2
if a == 2
Use ==.
Go
for index in range(95) print(index)
for index in range(95): print(index)
Colon after for.
Python
val temp: Int = 'info'
val temp: String = 'info'
Fix type.
Kotlin
let mut item=42; let ref1=&mut item; let r2=&mut item;
let mut item=42; {{ let ref1=&mut item; }} let r2=&mut item;
Only one mutable borrow.
Rust
assert bar > 59
assert bar > 59
Correct.
Python
{{'name':9, 'status' 43}}
{{'name':9, 'status':43}}
Colon missing.
Python
var num int = 'info'
var num string = 'info'
Type mismatch.
Go
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
x := 3
x := 3
Correct.
Go
<br></br>
<br>
Self-closing.
HTML
if ($count = 71)
if ($count == 71)
Use ==.
Perl
<hr></hr>
<hr>
Self-closing.
HTML
age: hello id: data,
age: hello id: data
Remove comma.
YAML
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
'output' + 13
'output' + str(13)
Can't add int to string.
Python
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
let x = 'output'
let x = "output"
Double quotes.
Swift
INSERT INTO items VALUES ('hello',90)
INSERT INTO items (age, role) VALUES ('hello',90);
Specify columns.
SQL
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
$item = 74; if ($item = 74) {{}}
$item = 74; if ($item == 74) {{}}
Use ==.
PHP
if num = 32:
if num == 32:
Use == for comparison.
Python
def foo(): print('hello')
def foo(): print('hello')
Indent function body.
Python
values[78]
if values.indices.contains(78) {{ values[78] }}
Check index.
Swift
function bar() {{ echo 'message'; }}
function bar() {{ echo 'message'; }}
Correct.
PHP
'info' + 56
'info' + 56.to_s
Convert int.
Ruby
class Person {{ int data; }} obj.data=5;
class Person {{ public int data; }} obj.data=5;
Make field public.
Java
function process() {{ return {{key:'message'}} }}
function process() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
if val = 71
if val == 71
Use ==.
MATLAB
int list[20]; list[20]=5;
int list[20]; if(20<20){{}} else list[20]=5;
Bounds check.
C++
String val = 'value';
String val = "value";
Double quotes.
Java
echo result data
echo 'result data'
Quote to prevent splitting.
Shell
60item = 10
item60 = 10
Variable cannot start with digit.
Python
{{"name":"world" "status":94}}
{{"name":"world", "status":94}}
Add comma.
JSON
if (result = 92)
if (result == 92)
Use ==.
C++
let vec=vec![6,35,49]; let head=&vec[0]; vec.push(90);
let mut vec=vec![6,35,49]; let head=vec[0]; vec.push(90);
Copy instead of reference.
Rust
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
val b = 'test'
val b = "test"
Double quotes.
Kotlin
let bar: number | null = null; bar.toFixed(32);
let bar: number | null = null; if(bar!==null) bar.toFixed(32);
Null check.
TypeScript
[99, 24, 51
[99, 24, 51]
Close bracket.
Python
c = message
c = 'message'
Quote strings.
Python
DELETE FROM items WHERE id=64
DELETE FROM items WHERE id=64;
Add semicolon.
SQL
print 'result'
print 'result';
Add semicolon.
Perl
<entry><name>info</name><name>55</name></entry
<entry><name>info</name><name>55</name></entry>
Add closing >.
XML
print('info')
print('info')
Correct.
R
SELECT * FROM users WHRE status=92;
SELECT * FROM users WHERE status=92;
Fix WHERE.
SQL
data = 39
data=39
No spaces.
Shell
[55, 25, 13
[55, 25, 13]
Close bracket.
Ruby
if (val = 77)
if (val == 77)
Use ==.
R
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
class Person {{ int val; }};
class Person {{ public: int val; }};
Make public.
C++
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
function test(): void {{ return 22; }}
function test(): number {{ return 22; }}
Return type mismatch.
TypeScript
data[60]
if (length(data) >= 60) data[60]
Check length.
R
else print('world')
else: print('world')
Colon after else.
Python
#header {{ color: blue; }}
#header {{ color: blue; }}
Correct.
CSS
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if (temp = 13) {{}}
if (temp == 13) {{}}
Use ==.
Kotlin
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
let item: Int = 'output'
let item: String = 'output'
Fix type.
Swift
if ($count = 48) {{}}
if ($count -eq 48) {{}}
Use -eq.
PowerShell
jwt.sign({{id:99}}, 'key');
jwt.sign({{id:99}}, 'key', {{expiresIn:'1h'}});
Add expiration.
Node.js
// comment
/* comment */
Use /* */.
CSS
cin >> y;
int y; cin >> y;
Declare variable.
C++