https://kotlinlang.org logo
Title
v

vapoyan

07/22/2019, 6:01 AM
Where do you keep your Extension methods?
p

prasham.h.trivedi

07/22/2019, 6:09 AM
In a single file if there are less numbers of extensions. If there are more, I create one file per type.
v

vapoyan

07/22/2019, 6:16 AM
So if you need extension for Context you will create Context.kt and put everything there? That’s what I am currently doing
but I was thinking maybe somehow prefix that file ex:
_Context.kt
or
ContextExt.kt
or
ExtContext.kt
p

prasham.h.trivedi

07/22/2019, 6:37 AM
No prefixes. Just
Contexts.kt
. I personally use plurals, your personal preferences can be bit different.
👍 2
In case you need example, here is a utility library, and I arrange extension classes just like it’s arranged in this library https://github.com/PrashamTrivedi/UtilsLibrary
u

ursus

07/22/2019, 6:44 AM
I like ContextExt.kt
v

vapoyan

07/22/2019, 7:03 AM
I like more
_Context.kt
not self explanatory name of-course, can be also
Context+.kt
?
s

Stanislav

07/22/2019, 2:38 PM
I like way with only "classname" for name file with Extensions, bcs if u package named extensions or utils , you probably will have all files like ContextExtensions.kt, Some1Extensions.kt, Some2Extensions.kt etc.
c

Cody Engel

07/22/2019, 6:39 PM
My team does the following:
<Type>Extensions.kt
So for Context it’d be
ContextExtensions.kt
p

prasham.h.trivedi

07/23/2019, 8:41 AM
@Cody Engel This is my second favorite style. 🙂
v

vapoyan

07/23/2019, 12:03 PM
Thanks all ! Yes I also like ContextExtensions.kt
👍 1
👍
w

Will Shelor

07/24/2019, 2:01 AM
we also do <Type>Extensions.kt. We do a lot of navigation by navigate to file, so the name needs to be descriptive enough to know exactly what we're getting. We have a pretty big team, and this helps avoid confusion.
👍 1
i

igor.wojda

07/25/2019, 12:28 PM
ContextExtensions.kt