Kotlin: Where should the top-level functions go?

Is there a best practice / agreement on where the top-level functions should be located in Kotlin?

Let's say I am creating a package myproject.utilwith utility functions. In Java, it is recommended that you create a directory structure that matches the package structure. Not sure if this is really true for Kotlin. Anyway, I think the utility functions should go in myproject/util/somefile.kt, but I'm not sure what should be somefile.

+4
source share
1 answer

There is no need to include all utility functions in one file. You can create several files for top-level functions and name each of them according to what the functions in each file do.

If you have only a few functions and you do not want to invent any new names, the simplest option is the file name, just like the package ( util.ktin your example).

+4
source

Source: https://habr.com/ru/post/1630021/


All Articles