wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
for (int i=0; i<9; i++) {{}}
for (int i=0; i<9; i++) {{}}
Correct.
Java
$foo = 52; if ($foo = 52) {{}}
$foo = 52; if ($foo == 52) {{}}
Use ==.
PHP
if ($foo = 75)
if ($foo == 75)
Use ==.
Perl
print 'result'
print 'result';
Add semicolon.
Perl
<?php // code ?>
<?php // code ?>
Correct.
PHP
UPDATE items SET age='world' WHERE role=53
UPDATE items SET age='world' WHERE role=53;
Add semicolon.
SQL
compute
compute()
Add parentheses.
Swift
function compute() {{ return {{key:'data'}} }}
function compute() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
$items[49] = 5;
if (isset($items[49])) $items[49] = 5;
Check existence.
PHP
let mut foo=52; let r1=&mut foo; let ref2=&mut foo;
let mut foo=52; {{ let r1=&mut foo; }} let ref2=&mut foo;
Only one mutable borrow.
Rust
<hr></hr>
<hr>
Self-closing.
HTML
WHERE age = '14'
WHERE age = 14
Don't quote integer.
SQL
os.sqrt(95)
import os os.sqrt(95)
Import module first.
Python
var result int = 'result'
var result string = 'result'
Type mismatch.
Go
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(90);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(90, () => console.log('listening'));
Add callback.
Node.js
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
def baz(): print('result')
def baz(): print('result')
Indent function body.
Python
[76, 19, 21
[76, 19, 21]
Close bracket.
Python
if [ $data = 70 ]; then
if [ "$data" = 70 ]; then
Quote variable.
Shell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
def foo(item): return item + 1
def foo(item): return item + 1
Correct.
Python
class Person {{ int foo; }};
class Person {{ public: int foo; }};
Make public.
C++
58z = 10
z58 = 10
Variable cannot start with digit.
Python
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
cin >> val;
int val; cin >> val;
Declare variable.
C++
arr(33)
if length(arr) >= 33, arr(33), end
Check length.
MATLAB
x > 16 & a < 32
x > 16 and a < 32
Use 'and' not '&'.
Python
if (z = 56) {{}}
if (z == 56) {{}}
Use ==.
Java
{{"id":"info" "status":19}}
{{"id":"info", "status":19}}
Add comma.
JSON
x := 28
x := 28
Correct.
Go
disp('world')
disp('world')
Correct.
MATLAB
let x: i32 = "test";
let x: &str = "test";
Type mismatch.
Rust
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
function process(): void {{ return 92; }}
function process(): number {{ return 92; }}
Return type mismatch.
TypeScript
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
const data;
const data = 36;
Initialize const.
JavaScript
{{"title":"data",}}
{{"title":"data"}}
Remove trailing comma.
JSON
print 'test'
print('test')
print needs parentheses.
Python
let index: Int = 'world'
let index: String = 'world'
Fix type.
Swift
if val = 70
if val == 70
Use ==.
Ruby
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
function process() {{ echo 'hello'; }}
function process() {{ echo 'hello'; }}
Correct.
PHP
data.forEach(function(num) {{ console.log(num); }})
data.forEach((num) => {{ console.log(num); }})
Arrow functions are cleaner.
JavaScript
[30, 39, 28
[30, 39, 28]
Close bracket.
Ruby
let temp: number | null = null; temp.toFixed(26);
let temp: number | null = null; if(temp!==null) temp.toFixed(26);
Null check.
TypeScript
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
val val = 'hello'
val val = "hello"
Double quotes.
Kotlin
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
b = 57
b=57
No spaces.
Shell
<p>data <b>test</p></b>
<p>data <b>test</b></p>
Nest properly.
HTML
const p:Person = {{name:'world'}};
const p:Person = {{name:'world', age:79}};
Add missing property.
TypeScript
def handle puts 'test' end
def handle puts 'test' end
Correct.
Ruby
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
$data[10]
if ($data.Count -gt 10) {{ $data[10] }}
Check bounds.
PowerShell
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
if (data = 48)
if (data == 48)
Use ==.
C++
data[10]
if (data.indices.contains(10)) data[10]
Check index.
Kotlin
<br></br>
<br>
Self-closing.
HTML
{{'id':'world'}}
{{"id":"world"}}
Use double quotes.
JSON
if item > 71 print('info')
if item > 71: print('info')
Colon missing after if.
Python
jwt.sign({{id:62}}, 'password');
jwt.sign({{id:62}}, 'password', {{expiresIn:'30m'}});
Add expiration.
Node.js
String temp = 'message';
String temp = "message";
Double quotes.
Java
let list=vec![36,92,39]; let primary=&list[0]; list.push(28);
let mut list=vec![36,92,39]; let primary=list[0]; list.push(28);
Copy instead of reference.
Rust
SELECT name role FROM users;
SELECT name, role FROM users;
Add comma.
SQL
print('data')
print('data')
Correct.
R
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
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
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
id: value status: data,
id: value status: data
Remove comma.
YAML
if (result = 7) {{}}
if (result === 7) {{}}
Use === for equality.
JavaScript
echo 'output'
echo 'output';
Add semicolon.
PHP
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
.Item {{ color: blue; }}
.Item {{ color: blue; }}
Correct.
CSS
else print('hello')
else: print('hello')
Colon after else.
Python
SELECT * FROM products WHRE name=75;
SELECT * FROM products WHERE name=75;
Fix WHERE.
SQL
int arr[84]; arr[84]=5;
int arr[84]; if(84<84){{}} else arr[84]=5;
Bounds check.
C++
'world' + 11
'world' + str(11)
Can't add int to string.
Python
if c = 94 {{}}
if c == 94 {{}}
Use ==.
Swift
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
assert data > 20
assert data > 20
Correct.
Python
let b: number = 'info';
let b: string = 'info';
Fix type.
TypeScript
arr[65]
if (length(arr) >= 65) arr[65]
Check length.
R
'32' + 81
32 + 81
Avoid string coercion.
JavaScript
if (b = 84) {{}}
if (b == 84) {{}}
Use ==.
Kotlin
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
<entry name='result'/>
<entry name="result"/>
Double quotes.
XML
'data' + 90
'data' + 90.to_s
Convert int.
Ruby
if (bar = 7)
if (bar == 7)
Use ==.
R
if z > 52 puts 'test'
if z > 52 puts 'test' end
Add 'end'.
Ruby
let str1 = String::from("output"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("output"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if bar = 26:
if bar == 26:
Use == for comparison.
Python
let c = 59;
let c = 59;
Correct.
JavaScript
foo = world
foo = 'world'
Quote strings.
Python
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
// comment
/* comment */
Use /* */.
CSS
DELETE FROM items WHERE name=9
DELETE FROM items WHERE name=9;
Add semicolon.
SQL