Home > Net >  Naming Conventions?
Naming Conventions?

Time:03-21

I am following this official code style guide for Kotlin (link goes to the section in particular): https://kotlinlang.org/docs/coding-conventions.html#property-names

This is my first time following a Code Style guide, so I want to verify, are they saying that all variable names that aren't immutable should be in UpperCamelCase?

The second example shows a mutable list, so I assumed that it is only for variables that hold array like data.

So my conclusion was that I should use the third example's UpperCamelCase for all regular variable names, like a findViewById<Button> val.

What I assumed seems wrong, so is it the LowerCamelCase for such variables given in the second example? And only special objects get UpperCamelCase? I am asking for simple things like findViewById<Button>, Strings, Ints, Booleans, etc.

CodePudding user response:

I think you made a confusion reading the documentation. But to clarify:

  • Deeply immutable data (like constants): SCREAMING_SNAKE_CASE
  • References to singleton objects: UpperCamelCase
  • All other cases: lowerCamelCase

So for your cases of findViewById, Strings, Ints, Booleans (since your Strings and Ints aren't constants), then you should use lowerCamelCase.

  • Related