camelCase vs under_scores
Posted by Jesse Freeman | Filed under Advanced Topics
One of my pet peeves is code you can’t read or understand by quickly glancing over it. Since the roots of ActionScript come from a language where everything was written in camel case that doesn’t make it right. I have long favored underscoring my variable names and methods and here is why.
About 2 years ago when I worked on the new New York Jets site I had a great opportunity to talk to Matt Pelletier from East Media about Ruby naming conventions. We began talking about why Flash Developers used camel case and when he asked me why camel case was better I didn’t really have a valid answer. At the time my only excuse was to save file space (probably a couple of k here and there) and also because that is how the core methods in AS is written so I followed Macromedia (Now Adobe’s) convention. When I looked through his ruby code I realize just how much cleaner variable names were. I eventually began adopting the ruby style underscore with long descriptive variable/method names and haven’t looked back since.
Lets take a look at a few examples. It is hard to see the downfalls of camel case because as Flash and JavaScript developers you are trained to read it. Even the names “JavaScript ” and “ActionScript” are suppose to be written in Camel Case.
Example 1: Variable Name
Now a more descriptive underscore variable name:
now the underscore version
So whats the big deal? Well when you begin to move over to underscore naming conventions you will find it easier to write more descriptive variable names without having to truncate or abbreviate parts of the name because of how complex long camel case names look.
Example 2: Method Name
now the underscore version
It may just be me but I feel with the underscores you can easily read exactly what the method does without getting hung up in the alternating Case.
Example 3: Forced uppercase words
now the underscore name
So this one is kind of a special case example where you could just do “containerMCGroup” but that look really hard to read, so when you make the “C” Lowercase it adds a strange weight to the letters (sorry I am a designer after all so I pay attention to these kinds of things). With the underscore version you don’t have to force any part of the variable name to be upper or lower case just to make it fit the camel case naming convention.
The move towards using underscores is a difficult one and I don’t know may Flash Developers who do this but once you accept having longer variable/method names to have legible descriptive ones the benefits pay off.
-
Nathan
-
Maudlin
-
Michael
-
John
-
John
-
John
-
Daniel Ribeiro Maciel
-
FlashBum
-
Rafael Cosman
-
Kfz Versicherung
-
Jozef
-
tom
-
Todd
-
Ben Novakovic
-
Alex Loret de Mola
-
Ben Overmyer
-
Adam Hill
-
kris
-
kris
-
felix
-
Peter
-
PENIX
-
FlashBum
-
sunny zandro












