Get $500+ of the best After Effects files, video templates and music for only $20!
Open Mike: Capitalization

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:

var textBox:TextBox = new TextBox();

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?

Add Comment

Discussion 10 Comments

  1. André says:

    Yeah, i think i am inside the conventions!!

    lowerCaseCammel for variables and functions
    UPPER_CASE for consts
    _underscore for private variables and functions
    UpperCaseCammel for classes…

    I think it´s the basic in my opinion….

  2. Y says:

    I use lowerCamelCase for variables, functions
    I usually use UpperCamelCase for constants, but I put a lowercase “k” in front like: kMaxFrames (I think I stared doing that from iPhone Obj-C…)
    I usually don’t underscore or prefix my private variables
    Definitely UpperCamelCase for classes (Same for constructor functions (and static helper functions that return a new instance of the class))
    Acronyms I’ll capitalize (myXMLConverter) unless it doesn’t have a prefix (like xmlConverter)

    Pretty much the way I’ve always done it…

  3. Brett says:

    I pretty much agree with André, but my acronyms all follow the first letter. For example, when I create a loader for XML, I call it xmlLoader or something, but then with the ‘complete’ event listener on the loader, I name the function onXMLLoaded or something similar.

  4. Seems like I’m entirely conventional :D
    Except for the last one. I use the same case as the first letter fro acronyms.

    All the same for Java, but if I write codes in PHP I use their conventions, like writing method names with underscores some_method()

  5. Well, i think the one factor that should dictate the way you code is readability. If you and your team can read trough your code without stoping every 2 / 3 lines, it’s good. Obviously conventions are there for a reason, so you can share code and get code from others and still read it like it was yours.
    The problem is, sometimes conventions aren’t always right. I’ll take php for example, they have the most awful set of conventions that differ from anything else in the business. Dollar sign for variables? Seriously? Not a single other language uses that, so for me, that’s a bad thing.
    This is just to show you the ups and downs of conventions, obviously I advise you to follow as much them as you can, but when it interferes with your code readability you should avoid them.

    As for me i use the following:

    Variables: lowerCaseCammel
    Constants: UPPER_CASE_WIDHT_UNDERSCORES
    Methods: lowerCaseCammel
    Event Handlers: target_eventHandler
    Class Names: UpperCaseCammel
    Acronyms: XMLLoader

  6. As for me i use the following:

    Variables: lowerCaseCammel
    Constants: UPPER_CASE_WIDHT_UNDERSCORES
    Methods: lowerCaseCammel
    Event Handlers: onSomeEvent
    Class Names: UpperCaseCammel
    Acronyms: XMLLoader
    Private Variables: _lowerCaseCammel;
    Public Variables: lowerCaseCammel;

    How u guys use function parametrs?

    1). someFunction($param1:Type, $param2:Type) or 2). someFunction(pParam1:Type, pParam2:Type)

    How u guys use variables types in thair names?

    1). someVariable_type or 2). typeSomeVariable or 3). someVariableType or 4). someVariable

    Examle:
    var mcBall:MovieClip;
    var ball_mc:MovieClip;
    var BallMc:MovieClip;
    var ball:MovieClip;

Add a Comment

To add a code snippet to your comment, please wrap your code like so: <pre name="code" class="html">YOUR CODE</pre>. You can replace the class name with "js," "css," "sql," or "php." If there are any "<" or ">" within your code, please search and replace them with: &lt; and &gt; respectively.