# Naming positional arguments at call site

**URL:** <https://discourse.julialang.org/t/naming-positional-arguments-at-call-site/103526>\
**Category:** Internals & Design\
**Created:** [September 4, 2023, 7:07pm UTC](https://discourse.julialang.org/t/naming-positional-arguments-at-call-site/103526 "2023-09-04T19:07:20Z")\
**Posts on this page:** 20\
**Page:** 6

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [September 8, 2023, 4:16am UTC](https://discourse.julialang.org/t/naming-positional-arguments-at-call-site/103526/104 "2023-09-08T04:16:59Z")

</div>

> [@ParadaCarleton](#):
>
> Joint keyword/positional arguments are a good default because they’re never a huge problem.

This thread already covered why it’s a huge problem for multimethods and API, and that linked political blogpost has nothing to do with programming.

---

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [September 8, 2023, 6:16am UTC](https://discourse.julialang.org/t/naming-positional-arguments-at-call-site/103526/105 "2023-09-08T06:16:14Z")

</div>

Optionally naming function arguments is a useful feature – but both IME and from other responses in this thread, its usefulness is mostly limited to a smallish set of functions.  
It’s perfectly reasonable for function authors to opt-in in these cases. Even Base does that, I particularly like the `range` function:

```julia
range(start, stop, length)
range(start, stop; length, step)
range(start; length, stop, step)
range(;start, length, stop, step)

```

Maybe, just advertising, promoting, recommending this approach would already help? For user/package functions where naming makes sense.  
Or adding an even easier way to opt-in.

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [September 8, 2023, 7:18am UTC](https://discourse.julialang.org/t/naming-positional-arguments-at-call-site/103526/106 "2023-09-08T07:18:31Z")

</div>

> [@aplavin](#):
>
> Or adding an even easier way to opt-in.

Maybe a way to generate the text of the method signatures so you can fill in or edit the bodies. It doesn’t seem like something a macro can always do automatically, the simplest `_range` helper method pattern breaks down in the source code for `range` because of the keyword-only `step`.  
It’s also important to note that without the methods to allow keywords, `range` would be a 1-method function, the only possibility where positional-or-keyword arguments can’t run into dispatch ambiguity. Maybe the way to generate that text can warn “only do this to a unimethod and handle the dispatch in the positional helper methods”.

---

<div class="post-metadata">

**Author:** ![ParadaCarleton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paradacarleton/32/20005_2.png) [@ParadaCarleton](https://discourse.julialang.org/u/ParadaCarleton)\
**Post date:** [September 8, 2023, 5:54pm UTC](https://discourse.julialang.org/t/naming-positional-arguments-at-call-site/103526/107 "2023-09-08T17:54:17Z")

</div>

This post was temporarily hidden by the community for possibly being off-topic, unfocused, inappropriate, or spammy.

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [September 8, 2023, 6:34pm UTC](https://discourse.julialang.org/t/naming-positional-arguments-at-call-site/103526/108 "2023-09-08T18:34:57Z")

</div>

This post was temporarily hidden by the community for possibly being off-topic, unfocused, inappropriate, or spammy.

---

<div class="post-metadata">

**Author:** ![ParadaCarleton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paradacarleton/32/20005_2.png) [@ParadaCarleton](https://discourse.julialang.org/u/ParadaCarleton)\
**Post date:** [September 8, 2023, 8:11pm UTC](https://discourse.julialang.org/t/naming-positional-arguments-at-call-site/103526/109 "2023-09-08T20:11:34Z")

</div>

This post was temporarily hidden by the community for possibly being off-topic, unfocused, inappropriate, or spammy.

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [September 8, 2023, 10:51pm UTC](https://discourse.julialang.org/t/naming-positional-arguments-at-call-site/103526/110 "2023-09-08T22:51:52Z")

</div>

This post was temporarily hidden by the community for possibly being off-topic, unfocused, inappropriate, or spammy.

---

<div class="post-metadata">

**Author:** ![GregVernon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gregvernon/32/5611_2.png) [@GregVernon](https://discourse.julialang.org/u/GregVernon)\
**Post date:** [September 9, 2023, 4:42am UTC](https://discourse.julialang.org/t/naming-positional-arguments-at-call-site/103526/111 "2023-09-09T04:42:25Z")

</div>

@mbauman – as you’ve probably noticed, I chose your post as the solution as I think that satisfactorily answers the “why it won’t happen” part of this question, and I think there are a lot of other good pieces of advice for workarounds in other places. To fully finish this off I’m happy to add some documentation in the Julia manual that summarizes your comment(s) as well as the workarounds, etc., then future questions relating to this can be answered by a simple link.

Do you happen to have any thoughts as to where in the docs I should put such a discussion? I’m thinking one of [Methods](https://docs.julialang.org/en/v1/manual/methods/), [Style Guide](https://docs.julialang.org/en/v1/manual/style-guide/), or [FAQ](https://docs.julialang.org/en/v1/manual/faq/), probably leaning towards the latter – but maybe not a bad idea to split between Methods and FAQ? Is there a different spot you’d recommend?

---

<div class="post-metadata">

**Author:** ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)\
**Post date:** [September 9, 2023, 9:09am UTC](https://discourse.julialang.org/t/naming-positional-arguments-at-call-site/103526/112 "2023-09-09T09:09:25Z")

</div>

The FAQ seems like a good place for this. The [Noteworthy differences from other languages](https://docs.julialang.org/en/v1/manual/noteworthy-differences/) page is also appropriate, specifically the Python and R sections; the disadvantage is that the sections in that page are pretty heavy info dumps, and the individual points are not linkable, so it’s not as convenient as a reference.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [September 11, 2023, 2:15pm UTC](https://discourse.julialang.org/t/naming-positional-arguments-at-call-site/103526/113 "2023-09-11T14:15:27Z")

</div>

I think you’re taking the wrong conclusion here. You’ve decided that you don’t like some of Julia’s defaults so we must not care about good defaults. However that’s the wrong conclusion. We very much believe that bad defaults are a drag and that one should always have good defaults—it is crucially important and we have agonized over it many times. (The number of times Jeff and I have gotten heated about some feature requiring people to opt into the correct behavior is hard to even enumerate.) However I disagree that most of your list of supposed bad defaults are in fact bad. In this particular case, it is my opinion that being able to call positional arguments by name is a bad default in general but even more so in Julia. So please stop asserting that we don’t care about defaults (we do), when in fact we simply disagree with what you think the defaults should be. I can address the other defaults you disagree with if you’d like me to.

---

<div class="post-metadata">

**Author:** ![ParadaCarleton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paradacarleton/32/20005_2.png) [@ParadaCarleton](https://discourse.julialang.org/u/ParadaCarleton)\
**Post date:** [September 12, 2023, 1:23am UTC](https://discourse.julialang.org/t/naming-positional-arguments-at-call-site/103526/114 "2023-09-12T01:23:21Z")

</div>

> [@StefanKarpinski](#):
>
> (The number of times Jeff and I have gotten heated about some feature requiring people to opt into the correct behavior is hard to even enumerate.)

My comments were not meant to be directed at you or Jeff, and I apologize if I gave that impression. It was aimed at replies I’ve commonly gotten on both the Discourse and the Slack when I bring up that some default or another creates substantial difficulties for beginners. In this thread alone, there were many posts arguing that this choice of default doesn’t matter or isn’t a substantial cost. The most common kind of reply to this thread:

> I still haven’t seen a single counterargument to the point that the package developer can always choose their API to be kwargs and forward to internal methods with positional args.

The mental model behind it being that because developers _can_ do something, they _will_ do it when appropriate. Whereas if defaults matter, what matters isn’t that they could do it, it’s that they don’t.

Some other highlights:

> it’s really not though. I should hope that the most challenging part of designing a comfortable user interface isn’t writing a singular extra dispatch…

> [this] bears on activation energy for choices we do not have to want to make nor want to have to begin any engagement with[, not here]

> of all the things I’ve read someone claim will doom Julia, this is one of the silliest […] it’s also largely irrelevant. […] they’ll get over it.

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [September 12, 2023, 1:25am UTC](https://discourse.julialang.org/t/naming-positional-arguments-at-call-site/103526/115 "2023-09-12T01:25:52Z")

</div>

all 5 of those are me lol

---

<div class="post-metadata">

**Author:** ![ParadaCarleton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paradacarleton/32/20005_2.png) [@ParadaCarleton](https://discourse.julialang.org/u/ParadaCarleton)\
**Post date:** [September 12, 2023, 1:28am UTC](https://discourse.julialang.org/t/naming-positional-arguments-at-call-site/103526/116 "2023-09-12T01:28:35Z")

</div>

Yes, I think you’re the person who left the most replies against this proposal here, so I used your posts as examples.

That being said, I think I’m bowing out. I don’t think this conversation is going to be very productive.

---

<div class="post-metadata">

**Author:** ![tfiers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tfiers/32/32427_2.png) [@tfiers](https://discourse.julialang.org/u/tfiers)\
**Post date:** [September 13, 2023, 8:08pm UTC](https://discourse.julialang.org/t/naming-positional-arguments-at-call-site/103526/117 "2023-09-13T20:08:52Z")

</div>

I made a PR with a small addition to the docs 🙂

> <https://github.com/JuliaLang/julia/pull/51306>
>
> Many new (and old) Julians have been missing this feature over the years.\[^1\],\[^…2\] But it's not gonna come anytime soon, or ever.\[^3\]
> So, here we add best practices to the docs on how you can still document the names/meaning of positional arguments at the call site.
> 
> I added it to the 'Python' section in \`noteworthy-differences.md\`.
> Disadvantage of this location, as \[noted\]\[4\] by @digital-carver:
> \- it could also go in the R section.
> \- individual points on this page (like this one) are not linkable!
> \- the page in its entirety is already quite long.
> 
> The new bullet point \_does\_ fit in well with the existing, preceding one, however.
> 
> \[^1\]: https://discourse.julialang.org/t/allow-use-of-named-argument-syntax-for-positional-arguments/5287
> \[^2\]: https://discourse.julialang.org/t/naming-positional-arguments-at-call-site/103526
> \[^3\]: https://discourse.julialang.org/t/naming-positional-arguments-at-call-site/103526/97
> 
> \[4\]: https://discourse.julialang.org/t/naming-positional-arguments-at-call-site/103526/112?u=tfiers

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [September 14, 2023, 12:08am UTC](https://discourse.julialang.org/t/naming-positional-arguments-at-call-site/103526/118 "2023-09-14T00:08:54Z")

</div>

That PR seems strange to me because it’s about naming positional arguments but then compares it to Python, which doesn’t have named positional arguments either. Python has positional-_or_-keyword arguments, which are different because when a keyword is provided in the call, the argument is matched using the keyword, never the position e.g. `foo(id=1, mass=5.6) == foo(mass=5.6, id=1)`. To be matched by position, an argument cannot have a keyword in the call.

When comparing Julia and Python in particular, it’s illustrative to compare how methods specify which arguments are which and why. This more or less just sums up what had been discussed in the thread earlier in one place.

Julia methods simply divide positional arguments from keyword arguments with `;`. Positional-or-keyword arguments are impossible because multimethods vary on the number and annotated type of positional-only arguments:

```julia
# p_ - match position
# k_ - match keyword provided in call

# calling foo(1, 2) would be ambiguous if k1 could be positional
function foo(p1; k1)
function foo(p1, p2)

# matching keywords in a call e.g. foo2(p2=Cat(), p1=Dog()) would be ambiguous
function foo2(p1::Dog, p2::Cat)
function foo2(p2::Cat, p1::Dog)

```

In a hypothetical language, types could be matched by keyword instead, but that would only make multimethods dispatch on keyword-only arguments, not allow positional-or-keyword arguments:

```julia
# not Julia: foo(k1=Dog(), k2=Cat()) != foo(k2=Dog(), k1=Cat())
# matching positions in a call e.g. foo(Dog(), Cat()) would be ambiguous
function foo(k1::Dog, k2::Cat)
function foo(k2::Dog, k1::Cat)

function foo(k2::Cat, k1::Dog) # overwrites the 1st method
function foo(k1::Cat, k2::Dog) # overwrites the 2nd method

```

The only way to resolve that positional ambiguity is force an order on `k1, k2` in the methods, so types can be matched on position _and_ keywords. But now we’re forced to name _and_ order arguments consistently across all methods, e.g. a nonsensical `greet(dog::Cat, cat::Dog)` after `greet(dog::Dog, cat::Cat)`. This is a nightmare, so types were chosen to match by position, where calls are simpler to write.

Python can allow positional-or-keyword arguments because of its “unimethods,” though it must in turn disallow keyword arguments preceding positional arguments in calls and adds complexity (`*args`, `*`, `/`) to dividing the arguments:

```julia
# pk_ - match keyword if provided in call, position otherwise

def foo1(pk1, pk2): # calling foo1(1, pk1=2) specifies pk1 twice and errors
def foo2(p1, p2, *pv, k1, k2): # if pv is empty, p1, p2 --> pk1, pk2
def foo3(pk1, pk2, *, k1, k2): # PEP 3102, v3.0+
def foo4(p1, p2, /, pk1, pk2, *, k1, k2): # PEP 570, v3.8+

```

Since Python already has keyword-able arguments, it doesn’t have named positional arguments because it’d look indistinguishable in calls and clash with the positional-preceding-keyword rule. Julia doesn’t have named positional arguments because the indistinguishability results in dispatch ambiguity:

```julia
function foo3(x, y)
function foo3(y; x)
# foo3(x=1, 2) calls the latter, would be ambiguous otherwise

```

---

<div class="post-metadata">

**Author:** ![goerz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerz/32/3269_2.png) [@goerz](https://discourse.julialang.org/u/goerz)\
**Post date:** [September 14, 2023, 2:33am UTC](https://discourse.julialang.org/t/naming-positional-arguments-at-call-site/103526/119 "2023-09-14T02:33:35Z")

</div>

> [@Benny](#):
>
> compares it to Python, which doesn’t have named positional arguments either

No, but Python allows you to pass positional arguments by keyword, which I think is what most people are talking about in the context of this discussion, and certainly what people coming from Python to Julia might be expecting to find (and thus, what the FAQ discusses)

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [September 14, 2023, 4:15am UTC](https://discourse.julialang.org/t/naming-positional-arguments-at-call-site/103526/120 "2023-09-14T04:15:21Z")

</div>

I considered that at first, but people in that issue seem to agree the goal is to document the meaning of positional arguments at the call site without defining variables in advance (which I don’t find harder to write at all). That is not why people pass arguments by keyword, it’s to pass arguments and override default values without being constrained by preceding arguments. For example, if we have a `def foo(x=1, y=2, z=3): return (x,y,z)`, `foo(z=5)` specifies a value for `z` without specifying the preceding arguments; we can’t do that with position-only arguments in Python _or_ Julia e.g. `foo(5)` specifies `x`.

Earlier in the thread someone had proposed a new syntax for naming position-only arguments and did not realize people were discussing position-or-keyword arguments instead, so that also made me lean toward concluding the distinction was also being muddled in the issue.

---

<div class="post-metadata">

**Author:** ![bilderbuchi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bilderbuchi/32/13562_2.png) [@bilderbuchi](https://discourse.julialang.org/u/bilderbuchi)\
**Post date:** [September 14, 2023, 5:18am UTC](https://discourse.julialang.org/t/naming-positional-arguments-at-call-site/103526/121 "2023-09-14T05:18:37Z")

</div>

> [@goerz](#):
>
> No, but Python allows you to pass positional arguments by keyword, which I think is what most people are talking about in the context of this discussion, and certainly what people coming from Python to Julia might be expecting to find (and thus, what the FAQ discusses)

Exactly, 💯 this!

> [@Benny](#):
>
> not why people pass arguments by keyword, it’s to pass arguments and override default values without being constrained by preceding arguments.

That seems like a weirdly strong assertion to make? I mean, yeah that is definitely one use case, but using this to easily maintain argument clarity when calling is, at least in my personal experience, just as useful in Python.

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [September 14, 2023, 7:59am UTC](https://discourse.julialang.org/t/naming-positional-arguments-at-call-site/103526/122 "2023-09-14T07:59:41Z")

</div>

> [@bilderbuchi](#):
>
> That seems like a weirdly strong assertion to make?

It’s what I was taught, what the [Python tutorial section on keyword arguments](https://docs.python.org/3/tutorial/controlflow.html#keyword-arguments) highlights, and how it’s used in packages I’ve ran into (generally isn’t much different from how keyword-only arguments are used in Julia). Maybe my perspective is narrow, but I don’t really see how writing keyword arguments in their given position e.g. `foo(p1=1, p2=2, p3=3)` is any clearer than defining variables then writing positional arguments in the same line `p1=1; p2=2; p3=3; foo(p1, p2, p3)`. In practice, it’s usually clearer to use names that deviate slightly to distinguish multiple instances or to retrieve from an already named collection e.g. `pow(bases[3], exponent2)`. Without the need to write arguments or override default values out of order, keyword arguments are not necessary or even optimal for clarity.

---

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [September 15, 2023, 7:49pm UTC](https://discourse.julialang.org/t/naming-positional-arguments-at-call-site/103526/123 "2023-09-15T19:49:09Z")

</div>

As another perspective, I mostly wrote named arguments in Python, and write keyword arguments in Julia, in the same order they are defined in the function. The benefits of writing their names are both documentation (clear which value is which argument), and reducing errors (a typo or mixup between arguments gets caught immediately). You cannot really get that with just creating and naming variables upfront.

[Previous page](https://discourse.julialang.org/t/naming-positional-arguments-at-call-site/103526.md?page=5)

[Next page](https://discourse.julialang.org/t/naming-positional-arguments-at-call-site/103526.md?page=7)
