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
Youssef Shoaib [MOD]
05/21/2023, 9:55 PM
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
LeoColman
05/21/2023, 9:59 PM
Adding to that, I think it's within the expected code style. Kotlin itself does it to the
Exception: factory functions used to create instances of classes can have the same name as the abstract return type
s
Stefan Oltmann
05/22/2023, 10:02 PM
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
Ryan Smith
05/22/2023, 10:07 PM
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