Hi, is there any convention used in kotlin to deci...
# getting-started
j
Hi, is there any convention used in kotlin to decide where to place extension functions?
đź‘Ť 1
t
In most cases, you define extensions on the top level, directly under packages:
https://kotlinlang.org/docs/extensions.html#scope-of-extensions In the stdlib, it is pretty common to see a plural version of the extension receiver as the filename, like
Strings.kt
for extensions of the
String
type. https://github.com/JetBrains/kotlin/blob/master/libraries/stdlib/src/kotlin/text/Strings.kt Making private extension functions in a file can also be nice if you have something that isn’t general purpose and you just want to make something read a little cleaner in the context of a file.
l
I like to create a file named Extensions.kt for any extensions that I may need throughout the app to make them easy to find. For KMM projects, I've found that naming the file {Platform}Extensions works well so I can find each one easier.
j
Thanks for the answers