This article on naming conventions is based on Java, some rules apply to other programming languages as well.
I highly recommend this article to new programmers who are yet to have their own naming styles (for functions, variables, etc).
This is especially useful if you are just starting to learn programming.
If you are a experienced programmer with your own naming styles, you may want read this and see if there is anything to improve your naming techniques.
Original article: http://java.about.com/od/javasyntax/a/nameconventions.htm
Note on meaningfulness and length:
When choosing a name for an identifier make sure it’s meaningful.
Don’t worry about the length of the name. A longer name that sums up the identifier perfectly is preferable to a shorter name that might be quick to type but ambiguous.
There are 4 types of letter cases for naming:
Lowercase is where all the letters in a word are written without any capitalization e.g.
1 while, if, mypackageUppercase is where all the letters in a word are written in capitals. When there are more than two words in the name use underscores to separate them e.g.
1 MAX_HOURS, FIRST_DAY_OF_WEEKCamelCase (also known as Upper CamelCase) is where each new word begins with a capital letter e.g.
1 CamelCase, CustomerAccount, PlayingCardMixed case (also known as Lower CamelCase) is the same as CamelCase except the first letter of the name is in lowercase e.g.
1 hasChildren, customerFirstName, customerLastName
Standard Java Naming Conventions:
Basically, follow the naming guidelines below when you write your programs, you will find your programming process more systematic, efficient and professional than if you don’t.
Packages: Names should be in lowercase. With small projects that only have a few packages it’s okay to just give them simple (but meaningful!) names:
12 package pokeranalyzerpackage mycalculatorIn software companies and large projects where the packages might be imported into other classes, the names will normally be subdivided. Typically this will start with the company domain before being split into layers or features:
12 package com.mycompany.utilitiespackage org.bobscompany.application.userinterfaceClasses: Names should be in CamelCase. Try to use nouns because a class is normally representing something in the real world:
12 class Customerclass AccountInterfaces: Names should be in CamelCase. They tend to have a name that describes an operation that a class can do:
12 interface Comparableinterface EnumerableNote that some programmers like to distinguish interfaces by beginning the name with an “I”:
12 interface IComparableinterface IEnumerableMethods (Functions): Names should be in mixed case. Use verbs to describe what the method does:
12 void calculateTax()string getSurname()
“Methods” in Java are equivalent to “functions” in other languages like C, C++ and JavaScript.
Variables: Names should be in mixed case. The names should represent what the value of the variable represents:
12 string firstNameint orderNumberOnly use very short names when the variables are short lived, such as in for loops:
1234 for (int i=0; i<20;i++){//i only lives in here}Constants: Names should be in uppercase.
123 static final int DEFAULT_WIDTHstatic final int MAX_HEIGHT
Android Drawable File Naming Problem – R cannot be resolved error due to capital letters
I also found some related information on naming conventions for Android Development: http://stackoverflow.com/questions/6758228/why-cant-file-names-in-the-drawable-folder-contain-special-characters-or-start
Why can’t file names in the drawable folder contain special characters or start with a capital letter?
Each file inside folder is translated into java field name inside R.java class:
12 drawableicon.png -> R.drawable.iconHence the reason for not using special characters inside file names, as they can no be used in Java names.
As for capital letters, I guess that’s to avoid one little problem in Windows vs. Linux environment. That’s because Linux thinks thatIcon.png
andicon.png
are different files, and Windows thinks thatIcon.png
andicon.png
is the same file. So anyone using Linux can create application that is not compilable on Windows.
I had personally faced this problem when I was developing my own Android App for an competition. I was given some error like this:
1 |
R cannot be resolved |
It took a while for me to realize the problem lies in the naming of the images files in the drawable folder. I changed the capital letters to small letters and problem was solved. From that experience I learnt that naming is important in programming.