Hey everyone, when using Kotlin Synthetics how do ...
# android
c
Hey everyone, when using Kotlin Synthetics how do you name the view IDs? Do you stick with the traditional snake_case or do you go with camelCase? I’ve went with camelCase because it gives a consistent code style within the Kotlin files. Interested in what others do.
🐫 12
🐍 4
s
camel case with View at end, like userNameView
r
I keep using snake_case in xmls. Even it looks funny in Kotlin code if you are used to camelCase (specially when you have a strong java background), it helps to identify view elements really easily
👍 1
s
camelCase (see what I did there) with view at the end for the basic views (textView etc) and widget for views that have extra functionality.
g
snake_case proudly and intentionally. It stands out and the practicality of it is much higher for me than the abstract consistent code. Consistent with what? With you properties? But it's not really a property, why would you prefer to confuse them during the code review for example? Always sounded strange to me.
👍 3
c
Wow this is split more than I thought! I look at them as properties like any others. I look at the consistency being a win when you are running a tool like detect your don’t have two naming conventions to contend with
m
If you switch to ViewBinding then the properties on the Binding object are generated in camelCase regardless of whether camelCase or snake_case in layout.
🤔 2
g
in that case you'll always have
binding
in front. Means you'll never have to deal with a name clash like
myTitle.text = myTitle (error).
But without that prefix it matters, if you use synthetics, so
my_title.text = myTitle
is a neat bonus. Also, do you know those IDEA plugins, that show a small icon that allows you to navigate to Dagger declarations? That's what snake_case does for me, instantly shows me the points on the screen, where I can jump to xml.
j
My least favorite part of view binding is the camelCase conversion!
👍 2
e
If you want consistency in both XML and Kotlin and possibly some added confusion, then stick with snake case in XML and use camel case import aliases in Kotlin. Enjoy the extra work! 😅
f
@jw Why camelCase conversion is not so delightful to you?
g
probably because it's not this library's job to make assumptions about your code style..
s
I don't like using kotlin synthetics at all, I do prefer view binding or even the basic
findViewById
over it.
s
We have snake case. Looking into adopting view binding and databinding though.