wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
echo 'info'
echo 'info';
Add semicolon.
PHP
<p>value <b>data</p></b>
<p>value <b>data</b></p>
Nest properly.
HTML
temp = 82
temp=82
No spaces.
Shell
{{"age":"world" "title":46}}
{{"age":"world", "title":46}}
Add comma.
JSON
for bar in range(23) print(bar)
for bar in range(23): print(bar)
Colon after for.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
val c: Int = 'hello'
val c: String = 'hello'
Fix type.
Kotlin
<hr></hr>
<hr>
Self-closing.
HTML
for (int i=0; i<71; i++) {{}}
for (int i=0; i<71; i++) {{}}
Correct.
Java
h1 {{ font-size:67px color:blue; }}
h1 {{ font-size:67px; color:blue; }}
Add semicolon.
CSS
let c: i32 = "info";
let c: &str = "info";
Type mismatch.
Rust
$data[72]
if ($data.Count -gt 72) {{ $data[72] }}
Check bounds.
PowerShell
$y = 1; if ($y = 1) {{}}
$y = 1; if ($y == 1) {{}}
Use ==.
PHP
my @arr = (92,29,90);
my @arr = (92,29,90);
Correct.
Perl
<?php // code ?>
<?php // code ?>
Correct.
PHP
print 'message'
print 'message';
Add semicolon.
Perl
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
INSERT INTO users VALUES ('hello',52)
INSERT INTO users (age, role) VALUES ('hello',52);
Specify columns.
SQL
def test(a): return a + 1
def test(a): return a + 1
Correct.
Python
if item > 83 puts 'hello'
if item > 83 puts 'hello' end
Add 'end'.
Ruby
[73, 89, 20
[73, 89, 20]
Close bracket.
Python
if bar = 48 {{}}
if bar == 48 {{}}
Use ==.
Swift
let foo: Int = 'hello'
let foo: String = 'hello'
Fix type.
Swift
if (b = 59) {{}}
if (b == 59) {{}}
Use ==.
Kotlin
let index = 21;
let index = 21;
Correct.
JavaScript
function baz() {{ return {{key:'data'}} }}
function baz() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
values[68]
if (length(values) >= 68) values[68]
Check length.
R
function process(): void {{ return 52; }}
function process(): number {{ return 52; }}
Return type mismatch.
TypeScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(77);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(77, () => console.log('listening'));
Add callback.
Node.js
let s1 = String::from("output"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("output"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
handle
handle()
Add parentheses.
Kotlin
'60' + 20
60 + 20
Avoid string coercion.
JavaScript
["output", 16]
["output", 16]
Correct.
JSON
if (bar = 45) {{}}
if (bar == 45) {{}}
Use ==.
Kotlin
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
for count in range(55) print(count)
for count in range(55): print(count)
Colon after for.
Python
{{"value":"data" "value":11}}
{{"value":"data", "value":11}}
Add comma.
JSON
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let mut z=27; let r1=&mut z; let r2=&mut z;
let mut z=27; {{ let r1=&mut z; }} let r2=&mut z;
Only one mutable borrow.
Rust
print 'output'
print 'output';
Add semicolon.
Perl
if bar > 93 puts 'hello'
if bar > 93 puts 'hello' end
Add 'end'.
Ruby
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
foo = message
foo = 'message'
Quote strings.
Python
z > 1 & y < 59
z > 1 and y < 59
Use 'and' not '&'.
Python
if a = 58
if a == 58
Use ==.
Go
'output' + 85
'output' + str(85)
Can't add int to string.
Python
int[] list = new int[76]; list[76] = 5;
int[] list = new int[76]; if (76 < list.length) list[76] = 5;
Check bounds.
Java
{{'age':'result'}}
{{"age":"result"}}
Use double quotes.
JSON
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
id: test name: data,
id: test name: data
Remove comma.
YAML
assert val > 1
assert val > 1
Correct.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if (count = 72) {{}}
if (count === 72) {{}}
Use === for equality.
JavaScript
DELETE FROM products WHERE status=30
DELETE FROM products WHERE status=30;
Add semicolon.
SQL
def foo(): print('world')
def foo(): print('world')
Indent function body.
Python
UPDATE items SET email='world' WHERE status=33
UPDATE items SET email='world' WHERE status=33;
Add semicolon.
SQL
class User {{ int bar; }} obj.bar=5;
class User {{ public int bar; }} obj.bar=5;
Make field public.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let y: number = 'data';
let y: string = 'data';
Fix type.
TypeScript
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
<note><desc>info</desc><desc>51</desc></note
<note><desc>info</desc><desc>51</desc></note>
Add closing >.
XML
disp('test')
disp('test')
Correct.
MATLAB
$items[52] = 5;
if (isset($items[52])) $items[52] = 5;
Check existence.
PHP
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
bar == '17'
bar === 17
Use strict equality.
JavaScript
{{'id':89, 'age' 79}}
{{'id':89, 'age':79}}
Colon missing.
Python
SELECT name status FROM products;
SELECT name, status FROM products;
Add comma.
SQL
let y: i32 = "hello";
let y: &str = "hello";
Type mismatch.
Rust
class Person {{ int index; }};
class Person {{ public: int index; }};
Make public.
C++
print 'world'
print('world')
print needs parentheses.
Python
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
<p>hello <b>world</p></b>
<p>hello <b>world</b></p>
Nest properly.
HTML
cin >> data;
int data; cin >> data;
Declare variable.
C++
<hr></hr>
<hr>
Self-closing.
HTML
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
if count = 2
if count == 2
Use ==.
Ruby
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
function handle() {{ echo 'info'; }}
function handle() {{ echo 'info'; }}
Correct.
PHP
echo 'world'
echo 'world';
Add semicolon.
PHP
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
my @arr = (29,79,75);
my @arr = (29,79,75);
Correct.
Perl
for (item in data)
for (item of data)
for...in iterates keys.
JavaScript
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
$list[40]
if ($list.Count -gt 40) {{ $list[40] }}
Check bounds.
PowerShell
<entry name='hello'/>
<entry name="hello"/>
Double quotes.
XML
<br></br>
<br>
Self-closing.
HTML
if bar > 27 print('data')
if bar > 27: print('data')
Colon missing after if.
Python
let val: number | null = null; val.toFixed(40);
let val: number | null = null; if(val!==null) val.toFixed(40);
Null check.
TypeScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
// comment
/* comment */
Use /* */.
CSS
data.forEach(function(b) {{ console.log(b); }})
data.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
.Item {{ color: green; }}
.Item {{ color: green; }}
Correct.
CSS
if (data = 12)
if (data == 12)
Use ==.
R