question about kotlin's language design: why are t...
# announcements
l
question about kotlin's language design: why are the primary constructor parameters specified next to the class name? wouldnt it be way more consistent with secondary constructors and other functions to have them next to
init
?
t
The simple answer is probably because a lot of Kotlin’s syntax is borrowed from Scala.
😉 1
l
that doesn't really answer my question
t
Well Kotlin used the Scala syntax, and Scala probably based their syntax on Lisp. It’s pretty common in functional languages to define data types this way.
l
that may be so, but my question is: why? why is that common practice?
t
Well one of the reason is that this way of defining a class combines both the definitino of the class, with the definition of the contructor and the definition of the properties.
data class User(val id: Int, val name: String)
is much shorter than defining a class, constructor and properties separately.
👍 1
l
that is what i was looking for. ty