Hello. Do you have any code styling conventions wh...
# anko
d
Hello. Do you have any code styling conventions when you define layout with anko? With xml layouts the AS formatter will reorder attributes and you have attributes by definition at the top, but with anko dsl you can do whatever you want and the code can be really messy
m
Hello. Generally, you can write DSLs same way you write ordinary Kotlin code. For me it's handy to use two-space indentation, but not many people like it 🙂 https://kotlinlang.slack.com/archives/codingconventions/p1489073710228102
d
Generally, you can write DSLs same way you write ordinary Kotlin code.
- that is the main reason of my question 🙂 I think that layouts should have some strict rules and ordering .. eg. properties (padding, textColor, etc.), listeners, child views
m
@david.bilik I write id first (useful with RelativeLayouts and view state saving), then all view parameters, then all child views. Also I write anonymous adapters right in DSL, but this may be discouraged by some conventions.
Posted example in a channel.
d
nice, thanks 🙂 Do you have any special reason why you use layoutParams = ViewGroup.LayoutParams(…) instead of lparams from anko?
m
@david.bilik yes, they typically come first in XML, so I don't want them to get lost in the end in DSL.