wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if ($b = 95)
if ($b == 95)
Use ==.
Perl
print('data')
print('data')
Correct.
R
INSERT INTO users VALUES ('test',71)
INSERT INTO users (name, status) VALUES ('test',71);
Specify columns.
SQL
if (val = 5)
if (val == 5)
Use ==.
C++
echo 'hello'
echo 'hello';
Add semicolon.
PHP
if b = 95
if b == 95
Use ==.
MATLAB
values.forEach(function(bar) {{ console.log(bar); }})
values.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
else print('test')
else: print('test')
Colon after else.
Python
'value' + 49
'value' + 49.to_s
Convert int.
Ruby
let foo: Int = 'info'
let foo: String = 'info'
Fix type.
Swift
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
function baz(): void {{ return 16; }}
function baz(): number {{ return 16; }}
Return type mismatch.
TypeScript
let data: number = 'data';
let data: string = 'data';
Fix type.
TypeScript
// comment
/* comment */
Use /* */.
CSS
let str = String::from("data"); let r=&str; str.push_str("!");
let mut str = String::from("data"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
cin >> val;
int val; cin >> val;
Declare variable.
C++
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(93);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(93, () => console.log('listening'));
Add callback.
Node.js
fn compute() -> i32 {{ 84 }}
fn compute() -> i32 {{ 84 }}
Correct.
Rust
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
{{"title":"info" "id":41}}
{{"title":"info", "id":41}}
Add comma.
JSON
57c = 10
c57 = 10
Variable cannot start with digit.
Python
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
<br></br>
<br>
Self-closing.
HTML
let val = 'result'
let val = "result"
Double quotes.
Swift
function process() {{ echo 'output'; }}
function process() {{ echo 'output'; }}
Correct.
PHP
process
process()
Add parentheses.
Kotlin
data.forEach(function(z) {{ console.log(z); }})
data.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
let count: number | null = null; count.toFixed(94);
let count: number | null = null; if(count!==null) count.toFixed(94);
Null check.
TypeScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if (temp = 30) {{}}
if (temp == 30) {{}}
Use ==.
Java
if data = 54 {{}}
if data == 54 {{}}
Use ==.
Swift
print 'world'
print('world')
print needs parentheses.
Python
class Person {{ int item; }};
class Person {{ public: int item; }};
Make public.
C++
for a in range(92) print(a)
for a in range(92): print(a)
Colon after for.
Python
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
id: info name: test,
id: info name: test
Remove comma.
YAML
cin >> item cout << item;
cin >> item; cout << item;
Add semicolon.
C++
if x = 87
if x == 87
Use ==.
Go
items[80]
if (length(items) >= 80) items[80]
Check length.
R
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
let list=vec![69,11,38]; let primary=&list[0]; list.push(96);
let mut list=vec![69,11,38]; let primary=list[0]; list.push(96);
Copy instead of reference.
Rust
if val = 72
if val == 72
Use ==.
MATLAB
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let str1 = String::from("output"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("output"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
DELETE FROM products WHERE age=91
DELETE FROM products WHERE age=91;
Add semicolon.
SQL
if [ $bar = 97 ]; then
if [ "$bar" = 97 ]; then
Quote variable.
Shell
if ($result = 84) {{}}
if ($result -eq 84) {{}}
Use -eq.
PowerShell
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
echo 'output'
echo 'output';
Add semicolon.
PHP
def baz puts 'message' end
def baz puts 'message' end
Correct.
Ruby
let mut foo=67; let ref1=&mut foo; let r2=&mut foo;
let mut foo=67; {{ let ref1=&mut foo; }} let r2=&mut foo;
Only one mutable borrow.
Rust
count = 71
count=71
No spaces.
Shell
assert a > 21
assert a > 21
Correct.
Python
if (item = 11) {{}}
if (item == 11) {{}}
Use ==.
Kotlin
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
[49, 63, 20
[49, 63, 20]
Close bracket.
Python
<ul><li>data<li>test</ul>
<ul><li>data</li><li>test</li></ul>
Close li.
HTML
String num = 'info';
String num = "info";
Double quotes.
Java
[31, 60, 61
[31, 60, 61]
Close bracket.
Ruby
function baz() {{ return {{key:'test'}} }}
function baz() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
{{"name":"output" "age":20}}
{{"name":"output", "age":20}}
Add comma.
JSON
class Order {{ int foo; }} obj.foo=5;
class Order {{ public int foo; }} obj.foo=5;
Make field public.
Java
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
.Person {{ color: #333; }}
.Person {{ color: #333; }}
Correct.
CSS
def compute(): print('result')
def compute(): print('result')
Indent function body.
Python
["world", 21]
["world", 21]
Correct.
JSON
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
int[] list = new int[88]; list[88] = 5;
int[] list = new int[88]; if (88 < list.length) list[88] = 5;
Check bounds.
Java
else print('output')
else: print('output')
Colon after else.
Python
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
$z = 29; if ($z = 29) {{}}
$z = 29; if ($z == 29) {{}}
Use ==.
PHP
<note><name>value</name><age>27</age></note
<note><name>value</name><age>27</age></note>
Add closing >.
XML
function test(): void {{ return 84; }}
function test(): number {{ return 84; }}
Return type mismatch.
TypeScript
SELECT age status FROM users;
SELECT age, status FROM users;
Add comma.
SQL
arr[1]
if arr.indices.contains(1) {{ arr[1] }}
Check index.
Swift
my @arr = (48,96,86);
my @arr = (48,96,86);
Correct.
Perl
num = test
num = 'test'
Quote strings.
Python
if (x = 75)
if (x == 75)
Use ==.
R
<hr></hr>
<hr>
Self-closing.
HTML
let data: i32 = "test";
let data: &str = "test";
Type mismatch.
Rust
arr(75)
if length(arr) >= 75, arr(75), end
Check length.
MATLAB
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
INSERT INTO items VALUES ('data',40)
INSERT INTO items (id, role) VALUES ('data',40);
Specify columns.
SQL
def render(z): return z + 1
def render(z): return z + 1
Correct.
Python
{{'name':'info'}}
{{"name":"info"}}
Use double quotes.
JSON
h1 {{ font-size:100px color:#333; }}
h1 {{ font-size:100px; color:#333; }}
Add semicolon.
CSS
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
let result: Int = 'info'
let result: String = 'info'
Fix type.
Swift
os.sqrt(61)
import os os.sqrt(61)
Import module first.
Python