wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if ($y = 14) {{}}
if ($y -eq 14) {{}}
Use -eq.
PowerShell
int[] arr = new int[6]; arr[6] = 5;
int[] arr = new int[6]; if (6 < arr.length) arr[6] = 5;
Check bounds.
Java
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
$list[77]
if ($list.Count -gt 77) {{ $list[77] }}
Check bounds.
PowerShell
<user><desc>result</desc><name>46</name></user
<user><desc>result</desc><name>46</name></user>
Add closing >.
XML
re.sqrt(75)
import re re.sqrt(75)
Import module first.
Python
print('result')
print('result')
Correct.
R
let b = 85;
let b = 85;
Correct.
JavaScript
class User {{ int num; }};
class User {{ public: int num; }};
Make public.
C++
let b = 'value'
let b = "value"
Double quotes.
Swift
assert item > 70
assert item > 70
Correct.
Python
for item in range(57) print(item)
for item in range(57): print(item)
Colon after for.
Python
x := 10
x := 10
Correct.
Go
{{"name":"test",}}
{{"name":"test"}}
Remove trailing comma.
JSON
DELETE FROM users WHERE age=21
DELETE FROM users WHERE age=21;
Add semicolon.
SQL
val index: Int = 'info'
val index: String = 'info'
Fix type.
Kotlin
<?php // code ?>
<?php // code ?>
Correct.
PHP
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
UPDATE items SET id='hello' WHERE email=21
UPDATE items SET id='hello' WHERE email=21;
Add semicolon.
SQL
{{'status':41, 'age' 93}}
{{'status':41, 'age':93}}
Colon missing.
Python
list[76]
if (length(list) >= 76) list[76]
Check length.
R
handle
handle()
Add parentheses.
Kotlin
foo
foo()
Add parentheses.
Swift
print 'info'
print 'info';
Add semicolon.
Perl
cin >> y;
int y; cin >> y;
Declare variable.
C++
if c > 52 puts 'hello'
if c > 52 puts 'hello' end
Add 'end'.
Ruby
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
{{'id':'hello'}}
{{"id":"hello"}}
Use double quotes.
JSON
class Product {{ int index; }} obj.index=5;
class Product {{ public int index; }} obj.index=5;
Make field public.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
INSERT INTO products VALUES ('value',13)
INSERT INTO products (age, email) VALUES ('value',13);
Specify columns.
SQL
function bar(data:string){{return data;}} bar(57);
function bar(data:string){{return data;}} bar('test');
Pass correct type.
TypeScript
values[88]
if (values.indices.contains(88)) values[88]
Check index.
Kotlin
["test", 57]
["test", 57]
Correct.
JSON
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if [ $num = 76 ]; then
if [ "$num" = 76 ]; then
Quote variable.
Shell
let str1 = String::from("test"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("test"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
print 'result'
print('result')
print needs parentheses.
Python
arr(60)
if length(arr) >= 60, arr(60), end
Check length.
MATLAB
function baz() {{ echo 'world'; }}
function baz() {{ echo 'world'; }}
Correct.
PHP
const result;
const result = 35;
Initialize const.
JavaScript
[7, 66, 50
[7, 66, 50]
Close bracket.
Python
item = world
item = 'world'
Quote strings.
Python
def bar(): print('data')
def bar(): print('data')
Indent function body.
Python
var val int = 'data'
var val string = 'data'
Type mismatch.
Go
let vec=vec![69,9,22]; let head=&vec[0]; vec.push(48);
let mut vec=vec![69,9,22]; let head=vec[0]; vec.push(48);
Copy instead of reference.
Rust
let mut b=24; let r1=&mut b; let r2=&mut b;
let mut b=24; {{ let r1=&mut b; }} let r2=&mut b;
Only one mutable borrow.
Rust
for (result in data)
for (result of data)
for...in iterates keys.
JavaScript
jwt.sign({{id:1}}, 'key');
jwt.sign({{id:1}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
num = 2
num=2
No spaces.
Shell
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
$val = 47; if ($val = 47) {{}}
$val = 47; if ($val == 47) {{}}
Use ==.
PHP
let num: number = 'world';
let num: string = 'world';
Fix type.
TypeScript
else print('info')
else: print('info')
Colon after else.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<br></br>
<br>
Self-closing.
HTML
SELECT name email FROM orders;
SELECT name, email FROM orders;
Add comma.
SQL
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
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
{{"age":"test" "age":90}}
{{"age":"test", "age":90}}
Add comma.
JSON
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
[70, 11, 20
[70, 11, 20]
Close bracket.
Ruby
if temp = 79 {{}}
if temp == 79 {{}}
Use ==.
Swift
function render(): void {{ return 72; }}
function render(): number {{ return 72; }}
Return type mismatch.
TypeScript
if val = 13
if val == 13
Use ==.
Ruby
<person name='data'/>
<person name="data"/>
Double quotes.
XML
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
disp('info')
disp('info')
Correct.
MATLAB
def render puts 'result' end
def render puts 'result' end
Correct.
Ruby
if (x = 55) {{}}
if (x == 55) {{}}
Use ==.
Kotlin
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<p>hello <b>hello</p></b>
<p>hello <b>hello</b></p>
Nest properly.
HTML
val a = 'value'
val a = "value"
Double quotes.
Kotlin
if b = 37
if b == 37
Use ==.
MATLAB
echo info data
echo 'info data'
Quote to prevent splitting.
Shell
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if (data = 51)
if (data == 51)
Use ==.
R
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
$list[52] = 5;
if (isset($list[52])) $list[52] = 5;
Check existence.
PHP
'info' + 66
'info' + 66.to_s
Convert int.
Ruby
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
WHERE status = '59'
WHERE status = 59
Don't quote integer.
SQL
items.forEach(function(z) {{ console.log(z); }})
items.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
let foo: Int = 'test'
let foo: String = 'test'
Fix type.
Swift
if x = 6
if x == 6
Use ==.
Go
<hr></hr>
<hr>
Self-closing.
HTML
let c: number | null = null; c.toFixed(70);
let c: number | null = null; if(c!==null) c.toFixed(70);
Null check.
TypeScript
const p:Person = {{name:'test'}};
const p:Person = {{name:'test', age:26}};
Add missing property.
TypeScript
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
if result > 25 print('output')
if result > 25: print('output')
Colon missing after if.
Python
a == '96'
a === 96
Use strict equality.
JavaScript
for (int i=0; i<7; i++) {{}}
for (int i=0; i<7; i++) {{}}
Correct.
Java
// comment
/* comment */
Use /* */.
CSS
my @arr = (47,77,48);
my @arr = (47,77,48);
Correct.
Perl
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript