I prefer underscores for fields, too, but I'd still use the belowmentioned constructor argument syntax if I wanted to set a property corresponding to a field so as to take advantage of any format-checking in the property setter:
class PolarCoordinate extends Object { public function PolarCoordinate(radius:Number, theta:Number) { super(); this.radius = radius; this.theta = theta; } public function get radius():Number { return _radius; } public function set radius(value:Number):Void { if (isNaN(value) || !isFinite(value)) { // Default to 0. _radius = 0; } else { _radius = value; } } public function get theta():Number { return _theta; } public function set theta(value:Number):Void { if (isNaN(value) || !isFinite(value)) { // Default to 0. _theta = 0; } else { // Normalize: 0 ≤ θ < 2π while (value < 0) { value += Math.PI * 2; } while (value >= Math.PI * 2) { value -= Math.PI * 2; } _theta = value; } } private var _radius:Number; private var _theta:Number; } �D Mike Keesey > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:flashcoders- > [EMAIL PROTECTED] On Behalf Of JOR > Sent: Thursday, October 12, 2006 7:27 PM > To: Flashcoders mailing list > Subject: Re: [Flashcoders] Moving to AS2, array always undefined > > No, it isn't wrong which was entire the point of my earlier response. I > gave essentially the same example as you. In fact, you've included it > quoted at the bottom of your response which I left intact. > > However, just because it is correct doesn't mean I prefer it over other > conventions. I prefer to use underscores with my field names. > > -- james > > > > Ash Warren wrote: > > "In practice, you're right and I try not to name any parameters the same > as > > a field name to avoid "this" confusion. Don't tell anyone, but > sometimes I > > don't even use "this". :)" > > > > So this is wrong? > > > > function MyClass (myParam1:Number, myParam2:String) > > { > > this.myParam1 = myParam1; > > this.myParam2 = myParam2; > > } > > > > For me this method seems much easier to read and it even refers to > naming > > parameters this way in the adobe best-practices article. > > > > Why try and come up with 2 names for the same thing, when one will > suffice > > just fine? > > > > -----Original Message----- > > From: [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED] On Behalf Of JOR > > Sent: Tuesday, October 10, 2006 5:52 PM > > To: Flashcoders mailing list > > Subject: Re: [Flashcoders] Moving to AS2, array always undefined > > > > A bad practice most likely, but not technically wrong. I do see it in > > text books from time to time. I was just mentioning it as a case where > > "this" *would* be needed as opposed to speaking in absolutes. > > > > In practice, you're right and I try not to name any parameters the same > > as a field name to avoid "this" confusion. Don't tell anyone, but > > sometimes I don't even use "this". :) > > > > James O'Reilly - Consultant > > Adobe Certified Flash Expert > > http://www.jamesor.com > > Design . Code . Train > > > > > > > > Steven Sacks | BLITZ wrote: > > > >>Correct me if I'm wrong, but it looks like your rationale is entirely > >>based on an argument name being identical to a class variable name. I > >>might be looking at this too simply, but shouldn't you just use a > >>different argument name if it clashes with a class variable name? > >> > >>-Steven > >> > >> > >> > >> > >>>-----Original Message----- > >>>From: [EMAIL PROTECTED] [mailto:flashcoders- > >>>[EMAIL PROTECTED] On Behalf Of JOR > >>>Sent: Tuesday, October 10, 2006 1:19 PM > >>>To: Flashcoders mailing list > >>>Subject: Re: [Flashcoders] Moving to AS2, array always undefined > >>> > >>>Actually, the "need" is dependent on the implementation. > >>> > >>>It was my understanding that AS first looks to the local scope for the > >>>existence of a variable then works up to find it. By using "this" you > >>>were explicitly telling flash that the var isn't local to the function > >>>but rather belongs to the object cutting out a step for the VM. > >>> > >>>Therefore, something like the following becomes possible and the use > >> > >>of > >> > >> > >>>"this" becomes necessary: > >>> > >>>class MyConstructor { > >>> private var target:MovieClip; > >>> public function MyConstructor (target:MovieClip) { > >>> this.target = target; > >>> } > >>>} > >>> > >>>Because you can not do this: > >>> > >>>class MyConstructor { > >>> private var target:MovieClip; > >>> public function MyConstructor (target:MovieClip) { > >>> target = target; // ? > >>> } > >>>} > >>> > >>>However, depending on your naming conventions you "might" not have to > >>>use "this" if you did something like the following: > >>> > >>>class MyConstructor { > >>> private var _target:MovieClip; > >>> public function MyConstructor (target:MovieClip) { > >>> _target = target; > >>> } > >>>} > >>> > >>>Even still, I think the VM might check for the existence of a var > >> > >>named > >> > >> > >>>_target local to the constructor function before locating the object's > >>>field named _target. > >>> > >>>It's been a while since I've done anything in AS1 so I may be way off > >>>here but I thought I remembered "this" being necessary because at > >> > >>weird > >> > >> > >>>times the VM would think you were trying to instantiate a local var if > >>>you didn't use "this". Particularly in "on (something)" event > >> > >>handlers. > >> > >> > >>>Maybe I'm thinking of _global, or perhaps both. This, I'm not sure > >>>about... if you'll excuse the pun. :) > >> > _______________________________________________ > Flashcoders@chattyfig.figleaf.com > To change your subscription options or search the archive: > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > Brought to you by Fig Leaf Software > Premier Authorized Adobe Consulting and Training > http://www.figleaf.com > http://training.figleaf.com _______________________________________________ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com