https://kotlinlang.org logo
Title
f

Florian

09/19/2019, 7:54 AM
Does this argument really hold when the IDE already has these little parameter hints?
k

karelpeeters

09/19/2019, 7:55 AM
I turn those hints off, I hate them.
👍 4
v

Viktor Penelski

09/19/2019, 7:55 AM
What if you are reviewing a PR outside of your IDE?
😀 1
5
t

tddmonkey

09/19/2019, 7:55 AM
you don’t get the hints in a PR either
😀 1
1
l

Luca Nicoletti

09/19/2019, 8:00 AM
As they said: using named params allows you to see them even outside the IDE, or with that option disabled. On top of that, you can change the order in which you’re passing them
f

Florian

09/19/2019, 8:05 AM
makes a lot of sense, thanks
is mixing up the ordered considered acceptable practice?
k

karelpeeters

09/19/2019, 8:08 AM
I think so, yes.
l

Luca Nicoletti

09/19/2019, 8:10 AM
As you name the parameters, it's not a bad practice :)
f

Florian

09/19/2019, 8:10 AM
one more thing: Why does the IDE not allow unnamed parameters to the right of named ones, even if they have the original order?
is there any specific reason for that
k

karelpeeters

09/19/2019, 8:14 AM
Interesting question, it looks like C# does have this: https://gunnarpeipman.com/csharp-non-trailing-named-arguments/
l

Luca Nicoletti

09/19/2019, 8:17 AM
Are you sure?
Let me double check
k

karelpeeters

09/19/2019, 8:18 AM
It's in the official 7.2 release notes as well.
l

Luca Nicoletti

09/19/2019, 8:18 AM
I was referring to kotlin not allowing it 😄
IDE is not complaining with this
Oh sorry, @Florian mis-read what you wrote
I read the vice-versa
s

SiebelsTim

09/19/2019, 10:23 AM
Named parameters also allow to override defaults without repeating preceding parameters
s

Sergio C.

09/19/2019, 11:03 AM
👍
r

Ruckus

09/19/2019, 3:49 PM
@Florian My guess is because it would be confusing, and could lead to unexpected inconsistencies when refactoring.
l

Luca Nicoletti

09/19/2019, 3:52 PM
The problem is which is the next one? The one after the named one? Or the first one left behind before it?
The compiler can’t guess
r

Ruckus

09/19/2019, 3:53 PM
@Luca Nicoletti Or even the one that happens to be at the given position.
Which is why C# imposes a number of limitations (that basically make the feature pointless in my opinion). For example, if you had
int Volume(int a, int b, int c) {
    return a * b * c
}
This is illegal:
Volume(1, c: 2, 3)
So... what's the point?
l

Luca Nicoletti

09/19/2019, 3:58 PM
That’s the same for Kotlin 🙂 You can’t have named parameter if not at latest ones
r

Ruckus

09/19/2019, 4:00 PM
No, C# does allow it. For example, this would be allowed
Volume(1, b: 2, 3)
They just impose so many limits on it that it can't really be used for anything beyond glorified comments.
l

Luca Nicoletti

09/19/2019, 4:00 PM
The limit is: the named parameter must be in the correct order?
r

Ruckus

09/19/2019, 4:02 PM
Not exactly, but pretty close. For example, this is allowed as well:
Volume(b: 1, a: 2, 3)
Basically, non-labeled arguments have to be in the exact position they were declared. And labeled arguments must fill in gaps exactly.
Which is rather un-intuitive if you ask me. You didn't even consider that option when you listed your possibilities of what it could mean. It makes sense once you know the rule, but very few people would guess that rule.
f

Florian

09/19/2019, 7:37 PM
very interesting, thanks
👍 1
seems to make sense then