Understanding Kotlin code structure
When you start programming in Kotlin, your first step is typically to create a new file, which usually has the .kt
extension.
In contrast to Java, Kotlin doesn’t strictly enforce a one-to-one relationship between the filename and the class name. While you have the flexibility to include multiple public classes within a single Kotlin file, it’s generally considered best practice to group only logically related classes together in one file. Keep in mind that doing so should not make the file excessively long or difficult to read. Additionally, packing multiple public classes into a single file can make it harder to search for specific functionality, as the project overview may not display all available classes.
Naming conventions
As a convention, if your file consists of a single class, it is recommended to name your file the same as your class.
When your file contains multiple classes, the filename should describe the...