# How to document a method where the leading arguments are optional?

**URL:** <https://discourse.julialang.org/t/how-to-document-a-method-where-the-leading-arguments-are-optional/92180>\
**Category:** General Usage\
**Tags:** question, documentation\
**Created:** [December 27, 2022, 6:31am UTC](https://discourse.julialang.org/t/how-to-document-a-method-where-the-leading-arguments-are-optional/92180 "2022-12-27T06:31:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [December 27, 2022, 6:31am UTC](https://discourse.julialang.org/t/how-to-document-a-method-where-the-leading-arguments-are-optional/92180/1 "2022-12-27T06:31:01Z")

</div>

The julia docstring convention for a function `f(x,y)` where the second argument is optional, is:

```julia
f(x, y=1)

```

Here `1` is the default value of the argument. This coincides nicely with the method definition. What does one do, however, if `x` is the optional argument? The choice

```julia
f(x=1, y)

```

seems odd, as we don’t place non-optional arguments after optional ones. The alternative to this is to use square brackets, and express this as

```julia
f([x=1], y)

```

This is what `zeros` does, for example:

```julia
zeros([T=Float64,] dims::Tuple)

```

However, the docstring convention also states that brackets are to be used in cases where the optional argument does not have a default value, but it does have one in this case. I wonder if the convention is to use brackets in this case anyway?

---

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [December 27, 2022, 9:34am UTC](https://discourse.julialang.org/t/how-to-document-a-method-where-the-leading-arguments-are-optional/92180/2 "2022-12-27T09:34:33Z")

</div>

The statement in the docs is:

> Optional arguments which do not have a default value should be put in brackets

But I haven’t read anything _against_ using them if there are default values, too. From my point of view, `f([x=1], y)` looks fine.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [December 27, 2022, 10:14am UTC](https://discourse.julialang.org/t/how-to-document-a-method-where-the-leading-arguments-are-optional/92180/3 "2022-12-27T10:14:52Z")

</div>

> [@jishnub](#):
>
> `f([x=1], y)`

> [@heliosdrm](#):
>
> `f([x=1], y)`

I presume you mean

```julia
f([x=1,] y) 

```

?

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [December 27, 2022, 10:55am UTC](https://discourse.julialang.org/t/how-to-document-a-method-where-the-leading-arguments-are-optional/92180/4 "2022-12-27T10:55:04Z")

</div>

Yes
