wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
values[85]
if (values.indices.contains(85)) values[85]
Check index.
Kotlin
if z > 33 print('message')
if z > 33: print('message')
Colon missing after if.
Python
class User {{ int val; }} obj.val=5;
class User {{ public int val; }} obj.val=5;
Make field public.
Java
my @arr = (50,42,71);
my @arr = (50,42,71);
Correct.
Perl
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
if z = 21
if z == 21
Use ==.
Go
function process() {{ echo 'message'; }}
function process() {{ echo 'message'; }}
Correct.
PHP
let bar = 'info'
let bar = "info"
Double quotes.
Swift
<note><desc>test</desc><desc>55</desc></note
<note><desc>test</desc><desc>55</desc></note>
Add closing >.
XML
<?php // code ?>
<?php // code ?>
Correct.
PHP
data = 2
data=2
No spaces.
Shell
if (data = 69)
if (data == 69)
Use ==.
R
function bar(): void {{ return 29; }}
function bar(): number {{ return 29; }}
Return type mismatch.
TypeScript
x := 46
x := 46
Correct.
Go
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
math.sqrt(84)
import math math.sqrt(84)
Import module first.
Python
if (x = 50)
if (x == 50)
Use ==.
C++
list[63]
if list.indices.contains(63) {{ list[63] }}
Check index.
Swift
[62, 10, 56
[62, 10, 56]
Close bracket.
Ruby
if (b = 73) {{}}
if (b == 73) {{}}
Use ==.
Kotlin
if z = 24
if z == 24
Use ==.
MATLAB
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
let list=vec![90,35,29]; let first=&list[0]; list.push(44);
let mut list=vec![90,35,29]; let first=list[0]; list.push(44);
Copy instead of reference.
Rust
'71' + 8
71 + 8
Avoid string coercion.
JavaScript
else print('message')
else: print('message')
Colon after else.
Python
<p>data <b>data</p></b>
<p>data <b>data</b></p>
Nest properly.
HTML
String num = 'data';
String num = "data";
Double quotes.
Java
if ($temp = 17) {{}}
if ($temp -eq 17) {{}}
Use -eq.
PowerShell
for (temp in items)
for (temp of items)
for...in iterates keys.
JavaScript
INSERT INTO products VALUES ('world',77)
INSERT INTO products (age, status) VALUES ('world',77);
Specify columns.
SQL
def test(): print('output')
def test(): print('output')
Indent function body.
Python
["message", 40]
["message", 40]
Correct.
JSON
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
arr(95)
if length(arr) >= 95, arr(95), end
Check length.
MATLAB
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
var temp int = 'world'
var temp string = 'world'
Type mismatch.
Go
if (item = 83) {{}}
if (item === 83) {{}}
Use === for equality.
JavaScript
{{"value":"message" "age":78}}
{{"value":"message", "age":78}}
Add comma.
JSON
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
val count: Int = 'message'
val count: String = 'message'
Fix type.
Kotlin
if ($result = 91)
if ($result == 91)
Use ==.
Perl
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<br></br>
<br>
Self-closing.
HTML
z = output
z = 'output'
Quote strings.
Python
let y: Int = 'data'
let y: String = 'data'
Fix type.
Swift
'world' + 78
'world' + str(78)
Can't add int to string.
Python
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
assert result > 29
assert result > 29
Correct.
Python
cin >> a;
int a; cin >> a;
Declare variable.
C++
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
$data[94] = 5;
if (isset($data[94])) $data[94] = 5;
Check existence.
PHP
json.sqrt(85)
import json json.sqrt(85)
Import module first.
Python
.Order {{ color: #333; }}
.Order {{ color: #333; }}
Correct.
CSS
def process(): print('data')
def process(): print('data')
Indent function body.
Python
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 products VALUES ('message',35)
INSERT INTO products (name, role) VALUES ('message',35);
Specify columns.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let c: i32 = "world";
let c: &str = "world";
Type mismatch.
Rust
function handle(b:string){{return b;}} handle(14);
function handle(b:string){{return b;}} handle('value');
Pass correct type.
TypeScript
<br></br>
<br>
Self-closing.
HTML
let str = String::from("world"); let ref=&str; str.push_str("!");
let mut str = String::from("world"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
int values[97]; values[97]=5;
int values[97]; if(97<97){{}} else values[97]=5;
Bounds check.
C++
c = message
c = 'message'
Quote strings.
Python
const person:Person = {{name:'hello'}};
const person:Person = {{name:'hello', age:16}};
Add missing property.
TypeScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
SELECT age role FROM items;
SELECT age, role FROM items;
Add comma.
SQL
SELECT * FROM users WHRE status=33;
SELECT * FROM users WHERE status=33;
Fix WHERE.
SQL
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
class User {{ int count; }};
class User {{ public: int count; }};
Make public.
C++
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(19);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(19, () => console.log('listening'));
Add callback.
Node.js
let x = 'data'
let x = "data"
Double quotes.
Swift
print 'data'
print 'data';
Add semicolon.
Perl
function compute() {{ return {{key:'result'}} }}
function compute() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
if index > 77 print('world')
if index > 77: print('world')
Colon missing after if.
Python
num = 61
num=61
No spaces.
Shell
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
z > 48 & y < 77
z > 48 and y < 77
Use 'and' not '&'.
Python
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
let v=vec![79,42,98]; let head=&v[0]; v.push(17);
let mut v=vec![79,42,98]; let head=v[0]; v.push(17);
Copy instead of reference.
Rust
for (int i=0; i<71; i++) {{}}
for (int i=0; i<71; i++) {{}}
Correct.
Java
x := 14
x := 14
Correct.
Go
<person name='message'/>
<person name="message"/>
Double quotes.
XML
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
let c: number = 'message';
let c: string = 'message';
Fix type.
TypeScript
if (result = 80) {{}}
if (result == 80) {{}}
Use ==.
Java
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
echo 'data'
echo 'data';
Add semicolon.
PHP
<hr></hr>
<hr>
Self-closing.
HTML
val bar = 'info'
val bar = "info"
Double quotes.
Kotlin
arr[70]
if (arr.indices.contains(70)) arr[70]
Check index.
Kotlin
if num = 47
if num == 47
Use ==.
Ruby
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
class User {{ int foo; }} obj.foo=5;
class User {{ public int foo; }} obj.foo=5;
Make field public.
Java