Advertisement
Open Mike

Open Mike: Capitalization

by

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?

Related Posts
  • Code
    Mobile Development
    C++ Succinctly: Pointers, References, and Const-CorrectnessPreview image@2x
    Even though the concept of a pointer is simple, many people struggle with this topic. A pointer is nothing more than a variable that holds a memory address. After reading this article, pointers and references should no longer have secrets for you.Read More…
  • Code
    Mobile Development
    C++ Succinctly: Functions and ClassesPreview image@2x
    In this article, we discuss functions and classes in C++. You'll learn the difference between declaration and definition and we'll take a look at inheritance, abstract classes, and precompiled header files.Read More…
  • Business
    Marketing
    How to Write an Online Market Research SurveyResearch survey
    Market research is the key to a successful business. If your business isn’t meeting a need, you’ll struggle to get customers through your doors. Market research is your way of discovering what your customers need. Once you know that, you’ve got the foundation of a successful business.Read More…
  • Code
    JavaScript & AJAX
    Testing in Node.jsNodejs testing chai retina preview
    A test driven development cycle simplifies the thought process of writing code, makes it easier, and quicker in the long run. But just writing tests is not enough by itself, knowing the kinds of tests to write and how to structure code to conform to this pattern is what it's all about. In this article we will take a look at building a small app in Node.js following a TDD pattern.Read More…
  • Code
    iOS SDK
    Objective-C Succinctly: Methods0e5ds8 preview image@2x
    In this chapter, we'll explore Objective-C methods in much more detail than we have in previous chapters. This includes an in-depth discussion of instance methods, class methods, important built-in methods, inheritance, naming conventions, and common design patterns.Read More…
  • Code
    iOS SDK
    Objective-C Succinctly: Hello Objective-C0e5ds8 preview image@2x
    This chapter is designed to help you acclimate to Objective-C programming style. By the end of this chapter, you will be able to instantiate objects, create and call methods, and declare properties. Remember that the goal is to provide a very brief survey of the major object-oriented aspects of Objective-C, not a detailed description of each component. Later chapters fill in many of the conceptual details omitted from this chapter.Read More…