PDA

View Full Version : Does protected get an underscore?


Flash Gordon
11-25-2007, 12:11 AM
What are your standard coding practices for variables? How would you do this:

protected var foo:Number = 0;
// or
protected var _foo:Number = 0;


Do you save the underscore to private only? I seen senocular go back and forth between the 2 conventions.
PROTECTED UNDERSCORED (http://senocular.com/flash/actionscript.php?file=ActionScript_3.0/com/senocular/drawing/Path.as)

So what is your way or the "standard" way?

newblack
11-26-2007, 12:33 AM
I think this is really preference... underscores are certainly not necessary anywhere.

I do use them for both private and protected- 99% of the time my member properties are protected as opposed to private, so my differentiation is public vs. non-public for all intents and purposes.

Flash Gordon
11-26-2007, 12:40 AM
yea, I know there has been several threads on coding style, but i didn't see anything speficly about stuff like conts, protected vs private.

I know assertainfailure tends to use underscore only for private, so I just looking for some other people's inputs. And I've seen senocular go back and forth between them.

I tend to use underscore for them both as well, but I picked that up from a Colin Mook book I believe.

Thanks for responding!
:)

Assertnfailure
11-26-2007, 01:03 AM
You know....i am more inclined to think of protected as public rather than private. If you closed off your class to modification, devs can still see the protected properties via subclassing as if they had been exposed publicly.

My conventions are a bit more extreme, however.....
Generally speaking, I don't even use underscores for private properties. The only exception are private properties that are associated with getters/setters.

MichaelxxOA
11-26-2007, 05:00 AM
These habits I have picked up, and I stick to ... some actually because of Noobblack, even though I was arguing with him about it ...

It seems like most of the time I have read-only properties, but if a class is planned to be extended it will have its protected properties. Either way anything that is exposed I try to keep short and just letters (no underscores). I do use underscores though when I have read-only properties ... like


private var _velocity:Vector;
public function get velocity():Vector { return _velocity; }


Usually it seems like read-only properties aren't set in too many places, especially if they are objects. And the underscores make distinguishing where you set them easier(?), but I'm not arguing it ... everyone has there style.

For parameters I try to keep in mind the rest of the api ... If for instance initializing an object with it's position I don't mind using this in the constructor, so that I can keep the parameter as just x ...


public var x:Number;
public var y:Number;

public function Vector( x:Number, y:Number )
{
this.x = x;
this.y = y;
}


idk ...

Flash Gordon
11-26-2007, 06:46 AM
LoL...everybody does it differently. Same concepts but different ways of implementing that concept. That's good to know!

peptobismol
01-07-2008, 04:22 AM
i picked this up from my teacher... using 'in' in front of the variable in the parameter.. it's much easier to understand.


public var x:Number;
public var y:Number;

public function Vector( inx:Number, iny:Number )
{
x = inx;
y = iny;
}


And the this keyword is always confusing in AS2... Sometimes flash doesn't care, sometimes it does.

panel
02-07-2008, 02:11 PM
I think this is really preference... underscores are certainly not necessary anywhere.

I do use them for both private and protected- 99% of the time my member properties are protected as opposed to private, so my differentiation is public vs. non-public for all intents and purposes.
I do exectly the same thing

You know....i am more inclined to think of protected as public rather than private.

I am thinking about protected more as private becouse yuo cannot acess it 'from outside', but as Flash Gordon said everybody does it differently...


Trully it dosen't matter witch style you choice - just stay with it (at least to oend of current project). My style still evolving