Would you consider it bad practice to have a param...
# getting-started
l
Would you consider it bad practice to have a parameter with default values before parameters without default values or is it purely a matter of preference and readability? Example
data class Foo(val bar: Int, val bizz: Int? = null, val buzz: String)
c
This was only enabled recently (I can’t recall which version of Kotlin, specifically), but that in itself says it was a feature in demand, and thus OK to have default params mixed with ones which must be specified. With this, Basically, you’re asking users to use named parameters vs ordered ones, which is totally fine. Personally, I still go with the general concept of always putting optional parameters after required ones, so that this isn’t ever really an issue in my code. I, personally, find it preferable to use multiple constructors or factory functions, rather than doing anything odd with the ordering of the parameters in the primary constructor. To me, it makes it the overall API more clear.
l
Makes sense, agreed
r
It's very common when the last argument is a functional type.
👍 3