Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android id naming convention: lower case with underscore vs. camel case

Tags:

android

mobile

I'm currently programming an application for the Android. Now what I found out is that you cannot place resource objects, say, an image in the drawable folder and name it like "myTestImage.jpg". This will give you a compiler error since camel case syntax is not allowed, so you'd have to rename it like "my_test_image.jpg".

But what about ids you define in the XML file. Say you have the following definition

<TextView android:id="@+id/myTextViewFirstname"               android:layout_width="wrap_content"               android:layout_height="wrap_content"               android:text="Firstname" /> 

This is a valid definition, compiles and works just fine on my Android emulator although - as you see - I'm specifying the id in camel case syntax.

Now, the Android samples always use lower case and underscore. Is this just a naming convention to use lower case with underscore for the id's or may it cause problems on the real device?

Thx

like image 290
Juri Avatar asked Dec 02 '09 11:12

Juri


People also ask

Should I use camel case or underscore?

Results indicate that camel casing leads to higher accuracy among all subjects regardless of training, and those trained in camel casing are able to recognize identifiers in the camel case style faster than identifiers in the underscore style.

What is the difference between underscore case and camel case?

When multiple words are used to form a variable, camel case joins those words together, without any white space, and delineates the start of each new word with a capital letter. In contrast, snake case uses an underscore between words to create separation.

Does camel case use underscores?

are all examples of camel casing. Pascal casing is similar to camel casing except that the first letter also starts with a capital letter (SomeClass instead of someClass). In underscore casing, everything is in lower case (even acronyms) and the words are separated by underscores (some_class, some_func, some_var, etc).

Which naming convention is used in camelCase?

What is CamelCase? CamelCase is a way to separate the words in a phrase by making the first letter of each word capitalized and not using spaces. It is commonly used in web URLs, programming and computer naming conventions. It is named after camels because the capital letters resemble the humps on a camel's back.


1 Answers

The device will not complain if you use camel-case id names. For my first application I wrote all the ids in camel-case because I think it appears better in the Java code that way, and it works just fine.

I am slowly changing my mind on camel-case, though, because you end up with two different naming conventions - for example:

// This must be undescored due to naming constrictions setContentView(R.layout.my_long_layout_name);  // Now this looks a little out of place findViewById(R.id.myLongSpecificId); 

I, too, wonder about the standards here. Google is inconsistent in their examples; sometimes they use all lowercase, sometimes they insert underscores, and sometimes they use camel-case.

like image 168
Dan Lew Avatar answered Oct 16 '22 06:10

Dan Lew