Hello Guys, I have a question about code style. W...
# codingconventions
f
Hello Guys, I have a question about code style. We are developing a UI test helper library for Android Instrumentation tests and thought having common assertions in separate files can be convenient. But we are not sure if we should declare those functions top-level or in an object such as “ImageViewAssertions”. *So my question is: * When do you use top-level (root package) functions and when do you put them inside objects ?
c
Kotlin style is still a matter of discussion, here is the one relevant to your question. https://github.com/yole/kotlin-style-guide/issues/6
f
Even though i agree that it is an IDE issue. It still affects all of us and i think using objects is more convenient. You can pass them to
Copy code
with(foo: T)
if you want to define a scope
c
I tend to agree, even though I've read a lot of text justifying this particular tidbit of style and on the other hand removal of
package
visibility modifier, I cannot fully agree with either.
d
isn't
package-private
similar to
internal
? What are the differing semantics?
f
@Daniel Tam Is there package private in kotlin ? I think if you opt-out visibility it becomes public by default (I believe you can override this behaviour by adding a compiler plugin). Internal is more like a module visibility.
d
ahh yeah I was thinking that package private is similar to internal, but I think I had a fundamental misunderstanding of what a module is. So a module isn't the a single package namespace, but is instead essentially a build.gradle target?
f
Correct me if im wrong, https://www.jetbrains.com/help/idea/creating-and-managing-modules.html I believe its more of a Intellij IDEA idiom. Basically thats how android studio and intellij knows where to search for build tasks and groups them.