Open Mike: Capitalization

UpperCamel, or lowerCamel? This is Open Mike, a series of discussion posts to throw the cat amongst the pigeons. These posts are all about you — we want to hear your opinions, ideas, and thoughts. Due to popular demand, this Open Mike includes a poll to help us analyze opinion, so let's hear what you have to say about capitalization.


The Three Main Styles of Capitalization

There are three common capitalization styles used by AS3 programmers:

  • UpperCamelCase
  • lowerCamelCase
  • ALL_UPPERCASE_WITH_UNDERSCORES

I've seen others in use, too:

  • all_lowercase_with_underscores
  • lowercaseprefix_thenCamelCase

...but those first three are by far the most common. Which should you use, and where?


What do You Use For Variables and Consts?

Almost every API and tutorial I've seen uses lowerCamelCase for variables (sometimes with a prefix depending on the scope of the var).

Consts are usually ALL_UPPER_CASE_WITH_UNDERSCORES, though this doesn't seem to be such a hard and fast rule, for some reason.

What do you think?




What do You Use For Functions and Methods?

If you've been watching our Silverlight series you might have noticed that .NET functions and methods typically use UpperCamelCase, while in AS3 it's more common to use lowerCamelCase. I have no idea how or why this split came about. Any ideas?

For getter and setter functions, it makes sense to use the same type of casing as you do for public variables. After all, why make it obvious that it's not a "real" property?



What do You Use For Class Names?

UpperCamelCase is the usual choice for class names, partly because it gives an easy option for the name of an instance of that class:

Of course, this assumes you're using lowerCamelCase for your variable names.



How do You Deal With Acronyms?

Let's say you've got a utility class that converts XML to different formats. Let's also say, for the sake of argument, that you use UpperCamelCase for your class names. What do you call the class?

  • XMLConverter
  • XmlConverter

Likewise for the name of an instance of this class: myXmlConverter or myXMLConverter?



Any Exceptions?

Consider constructor functions: they're functions, but they have to be given the name (and thus the capitalization) of their class. Unless you use the same conventions for naming functions and classes, this is going to break one of your rules. Is there anywhere else you make such exceptions?

Tags:

Comments

Related Articles