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**

If the modifications are not apparent enough as is, you may need to use one last trick.

Alphabetically Sorting by Groups

If your IDE supports it, give this option a shot to see if it improves the readability of your code.

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

public static var shots:Array;

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

public var score:int;
public var upgrades:Array;
FlashDevelop supports this – Select the entire groups of variables (including static, constants, private, public, etc.) and choose Edit - Sort Line Groups

With all of the changes that we have done at this point, hopefully you can see a noticeable improvement from when we started!

Conclusion

Mr. Clean

Mr. Clean, approving your work!


In the end, you have to subjectively decide “Have I done enough? Can I re-arrange this any further?” . If you find yourself making minor tweaks, face a brick-wall and undo  those tweaks, this is generally a sign you have done all you could to perfect the code.

When there are no further changes to be made, you will know you are done!

For More Information

These “best practices”  that I share with you in this blog are a sum of all the habits, personal research and company code-standards that I have cultivated over the years. If you want to improve your programming skills, I can’t recommend this book enough:




Clean Code: A Handbook of Agile Software Craftsmanship
by Robert C. Martin 
Amazon link: http://www.amazon.ca/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882

Although this book isn’t aimed only for ActionScript 3.0 developers, using the advice of this book will make a huge difference in your code. Your coworkers, and yourself, will thank you for it.

If you have any other suggestions for “Clean Coding” , please share it in the comment form below! :)

  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**