Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File naming conventions for Kotlin

Tags:

Kotlin removes the Java "one top-level public class per file" restriction, which I've learned to love. I wonder if there are reasons for this discussed somewhere and whether there are some guidelines how to deal with this new freedom?

like image 886
maaartinus Avatar asked Sep 03 '14 03:09

maaartinus


People also ask

How do I name my Kotlin file?

Naming. If a source file contains only a single top-level class, the file name should reflect the case-sensitive name plus the . kt extension. Otherwise, if a source file contains multiple top-level declarations, choose a name that describes the contents of the file, apply PascalCase, and append the .

Does indentation matter in Kotlin?

Kotlin does not use significant indentation because the designers of Kotlin do not believe that significant indentation is a good idea.


1 Answers

You can still use that Java rule as a convention and name your files after your classes. Or you can start putting more classes into a single Kotlin file, in which situation I'd recommend naming the files after their purpose. Each file will usually contain classes or other top-level elements that are related to each other (if they are not, maybe they don't belong to the same file in the first place?). There should be single word or a small number of words that express the purpose of all the classes in a single file, which is then a natural candidate for the file name.

like image 127
Ladicek Avatar answered Sep 18 '22 12:09

Ladicek