https://kotlinlang.org logo
Title
n

Nick

08/26/2021, 3:48 PM
Something that made life easy with the XML was to keep all the properties in the same order. Is there a way to keep all the parameters in the same order for a composable element/function?
r

romainguy

08/26/2021, 3:54 PM
In the same order compared to what?
c

Colton Idle

08/26/2021, 4:09 PM
I think in xml when you hit reformat code it put all of the "modifiers"/xml layout attrs into a particular order. I would also say that I found that helpful.
☝️ 1
I think this worked in AS due to this setting
f

Fudge

08/26/2021, 4:18 PM
That's problematic in compose because modifier order has semantic value
r

romainguy

08/26/2021, 4:20 PM
Right so the modifiers shouldn’t be re-ordered because there’s meaning in the ordering. For everything that’s a function parameter you should just keep them in the order they are declared in the functions
f

Fudge

08/26/2021, 4:26 PM
it might be useful to reformat the function parameters to the order they are declared in cases the code you wrote doesn't match that order. On another note I am a fan of formatting myself and there seems to be no good deterministic kotlin formatters out there. The closest I found is https://github.com/facebookincubator/ktfmt but it has this horrendous rule for assignments with multi-line function calls that puts the function name on the next line
val x = 
           longFunctionCall(a,b,c)   //what the hell
c

Colton Idle

08/26/2021, 4:29 PM
True. Probably not modifiers, but for composable args. e.g. It's kind of annoying to see two functions with named args, but the args are reversed. But anyway, it's less important than it was in xml land, but I think something would be nice for composable arg order
n

Nick

08/26/2021, 5:00 PM
Sorry, let me try to clarify more. in XML, I’ll hit “option + shift + L”, and all the attributes in XML are arranged in the same order. I can then option + shift + click and bulk edit each view since the attributes are in the same order. Now in Compose, I could have a column full of elements that are similar:
Text(
		text = "element 1",
		softWrap = false
	)
	Text(
		softWrap = false,
		text = "element 2"
	)
option + shift + L won’t reorder the params here. I have to reorder the params manually, then I can bulk edit them.
1
… For everything that’s a function parameter you should just keep them in the order they are declared in the functions
This is a manual process, and a lot of times I can’t remember the order without a “cmd + p”.
i think php storm can do it? https://www.jetbrains.com/help/phpstorm/php-named-arguments-order-does-not-match-parameters-order.html. (Now that I think of it, i’m probably posting this in the wrong channel 🙈 )
c

Colton Idle

08/26/2021, 6:55 PM
@Nick if you file an issue I'll
❤️ 1
n

Nick

08/26/2021, 7:07 PM
Thanks @Colton Idle 🙂.