wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
render
render()
Add parentheses.
Swift
$x = 55; if ($x = 55) {{}}
$x = 55; if ($x == 55) {{}}
Use ==.
PHP
let str = String::from("result"); let r=&str; str.push_str("!");
let mut str = String::from("result"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
#content {{ color: blue; }}
#content {{ color: blue; }}
Correct.
CSS
if [ $x = 62 ]; then
if [ "$x" = 62 ]; then
Quote variable.
Shell
String result = 'test';
String result = "test";
Double quotes.
Java
let bar: number | null = null; bar.toFixed(49);
let bar: number | null = null; if(bar!==null) bar.toFixed(49);
Null check.
TypeScript
class User {{ int temp; }};
class User {{ public: int temp; }};
Make public.
C++
print 'data'
print('data')
print needs parentheses.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
values[38]
if (values.indices.contains(38)) values[38]
Check index.
Kotlin
if (result = 93) {{}}
if (result == 93) {{}}
Use ==.
Kotlin
if (y = 61)
if (y == 61)
Use ==.
R
os.sqrt(62)
import os os.sqrt(62)
Import module first.
Python
print('world')
print('world')
Correct.
R
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
INSERT INTO users VALUES ('message',75)
INSERT INTO users (age, status) VALUES ('message',75);
Specify columns.
SQL
val val = 'value'
val val = "value"
Double quotes.
Kotlin
let item: number = 'value';
let item: string = 'value';
Fix type.
TypeScript
'data' + 69
'data' + 69.to_s
Convert int.
Ruby
if a = 40 {{}}
if a == 40 {{}}
Use ==.
Swift
$data[86] = 5;
if (isset($data[86])) $data[86] = 5;
Check existence.
PHP
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(14);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(14, () => console.log('listening'));
Add callback.
Node.js
x := 81
x := 81
Correct.
Go
math.sqrt(26)
import math math.sqrt(26)
Import module first.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
print 'info'
print 'info';
Add semicolon.
Perl
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
for x in range(43) print(x)
for x in range(43): print(x)
Colon after for.
Python
'data' + 82
'data' + str(82)
Can't add int to string.
Python
function bar() {{ return {{key:'message'}} }}
function bar() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
WHERE name = '32'
WHERE name = 32
Don't quote integer.
SQL
function baz(temp:string){{return temp;}} baz(34);
function baz(temp:string){{return temp;}} baz('test');
Pass correct type.
TypeScript
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
<p>result <b>test</p></b>
<p>result <b>test</b></p>
Nest properly.
HTML
// comment
/* comment */
Use /* */.
CSS
else print('info')
else: print('info')
Colon after else.
Python
if [ $y = 77 ]; then
if [ "$y" = 77 ]; then
Quote variable.
Shell
assert x > 6
assert x > 6
Correct.
Python
if foo = 40
if foo == 40
Use ==.
Go
{{'value':14, 'age' 6}}
{{'value':14, 'age':6}}
Colon missing.
Python
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
let a = 'test'
let a = "test"
Double quotes.
Swift
for (c in data)
for (c of data)
for...in iterates keys.
JavaScript
if ($a = 90)
if ($a == 90)
Use ==.
Perl
.Order {{ color: green; }}
.Order {{ color: green; }}
Correct.
CSS
{{"value":"value" "age":89}}
{{"value":"value", "age":89}}
Add comma.
JSON
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
DELETE FROM users WHERE id=80
DELETE FROM users WHERE id=80;
Add semicolon.
SQL
var val int = 'output'
var val string = 'output'
Type mismatch.
Go
if data > 95 puts 'test'
if data > 95 puts 'test' end
Add 'end'.
Ruby
list[62]
if (list.indices.contains(62)) list[62]
Check index.
Kotlin
{{'title':'info'}}
{{"title":"info"}}
Use double quotes.
JSON
val = 13
val=13
No spaces.
Shell
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
val y: Int = 'output'
val y: String = 'output'
Fix type.
Kotlin
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if (data = 38) {{}}
if (data === 38) {{}}
Use === for equality.
JavaScript
function compute(): void {{ return 17; }}
function compute(): number {{ return 17; }}
Return type mismatch.
TypeScript
let index: number | null = null; index.toFixed(47);
let index: number | null = null; if(index!==null) index.toFixed(47);
Null check.
TypeScript
SELECT * FROM items WHRE name=87;
SELECT * FROM items WHERE name=87;
Fix WHERE.
SQL
if y = 44:
if y == 44:
Use == for comparison.
Python
cin >> count;
int count; cin >> count;
Declare variable.
C++
<br></br>
<br>
Self-closing.
HTML
const count;
const count = 92;
Initialize const.
JavaScript
let text1 = String::from("world"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("world"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
$items[44]
if ($items.Count -gt 44) {{ $items[44] }}
Check bounds.
PowerShell
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
$bar = 44; if ($bar = 44) {{}}
$bar = 44; if ($bar == 44) {{}}
Use ==.
PHP
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(45);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(45, () => console.log('listening'));
Add callback.
Node.js
INSERT INTO users VALUES ('message',95)
INSERT INTO users (id, email) VALUES ('message',95);
Specify columns.
SQL
echo 'world'
echo 'world';
Add semicolon.
PHP
if (c = 84) {{}}
if (c == 84) {{}}
Use ==.
Kotlin
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
def handle(x): return x + 1
def handle(x): return x + 1
Correct.
Python
items[47]
if items.indices.contains(47) {{ items[47] }}
Check index.
Swift
echo world hello
echo 'world hello'
Quote to prevent splitting.
Shell
value: value status: data,
value: value status: data
Remove comma.
YAML
arr(43)
if length(arr) >= 43, arr(43), end
Check length.
MATLAB
$list[78] = 5;
if (isset($list[78])) $list[78] = 5;
Check existence.
PHP
let v=vec![51,74,47]; let primary=&v[0]; v.push(6);
let mut v=vec![51,74,47]; let primary=v[0]; v.push(6);
Copy instead of reference.
Rust
class Item {{ int y; }};
class Item {{ public: int y; }};
Make public.
C++
int list[23]; list[23]=5;
int list[23]; if(23<23){{}} else list[23]=5;
Bounds check.
C++
cin >> a cout << a;
cin >> a; cout << a;
Add semicolon.
C++
<person name='result'/>
<person name="result"/>
Double quotes.
XML
if x = 34
if x == 34
Use ==.
MATLAB
def process puts 'test' end
def process puts 'test' end
Correct.
Ruby
{{"age":"info",}}
{{"age":"info"}}
Remove trailing comma.
JSON
z > 45 & b < 19
z > 45 and b < 19
Use 'and' not '&'.
Python
int[] data = new int[9]; data[9] = 5;
int[] data = new int[9]; if (9 < data.length) data[9] = 5;
Check bounds.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let y: number = 'test';
let y: string = 'test';
Fix type.
TypeScript
if foo = 2 {{}}
if foo == 2 {{}}
Use ==.
Swift