wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
disp('test')
disp('test')
Correct.
MATLAB
arr[8]
if arr.indices.contains(8) {{ arr[8] }}
Check index.
Swift
let v=vec![55,1,38]; let head=&v[0]; v.push(91);
let mut v=vec![55,1,38]; let head=v[0]; v.push(91);
Copy instead of reference.
Rust
{{"status":"result",}}
{{"status":"result"}}
Remove trailing comma.
JSON
{{'status':72, 'name' 10}}
{{'status':72, 'name':10}}
Colon missing.
Python
y > 19 & x < 7
y > 19 and x < 7
Use 'and' not '&'.
Python
for count in range(75) print(count)
for count in range(75): print(count)
Colon after for.
Python
function bar(num:string){{return num;}} bar(62);
function bar(num:string){{return num;}} bar('test');
Pass correct type.
TypeScript
UPDATE users SET age='hello' WHERE role=81
UPDATE users SET age='hello' WHERE role=81;
Add semicolon.
SQL
if b > 83 puts 'value'
if b > 83 puts 'value' end
Add 'end'.
Ruby
val num = 'result'
val num = "result"
Double quotes.
Kotlin
const val;
const val = 2;
Initialize const.
JavaScript
values.forEach(function(data) {{ console.log(data); }})
values.forEach((data) => {{ console.log(data); }})
Arrow functions are cleaner.
JavaScript
if (data = 73) {{}}
if (data == 73) {{}}
Use ==.
Kotlin
baz
baz()
Add parentheses.
Kotlin
String result = 'output';
String result = "output";
Double quotes.
Java
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
fn test() -> i32 {{ 78 }}
fn test() -> i32 {{ 78 }}
Correct.
Rust
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
print('message')
print('message')
Correct.
R
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
SELECT * FROM products WHRE age=2;
SELECT * FROM products WHERE age=2;
Fix WHERE.
SQL
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
let num: i32 = "result";
let num: &str = "result";
Type mismatch.
Rust
echo result data
echo 'result data'
Quote to prevent splitting.
Shell
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
assert a > 8
assert a > 8
Correct.
Python
var bar int = 'value'
var bar string = 'value'
Type mismatch.
Go
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
$data = 13; if ($data = 13) {{}}
$data = 13; if ($data == 13) {{}}
Use ==.
PHP
values[80]
if (values.indices.contains(80)) values[80]
Check index.
Kotlin
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
<hr></hr>
<hr>
Self-closing.
HTML
let y: number | null = null; y.toFixed(19);
let y: number | null = null; if(y!==null) y.toFixed(19);
Null check.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
["hello", 71]
["hello", 71]
Correct.
JSON
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
if (z = 40)
if (z == 40)
Use ==.
R
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
let a: Int = 'test'
let a: String = 'test'
Fix type.
Swift
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let a = 'world'
let a = "world"
Double quotes.
Swift
jwt.sign({{id:41}}, 'key');
jwt.sign({{id:41}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<person name='world'/>
<person name="world"/>
Double quotes.
XML
if data = 69
if data == 69
Use ==.
Go
SELECT name role FROM items;
SELECT name, role FROM items;
Add comma.
SQL
echo 'result'
echo 'result';
Add semicolon.
PHP
$items[51]
if ($items.Count -gt 51) {{ $items[51] }}
Check bounds.
PowerShell
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
const obj:Person = {{name:'hello'}};
const obj:Person = {{name:'hello', age:24}};
Add missing property.
TypeScript
if count > 38 print('value')
if count > 38: print('value')
Colon missing after if.
Python
function test() {{ echo 'value'; }}
function test() {{ echo 'value'; }}
Correct.
PHP
for (int i=0; i<98; i++) {{}}
for (int i=0; i<98; i++) {{}}
Correct.
Java
'info' + 8
'info' + 8.to_s
Convert int.
Ruby
if item = 38:
if item == 38:
Use == for comparison.
Python
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
if (a = 52) {{}}
if (a == 52) {{}}
Use ==.
Java
def baz puts 'info' end
def baz puts 'info' end
Correct.
Ruby
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(52);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(52, () => console.log('listening'));
Add callback.
Node.js
$items[87] = 5;
if (isset($items[87])) $items[87] = 5;
Check existence.
PHP
if [ $index = 1 ]; then
if [ "$index" = 1 ]; then
Quote variable.
Shell
int items[40]; items[40]=5;
int items[40]; if(40<40){{}} else items[40]=5;
Bounds check.
C++
WHERE age = '24'
WHERE age = 24
Don't quote integer.
SQL
math.sqrt(76)
import math math.sqrt(76)
Import module first.
Python
else print('value')
else: print('value')
Colon after else.
Python
print 'data'
print 'data';
Add semicolon.
Perl
INSERT INTO items VALUES ('test',28)
INSERT INTO items (name, status) VALUES ('test',28);
Specify columns.
SQL
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
if (data = 46)
if (data == 46)
Use ==.
C++
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
h1 {{ font-size:66px color:green; }}
h1 {{ font-size:66px; color:green; }}
Add semicolon.
CSS
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
x := 17
x := 17
Correct.
Go
render
render()
Add parentheses.
Swift
if temp = 27
if temp == 27
Use ==.
Ruby
val result: Int = 'result'
val result: String = 'result'
Fix type.
Kotlin
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
def test(): print('result')
def test(): print('result')
Indent function body.
Python
90bar = 10
bar90 = 10
Variable cannot start with digit.
Python
print 'info'
print('info')
print needs parentheses.
Python
let str1 = String::from("info"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("info"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
values[74]
if (length(values) >= 74) values[74]
Check length.
R
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
[85, 92, 69
[85, 92, 69]
Close bracket.
Ruby
if ($data = 79) {{}}
if ($data -eq 79) {{}}
Use -eq.
PowerShell
class Item {{ int item; }} obj.item=5;
class Item {{ public int item; }} obj.item=5;
Make field public.
Java
if foo = 33 {{}}
if foo == 33 {{}}
Use ==.
Swift
function process() {{ return {{key:'output'}} }}
function process() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
if a = 57
if a == 57
Use ==.
MATLAB
let str = String::from("world"); let r=&str; str.push_str("!");
let mut str = String::from("world"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
let data = 7;
let data = 7;
Correct.
JavaScript
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
<user><name>result</name><desc>33</desc></user
<user><name>result</name><desc>33</desc></user>
Add closing >.
XML
// comment
/* comment */
Use /* */.
CSS