Re: [flexcoders] WITH construction ?
You just illustrated why it's reducing readability. You have to read a lot more code to understand what is happening in the with statement. In your example you show x = 20, but where is x? is it on the object or is it in the function scope or is it in the parent object scope? This is why I think with should not be used. In javascript it improved performance slightly in some unique cases, but I don't think it's helpful in AS3. The only benefit I see for it is reduced typing, but that's just lazy in my opinion. Please type it out, it will help you out in the long run. I think the only time you should not state the scope of an assignment like that (ie x=20) is when the scope is local like in a function. Please use this whenever possible as well, even when you are the only one looking at your code. Oh and just because other languages have it does not make it a good idea. Lingo uses && for string concatenation, is that a good idea? Paul On Nov 6, 2007, at 2:45 AM, Samuel Colak wrote: Paul, apologies however languages such as C# include such a directive already - its not "reducing" readability at all - in reality I'm wondering if this is remotely possible in Flex. The issue I'm wondering about is that if you wrote the code below var object:Object = new Object(); With (object) { x = 20; trace("trap the app in debug here"); } and placed a breakpoint on the trace line - you'll note several things - 1) 'x' is defined as a variable of type Number (no var declaration which I didn't think possible) and outside of the scope of 'object' 2) object does not have a variable 'x'. How is it shown that 'x' is part of 'object' rather than an external variable ? In C#, the With statement is enacted in that properties of a object declared in the With construct are referenced in the following manner. With (object) { .x = 20; } Note the '.' ! Thanks & Regards Samuel On Nov 5, 2007, at 4:13 PM, Paul Decoursey wrote: I think that with should be avoided, it greatly reduces the readability of your code and makes maintaining it more difficult. On Nov 5, 2007, at 8:53 AM, Brent Dearth wrote: var o:Object = {a: 20, b: "twenty"}; trace (o.a + " " + o.b); with (o) { a = 40; b = "forty"; } trace (o.a + " " + o.b); On 11/5/07, Samuel Colak <[EMAIL PROTECTED]> wrote: Not quite what i mean - not to call the function but referring to properties inside the object - your demo implies a static object "Math" with functions cos and sin. inside the "object" i have a getter and setter for the property "x". Regards Samuel On Nov 5, 2007, at 10:56 AM, Edward Yakop wrote: I'm not sure what u meant, but [with] statement does exists. For example, taken from the flex doc: var a:Number, x:Number, y:Number; with (Math) { a = PI * pow(r, 2); x = r * cos(PI); y = r * sin(PI / 2); } where pow, cos and sin are static method of Math. Regards, Edward Yakop On Nov 5, 2007 10:45 AM, Samuel Colak <[EMAIL PROTECTED] > wrote: > Guys, > > am i going nuts and that there is no with construction for objects > (such like) > > object.x = 20 (x is a number) > > or > > WITH (object) { > .x = 20 > } > > Just wondering > > Samuel > > > -- > Flexcoders Mailing List > FAQ: http://groups.yahoo.com/group/flexcoders/files/ flexcodersFAQ.txt > Search Archives: http://www.mail-archive.com/flexcoders% 40yahoogroups.com > Yahoo! Groups Links > > > >
Re: [flexcoders] WITH construction ?
Paul, apologies however languages such as C# include such a directive already - its not "reducing" readability at all - in reality I'm wondering if this is remotely possible in Flex. The issue I'm wondering about is that if you wrote the code below var object:Object = new Object(); With (object) { x = 20; trace("trap the app in debug here"); } and placed a breakpoint on the trace line - you'll note several things - 1) 'x' is defined as a variable of type Number (no var declaration which I didn't think possible) and outside of the scope of 'object' 2) object does not have a variable 'x'. How is it shown that 'x' is part of 'object' rather than an external variable ? In C#, the With statement is enacted in that properties of a object declared in the With construct are referenced in the following manner. With (object) { .x = 20; } Note the '.' ! Thanks & Regards Samuel On Nov 5, 2007, at 4:13 PM, Paul Decoursey wrote: I think that with should be avoided, it greatly reduces the readability of your code and makes maintaining it more difficult. On Nov 5, 2007, at 8:53 AM, Brent Dearth wrote: var o:Object = {a: 20, b: "twenty"}; trace (o.a + " " + o.b); with (o) { a = 40; b = "forty"; } trace (o.a + " " + o.b); On 11/5/07, Samuel Colak <[EMAIL PROTECTED]> wrote: Not quite what i mean - not to call the function but referring to properties inside the object - your demo implies a static object "Math" with functions cos and sin. inside the "object" i have a getter and setter for the property "x". Regards Samuel On Nov 5, 2007, at 10:56 AM, Edward Yakop wrote: I'm not sure what u meant, but [with] statement does exists. For example, taken from the flex doc: var a:Number, x:Number, y:Number; with (Math) { a = PI * pow(r, 2); x = r * cos(PI); y = r * sin(PI / 2); } where pow, cos and sin are static method of Math. Regards, Edward Yakop On Nov 5, 2007 10:45 AM, Samuel Colak <[EMAIL PROTECTED] > wrote: > Guys, > > am i going nuts and that there is no with construction for objects > (such like) > > object.x = 20 (x is a number) > > or > > WITH (object) { > .x = 20 > } > > Just wondering > > Samuel > > > -- > Flexcoders Mailing List > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com > Yahoo! Groups Links > > > >
Re: [flexcoders] WITH construction ?
- Original Message - From: Samuel Colak To: flexcoders@yahoogroups.com Sent: Monday, November 05, 2007 2:32 PM Subject: Re: [flexcoders] WITH construction ? Not quite what i mean - not to call the function but referring to properties inside the object - your demo implies a static object "Math" with functions cos and sin. inside the "object" i have a getter and setter for the property "x". Regards Samuel function test():void { var o:Object = new Object(); o.k = "hello"; trace("k="+o.k); with (o) { trace("k="+k); k="goodbye"; trace("k="+k); } trace("k="+o.k); } Result: k=hello k=hello k=goodbye k=goodbye How hard was that to try out? Paul
Re: [flexcoders] WITH construction ?
I think that with should be avoided, it greatly reduces the readability of your code and makes maintaining it more difficult. On Nov 5, 2007, at 8:53 AM, Brent Dearth wrote: var o:Object = {a: 20, b: "twenty"}; trace (o.a + " " + o.b); with (o) { a = 40; b = "forty"; } trace (o.a + " " + o.b); On 11/5/07, Samuel Colak <[EMAIL PROTECTED]> wrote: Not quite what i mean - not to call the function but referring to properties inside the object - your demo implies a static object "Math" with functions cos and sin. inside the "object" i have a getter and setter for the property "x". Regards Samuel On Nov 5, 2007, at 10:56 AM, Edward Yakop wrote: I'm not sure what u meant, but [with] statement does exists. For example, taken from the flex doc: var a:Number, x:Number, y:Number; with (Math) { a = PI * pow(r, 2); x = r * cos(PI); y = r * sin(PI / 2); } where pow, cos and sin are static method of Math. Regards, Edward Yakop On Nov 5, 2007 10:45 AM, Samuel Colak <[EMAIL PROTECTED] > wrote: > Guys, > > am i going nuts and that there is no with construction for objects > (such like) > > object.x = 20 (x is a number) > > or > > WITH (object) { > .x = 20 > } > > Just wondering > > Samuel > > > -- > Flexcoders Mailing List > FAQ: http://groups.yahoo.com/group/flexcoders/files/ flexcodersFAQ.txt > Search Archives: http://www.mail-archive.com/flexcoders% 40yahoogroups.com > Yahoo! Groups Links > > > >
Re: [flexcoders] WITH construction ?
var o:Object = {a: 20, b: "twenty"}; trace (o.a + " " + o.b); with (o) { a = 40; b = "forty"; } trace (o.a + " " + o.b); On 11/5/07, Samuel Colak <[EMAIL PROTECTED]> wrote: > > Not quite what i mean - not to call the function but referring to > properties inside the object - your demo implies a static object "Math" with > functions cos and sin. > > inside the "object" i have a getter and setter for the property "x". > > Regards > Samuel > > On Nov 5, 2007, at 10:56 AM, Edward Yakop wrote: > > I'm not sure what u meant, but [with] statement does exists. > For example, taken from the flex doc: > > var a:Number, x:Number, y:Number; > > with (Math) { > a = PI * pow(r, 2); > x = r * cos(PI); > y = r * sin(PI / 2); > } > > where pow, cos and sin are static method of Math. > > Regards, > Edward Yakop > > On Nov 5, 2007 10:45 AM, Samuel Colak <[EMAIL > PROTECTED]> > wrote: > > Guys, > > > > am i going nuts and that there is no with construction for objects > > (such like) > > > > object.x = 20 (x is a number) > > > > or > > > > WITH (object) { > > .x = 20 > > } > > > > Just wondering > > > > Samuel > > > > > > -- > > Flexcoders Mailing List > > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > > Search Archives: > http://www.mail-archive.com/flexcoders%40yahoogroups.com > > Yahoo! Groups Links > > > > > > > > > > >
Re: [flexcoders] WITH construction ?
It is the same syntax. Here's the more complete solution that I hope illustrate with to call property. http://www.adobe.com/2006/mxml"; layout="absolute" creationComplete="init()"> Regards, Edward Yakop
Re: [flexcoders] WITH construction ?
Not quite what i mean - not to call the function but referring to properties inside the object - your demo implies a static object "Math" with functions cos and sin. inside the "object" i have a getter and setter for the property "x". Regards Samuel On Nov 5, 2007, at 10:56 AM, Edward Yakop wrote: I'm not sure what u meant, but [with] statement does exists. For example, taken from the flex doc: var a:Number, x:Number, y:Number; with (Math) { a = PI * pow(r, 2); x = r * cos(PI); y = r * sin(PI / 2); } where pow, cos and sin are static method of Math. Regards, Edward Yakop On Nov 5, 2007 10:45 AM, Samuel Colak <[EMAIL PROTECTED]> wrote: > Guys, > > am i going nuts and that there is no with construction for objects > (such like) > > object.x = 20 (x is a number) > > or > > WITH (object) { > .x = 20 > } > > Just wondering > > Samuel > > > -- > Flexcoders Mailing List > FAQ: http://groups.yahoo.com/group/flexcoders/files/ flexcodersFAQ.txt > Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com > Yahoo! Groups Links > > > >
Re: [flexcoders] WITH construction ?
I'm not sure what u meant, but [with] statement does exists. For example, taken from the flex doc: var a:Number, x:Number, y:Number; with (Math) { a = PI * pow(r, 2); x = r * cos(PI); y = r * sin(PI / 2); } where pow, cos and sin are static method of Math. Regards, Edward Yakop On Nov 5, 2007 10:45 AM, Samuel Colak <[EMAIL PROTECTED]> wrote: > Guys, > > am i going nuts and that there is no with construction for objects > (such like) > > object.x = 20 (x is a number) > > or > > WITH (object) { > .x = 20 > } > > Just wondering > > Samuel > > > -- > Flexcoders Mailing List > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com > Yahoo! Groups Links > > > >
[flexcoders] WITH construction ?
Guys, am i going nuts and that there is no with construction for objects (such like) object.x = 20 (x is a number) or WITH (object) { .x = 20 } Just wondering Samuel