I thought that AS3 now has private abilities added. So why should I still preface private variables with an underscore?
private var _privVar:String;
I make it a general rule in ActionScript 3 to follow Adobe's style.
Don't use underscores for private varibles unless your using a getter or setter. For example:
private var _foo:String;
public function get foo():String
{
return _foo;
}
public function set foo(value:String):void
{
_foo = value;
}
This example getter/setter is a little useless, as you could just make a public property that does the same thing. Only use a getter or setter when you need to do something special when you get or set the property. Even then, it's usually best just to create a public method instead.
Also another point. Personally I don't think it's a good idea to abbreviate your variable or method names. So instead of calling my variable privVar, I would call it privateVariable. This is especially true if you are using an IDE with autocomplete/suggest such as FlashBuilder(Flex Builder) or FlashDevelop.
Take a look at Adobe - coding conventions and best practices for more information.
You don't have to. It's something that encourages readability, but is by no means mandatory. Entirely a personal preference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With