https://kotlinlang.org logo
#compose
Title
# compose
t

Travis Griggs

10/27/2023, 3:38 PM
Style question: When you have a file with a primary "for use by others" composable, and it is made up of sub pieces (composables), do you tend to put the children above and the parent at the bottom to compose all of the pieces together? Or the other way around? Parent at top, with children below? The C programmer in me wants to do the former, but I'm curious if there's a common idiom/convention?
p

Pablichjenkov

10/27/2023, 3:47 PM
I do the second, adding at the end of the file is usually better for git diff than adding at the top. In c you don't have that luxury, you have to define first whatever you use, he used to it.
a

ascii

10/27/2023, 3:56 PM
If you're thinking of them as parent & child, then it makes more sense for parent to be defined first. If you instead see them as function depending on another function, the C-era arrangement can take over mentally.
1
I wish this Java code style thingy was available for Kotlin as well
👀 1
Also, at least for composables, its better if the "main" composable is defined right at the top because that's what most clients (read: callers) will see. They shouldn't care about internal child implementations.
t

Travis Griggs

10/27/2023, 4:40 PM
Do you put Previews at top or bottom?
a

ascii

10/28/2023, 3:28 AM
Previews at the bottom, but I'm conflicted if it should be below private vals or above them
2 Views