Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > General > Best Practices

Reply
 
Thread Tools Rate Thread Display Modes
Old 11-25-2007, 01:11 AM   #1
Flash Gordon
rather be programming
 
Flash Gordon's Avatar
 
Join Date: Feb 2005
Location: City of Angels
Posts: 10,000
Default Does protected get an underscore?

What are your standard coding practices for variables? How would you do this:
ActionScript Code:
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

So what is your way or the "standard" way?
__________________
I'm old enough to know better and young enough to do it anyway. -- maskedman
Flash Gordon is offline   Reply With Quote
Old 11-26-2007, 01:33 AM   #2
newblack
dondeEstanMisPantalones?
 
newblack's Avatar
 
Join Date: Nov 2005
Location: New York Proper
Posts: 1,173
Send a message via AIM to newblack
Default

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 am gibreel farishta
general relativity
jellytanks alpha redux
newblack is offline   Reply With Quote
Old 11-26-2007, 01:40 AM   #3
Flash Gordon
rather be programming
 
Flash Gordon's Avatar
 
Join Date: Feb 2005
Location: City of Angels
Posts: 10,000
Default

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!
__________________
I'm old enough to know better and young enough to do it anyway. -- maskedman
Flash Gordon is offline   Reply With Quote
Old 11-26-2007, 02:03 AM   #4
Assertnfailure
as[org].addListener(this)
 
Assertnfailure's Avatar
 
Join Date: Dec 2005
Location: LA, California
Posts: 838
Default

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.
Assertnfailure is offline   Reply With Quote
Old 11-26-2007, 06:00 AM   #5
MichaelxxOA
Flash Sucks
 
MichaelxxOA's Avatar
 
Join Date: Mar 2005
Location: Victorville, Ca
Posts: 2,224
Send a message via AIM to MichaelxxOA Send a message via MSN to MichaelxxOA Send a message via Yahoo to MichaelxxOA Send a message via Skype™ to MichaelxxOA
Default

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

ActionScript Code:
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 ...

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

idk ...

Last edited by MichaelxxOA; 11-26-2007 at 06:02 AM..
MichaelxxOA is offline   Reply With Quote
Old 11-26-2007, 07:46 AM   #6
Flash Gordon
rather be programming
 
Flash Gordon's Avatar
 
Join Date: Feb 2005
Location: City of Angels
Posts: 10,000
Default

LoL...everybody does it differently. Same concepts but different ways of implementing that concept. That's good to know!
__________________
I'm old enough to know better and young enough to do it anyway. -- maskedman
Flash Gordon is offline   Reply With Quote
Old 01-07-2008, 05:22 AM   #7
peptobismol
Senior Member
 
Join Date: Oct 2005
Posts: 282
Default

i picked this up from my teacher... using 'in' in front of the variable in the parameter.. it's much easier to understand.

ActionScript Code:
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.
peptobismol is offline   Reply With Quote
Old 02-07-2008, 03:11 PM   #8
panel
AS3
 
panel's Avatar
 
Join Date: Mar 2007
Location: Warsaw
Posts: 1,761
Send a message via Skype™ to panel
Default

Quote:
Originally Posted by newblack View Post
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

Quote:
Originally Posted by Assertnfailure View Post
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
panel is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Inheritence question GuyFawkes ActionScript 3.0 12 11-02-2007 05:39 PM
Extending a basic framework for specific needs. Flash Gordon Best Practices 2 09-17-2007 01:13 AM
protected members felipe_chs ActionScript 2.0 1 04-24-2007 01:55 PM
meaning of the underscore billingsgate Components 10 02-11-2006 05:22 PM
Can we start an XML tag by an underscore ? Mathieu_BSL ActionScript 2.0 3 04-24-2005 06:58 PM


All times are GMT. The time now is 06:36 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.