I’ve been getting into Swift recently and noticed that it is incredibly similar to Kotlin. Something that Swift has and I think would be of great help for the Kotlin community to improve code legibility even more is the addition of internal function parameter names (referred as ‘argument labels’ in Swift’s documentation) to Kotlin.
So, for example, if we have a function to greet someone, we’d do something like this in Kotlin:
fun main() {
greeting(name = "Alex")
}
fun greeting(name: String) {
println("Hello, $name!")
}
But, if we have argument labels, it can be converted to something more legible:
fun main() {
greeting(for = "Alex")
}
fun greeting(for name: String) {
println("Hello, $name!")
}
The argument label (represented as for
) is used when the function is called, and the parameter name (represented as name
) is used only inside the function itself. I think this tiny change can lead to a great impact on code legibility and would be a great feature to have in a future release of Kotlin!