Hi everyone, does anyone have insight in to the re...
# naming
r
Hi everyone, does anyone have insight in to the reason behind capitalized function names in Compose? It's a style that has grown on me, and I'm starting to use it for factory functions in my own (non-compose) code, but I don't want to break style conventions for the wrong reason.
y
It's the convention used for factory functions. It's meant to mimic class names/constructors, sort of signaling "hey I'm creating a significant object here"
l
Adding to that, I think it's within the expected code style. Kotlin itself does it to the
List
constructor-like function, for example
k
Indeed, it's mentioned in the Kotlin Coding Conventions page:
Exception: factory functions used to create instances of classes can have the same name as the abstract return type
s
Initially, I also had difficulty with capitalizing a method, but I have come to realize that they are more than just methods. They are Composables, entities that have their own significance. From my perspective, representing them as functions with annotations is simply a current language workaround. I appreciate the explanation of the factory function as well.
r
Thanks for the insight everyone! And an extra thanks for pointing out that passage in the style conventions @Klitos Kyriacou. I definitely overlooked that part... I guess past me never considered I'd see or use this style lol