In which order should Kotlin parameters be declare...
# feed
c
In which order should Kotlin parameters be declared? https://ivan.canet.dev/blog/2026/06/08/kotlin-parameter-order.html
y
Alternatively, if a mandatory parameter is placed after a default parameter, a user who wants to use positional syntax is forced to specify the default parameter too:
I think your example has a typo; likely what you meant was:
Copy code
fun foo(
    a: Int,
    b: String = "default",
    c: Boolean,
)

foo(a, "default", false)
// I cannot specify 'c' without specifying 'b'
That comment should probably say "positionally" as well, but it's implied in the context
🙏 2
positional parameters are forbidden after a vararg parameter
I did a double take at this line. The context explains it sufficiently, so I am being pedantic, but I believe you meant positional arguments are forbidden after vararg. Although maybe you do mean that parameters that come after vararg aren't positional? That is very true, but "forbidden" makes it sound like it's a compiler error, while a parameter being positional or not is contractual, and isn't in the declaration itself.
I wonder: why optional lambda before optional non-lambda? I'm guessing it's so that lambda parameters are together? I don't disagree, just wondering about the justification because I never really thought about it before
c
I did a double take at this line. The context explains it sufficiently, so I am being pedantic, but I believe you meant positional arguments are forbidden after vararg.
Correct, fixed 🙏
> I wonder: why optional lambda before optional non-lambda? This ensures that if there is no primary lambda and there are non-lambda optional parameters, the non-primary lambda parameter doesn't end up as last parameter, and thus can't be used with trailing syntax
Arguably, I don't always respect that specific rule, and I often mix optional parameters together whether they're a lambda or not. But I try to avoid having a lambda in very last place if it doesn't follow the definition of "primary"