https://kotlinlang.org logo
#android
Title
# android
c

Cody Engel

02/22/2020, 2:34 PM
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

sajadgarshasbi

02/22/2020, 3:46 PM
camel case with View at end, like userNameView
r

rolgalan

02/22/2020, 4:17 PM
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

Sean Keane

02/22/2020, 4:20 PM
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

ghedeon

02/22/2020, 5:56 PM
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

Cody Engel

02/22/2020, 6:03 PM
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

Mark

02/23/2020, 2:29 AM
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

ghedeon

02/23/2020, 3:17 AM
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

jw

02/23/2020, 3:17 AM
My least favorite part of view binding is the camelCase conversion!
👍 2
e

Erik

02/23/2020, 7:16 AM
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

farzad

02/23/2020, 9:32 AM
@jw Why camelCase conversion is not so delightful to you?
g

ghedeon

02/23/2020, 12:53 PM
probably because it's not this library's job to make assumptions about your code style..
s

Saurabh

02/23/2020, 2:30 PM
I don't like using kotlin synthetics at all, I do prefer view binding or even the basic
findViewById
over it.
s

stantronic

02/25/2020, 3:00 PM
We have snake case. Looking into adopting view binding and databinding though.