There are many ways to do camel-case. When given the choice, I use
the following rules, because they are simple and easy to follow and
don't require any exceptions to be made for certain words.
e.g. for type names or other cases where you want the first letter capitalized.
Upper-case the first letter of each word, then smash the words together.
- "party sauce" becomes "PartySauce"
- "XML decoder" becomes "XMLDecoder"
- "XML HTTP request" becomes "XMLHTTPRequest"
- "I need a new ID card" becomes "INeedANewIDCard"
Ususally used for variables and property names
Lower-case all words completely, upper-case the first letter of each exept the first, then smash the words together.
- "party sauce" becomes "partySauce"
- "XML decoder" becomes "xmlDecoder"
- "XML HTTP request" becomes "xmlHttpRequest"
- "I need a new ID card" becomes "iNeedANewIdCard"
I've seen other conventions that are less self-consistent or give bad results.
- lowerCamelCasing by lower-casing the first letter of the first word without lower-casing all words results in things like "xMLHTTPRequest", which bothers me.
- lowerCamelCasing by lower-casing the entire first word can results in things like "xmlHTTPRequest", which also bothers me.
- In either upper or lower-camelcase, some codebases arbitrarily
allow certain words to keep their original case while others are
well-known example. But "ID" tends to get special treatment, too.
This just makes it harder to follow a convention because a list of
exceptions needs to be referenced.
- Allowing words under a certain length (such as 3 characters) to
keep their original casing, but transforming others. Similar to the
previous case, why add unnecessary exceptions?
Thank you for visiting my web site.
If you enjoyed this article,
you may also like 'how to use tabs for leading indentation'.