Advertisement
Open Mike

Open Mike: Prefixes

by

To underscore, or not to underscore? 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 prefixes.


Do You Put Underscores Before Variables?

AS3 developers often use underscores as prefixes for private or protected variables in a class:

private var _playerID:String;

Some coders find this a useful way to tell at a glance whether the var is available to other classes; others deride it as useless and ugly. Whose side are you on?



How About Method Arguments and Interfaces? What Else?

Other common prefixes are a_ for method arguments (or p_ for parameters), and I for interfaces.

public function takeDamage(a_damage:Number):void
{
	_damage-=a_damage;
}
package
{
	public interface IPlayerCharacter
	{
		function takeDamage(a_damage:Number):void;
	}
}

The "I for interface" prefix is pretty common, but argument prefixes are rarer.



Any others you use often? Let us know in the comments.


Hungarian Notation: Yea or Nay?

If those didn't bring out strong opinions, I've got two words for you: Hungarian notation.

No, I'm not talking about Systems Hungarian, where the data type of the object is encoded into a prefix of the name:

var intCounter:int = 0;
var boolBestScore:Boolean = false;
var nHeight:Number = 120;
var btnOK:SimpleButton = new Button();

No-one's still using that, are they? With a decent IDE you can tell the data type of any variable easily; there's little need to have that information in the name of the variable.

I'm talking about Apps Hungarian, where the purpose of the object is encoded into a prefix of the name:

var dHeight:Number = newHeight - oldHeight;	//d for 'difference'
var cChildren:int;	//c for 'count'
var degAngle:Number;	//deg for 'degrees'
var radAngle:Number;	//rad for 'radians'

(Check out Joel Spolsky's excellent article Making Wrong Code Look Wrong for more information on this.)

Do you use any form of Hungarian notation, or is it completely unnecessary in an OOP language like AS3?


Related Posts
  • Code
    PHP
    Object-Oriented Programming in WordPress: Functions and AttributesWordpress oop
    As we continue our discussion of object-oriented programming within the context of WordPress, it's time for us to begin talking about actual features of object-oriented programming. Though we've already covered classes, we needed to explore some foundational programming constructs before coming back around to some of the core object-oriented concepts. In this article, we're going to begin talking about functions and attributes: two foundational aspects of object-oriented programming.Read More…
  • Game Development
    Implementation
    Write Once, Publish Everywhere With HaxePunk: Making a GamePreviewretinaimage
    You've probably had this experience before: you hear about an awesome game, but then you find out that it's only coming out on the one platform that you don't own. It doesn't have to be this way. In this tutorial, you will learn how to use Haxe to make a game in one development platform that can target multiple gaming platforms, including Linux, Mac, Windows, iOS, Android, and Flash.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…
  • 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…
  • Code
    Cheat Sheets
    The WordPress Coding Standards: Naming Conventions and Function ArgumentsThe wordpress coding standards
    In this series, we're taking a deep dive into the WordPress Coding Standards - specifically, the PHP coding standards - in order to evangelize and understand how quality WordPress code should be written. Despite the fact that this is documented within the WordPress Developer Handbook, I think there's something to be said for understanding the rationale behind why some things are the way that they are. Remember: Our ultimate goal is to make sure that we're writing code that conforms to the coding standards so that we, along with other developers, are able to more easily read, understand, and maintain code for themes, plugins, and applications built on top of WordPress. In this post, we're going to be taking a look at how to handle naming conventions and function arguments.Read More…