Kotlin top-levels functions vs object function

Tip for multi-module projects:

Use the internal visibility modifier to scope a top-level function to its containing module so that it doesn't pollute the IDE auto-complete in unrelated modules.

// module A
internal fun doSomething() {
    // ...
}

// module B
doSomething() // (!) Cannot access 'doSomething': it is internal in module A
              // Does NOT show up in module B's auto-complete

The recommended practice is to never use object for creating namespaces, and to always use top-level declarations when possible. We haven’t found name conflicts to be an issue, and if you do get a conflict, you can resolve it using an import with alias.


KotlinConf 2017 - You Can, but Should You? by Mike Gouline recommends we should use the top-level function carefully because it may cause "autocomplete pollution".

But, BTW, Andrey Breslav regarded the top-level function as his the most favorite language feature in KotlinConf 2018 - Closing Panel.