featured_image

  1. Overview of the Refactoring process
  2. Identify and Group your Access Modifiers
  3. Choose Wise Variable Names, Prefixes and Suffixes
  4. Sort each Access Modifier Groups Alphabetically
  5. **View All**

What is the point of coding if you can’t make any sense of the very thing that holds your data? Well, there really isn’t a point. Even though I might of personally done this myself, it drives me nuts to see meaningless variable names used in a function that seems to do a very complex task. I would at least urge everyone to make the member variables (Class and Instance level) self-explanatory and relevant. If you want to go the extra mile, I would encourage people to apply the following rules to the local variables as well:

Boolean (on/off) values should be in the form: is****, has****, can**** , depending on whether it’s about a status , an ownership , or an ability .
Integer values used for counting  certain items should be in the form: num**** , or ****Total  depending on whether you wish to match the prefix of another variable or not.
– Multiple variables or constants pertaining to a similar context should use the same prefix to keep them alphabetically tied together.
variables that refers to a selected object in some manner should be in the form: current****.
variables that hold a collection of objects (Arrays) should be in their plural form, or suffixed with: ****List.

A few extra good naming conventions for specific data-types:

XML variables should be of the form: x**** (ex: xDocument, xElements, xImages).
XML attribute references should be of the form: a**** (ex: aDocumentName, aElementID, aImageURL).
Arguments (or parameters) in a method declaration should be prefixed by: p**** (ex: pFileList, pIsAlive, pCallback).
Dynamic Argument Lists (where any number of parameters can be passed) should simply be: … args, or … pArgs

public static const FIRING_SPEED:int;
private static const _FIRING_INTERVAL:int;

public static var shots:Array;

private var _speed:int;
private var _shotsFiredTotal:int;
private var _angle:Number;
private var _numOfLives:int;
private var _currentWeapon:Weapon;

public var score:int;
public var upgrades:Array;

Now imagine if this had a few more dozen lines of variable declarations. With the steps we have taken so far, it would be more meaningful, yes… but the line-order of your declarations might get you cross-eyed!

Let’s see what we can do to improve the flow of our code.

  1. Overview of the Refactoring process
  2. Identify and Group your Access Modifiers
  3. Choose Wise Variable Names, Prefixes and Suffixes
  4. Sort each Access Modifier Groups Alphabetically
  5. **View All**