Re: [Flashcoders] Coding Standards: Use of Get/Set
That's exactly why I prefer using them. Implicit getter/settters allow you do define a property (variable) of a class and do something when the property changes. So you get to keep the clear distinction between a property and a method of a class (from a user perspective). regards, Muzak - Original Message - From: Matthias Dittgen [EMAIL PROTECTED] To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com Sent: Wednesday, February 14, 2007 8:54 AM Subject: Re: [Flashcoders] Coding Standards: Use of Get/Set You always compare implicit getter/settter with explicit getter/setter. Just a thought of mine is to compare implicit getter/setter with public variables. When you use someClass, that was written by someone else, you do not know if the following code uses implicit getter/setter or is just a public variable: someClassInstance._fancy = 10 If it is an implicit getter/setter, it can do for example some kind of event handling, like like calling onFancy() or broadcast(onFancy) everytime you set the _fancy property. So implicit getter/setter are hiding such things effectivly from the user of you classes. Matthias ___ 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] Coding Standards: Use of Get/Set
I was wondering what people's thoughts were on the use of get and set functions. I personally have felt that creating functions such as: public function get theLetterA(){ return a; } so the user can simply call someObject.theLetterA are confusing because the user doesn't know if they are doing a function call or accessing a public variable. I prefer writing functions such as: public function getTheLetterA(){ return a; } So the user needs to explicitly call the function someObject.getTheLetterA(). Are there advantages to using get and set that I'm not seeing? I ask because I was always use getVariable() functions and started reading ActionScript 3 with Design Patterns and the authors (as well as many others I've read) are using get and set functions. Daniel Holth I.S. Programmer This e-mail and its attachments are intended only for the use of the addressee(s) and may contain privileged, confidential or proprietary information. If you are not the intended recipient, or the employee or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution, displaying, copying, or use of this information is strictly prohibited. If you have received this communication in error, please inform the sender immediately and delete and destroy any record of this message. Thank you. ___ 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
RE: [Flashcoders] Coding Standards: Use of Get/Set
Just to fuel your query, how does it affect the user to know whether they are 'get'-ing from a variable or a function call, encapsulation considered? P. -Original Message- From: [EMAIL PROTECTED] [mailto:flashcoders- [EMAIL PROTECTED] On Behalf Of Holth, Daniel C. Sent: Tuesday, February 13, 2007 3:32 PM To: Flashcoders@chattyfig.figleaf.com Subject: [Flashcoders] Coding Standards: Use of Get/Set I was wondering what people's thoughts were on the use of get and set functions. I personally have felt that creating functions such as: public function get theLetterA(){ return a; } so the user can simply call someObject.theLetterA are confusing because the user doesn't know if they are doing a function call or accessing a public variable. I prefer writing functions such as: public function getTheLetterA(){ return a; } So the user needs to explicitly call the function someObject.getTheLetterA(). Are there advantages to using get and set that I'm not seeing? I ask because I was always use getVariable() functions and started reading ActionScript 3 with Design Patterns and the authors (as well as many others I've read) are using get and set functions. Daniel Holth I.S. Programmer This e-mail and its attachments are intended only for the use of the addressee(s) and may contain privileged, confidential or proprietary information. If you are not the intended recipient, or the employee or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution, displaying, copying, or use of this information is strictly prohibited. If you have received this communication in error, please inform the sender immediately and delete and destroy any record of this message. Thank you. ___ 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
Re: [Flashcoders] Coding Standards: Use of Get/Set
The biggest complaint that I have seen is the issue of speed. If you do var foo: String = obj.theLetterA you expect that to be a hash lookup/dereference/something fast. If you do var foo: String = obj.getSomething() and you are thinking about speed, you go and look at what getSomething() is doing. This makes sense to me, while the other arguments I've heard against get/set make no sense to me. For the record though I've never used get/set functions because I don't see the point in making the syntax stranger compared to the other languages I've used which either don't have or didn't provide me a good reason to use get/set. Can someone tell me any benefit at all? Daniel Pete Miller wrote: Just to fuel your query, how does it affect the user to know whether they are 'get'-ing from a variable or a function call, encapsulation considered? P. -Original Message- From: [EMAIL PROTECTED] [mailto:flashcoders- [EMAIL PROTECTED] On Behalf Of Holth, Daniel C. Sent: Tuesday, February 13, 2007 3:32 PM To: Flashcoders@chattyfig.figleaf.com Subject: [Flashcoders] Coding Standards: Use of Get/Set I was wondering what people's thoughts were on the use of get and set functions. I personally have felt that creating functions such as: public function get theLetterA(){ return a; } so the user can simply call someObject.theLetterA are confusing because the user doesn't know if they are doing a function call or accessing a public variable. I prefer writing functions such as: public function getTheLetterA(){ return a; } So the user needs to explicitly call the function someObject.getTheLetterA(). Are there advantages to using get and set that I'm not seeing? I ask because I was always use getVariable() functions and started reading ActionScript 3 with Design Patterns and the authors (as well as many others I've read) are using get and set functions. Daniel Holth I.S. Programmer This e-mail and its attachments are intended only for the use of the addressee(s) and may contain privileged, confidential or proprietary information. If you are not the intended recipient, or the employee or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution, displaying, copying, or use of this information is strictly prohibited. If you have received this communication in error, please inform the sender immediately and delete and destroy any record of this message. Thank you. ___ 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 ___ 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
Re: [Flashcoders] Coding Standards: Use of Get/Set
On 2/13/07, Holth, Daniel C. [EMAIL PROTECTED] wrote: I was wondering what people's thoughts were on the use of get and set functions. I personally have felt that creating functions such as: public function get theLetterA(){ return a; } so the user can simply call someObject.theLetterA are confusing because the user doesn't know if they are doing a function call or accessing a public variable. I prefer writing functions such as: That's the point, though. They don't actually need to know. If you're using someone else's class, you don't need to know how it's implemented; you just need to know the interface. Are there advantages to using get and set that I'm not seeing? You can implement as either a public variable (faster, simpler) or as getter/setter functions (more options, more security) without changing the class' interface. I ask because I was always use getVariable() functions and started reading ActionScript 3 with Design Patterns and the authors (as well as many others I've read) are using get and set functions. AFAIK, getVariable() is a holdover from Java, which doesn't have properties. As a final benefit, using properties makes code much more readable. Compare: obj.property += value; obj.setProperty(obj.getProperty() + value); The only time I ever use getX as a function name is if I need to pass one or more arguments (which you can't do with getters) For example: public function getItemAt(index:Number):Item { return _items[index]; } -- Mike Keesey ___ 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
RE: [Flashcoders] Coding Standards: Use of Get/Set
Get/set is useful when creating a visual object class, as well as for setting private variables on set. It's also useful when you don't want the variable that is being set to be getted, as well. For instance, I have an application which allows a user to type in the day, month and year into three different fields. This data is applied to the model via setters: public function set month(n:Number):Void { _month = --n; var d:Date = new Date(_msDate); d.setMonth(n); _msDate = d.getTime(); } public function set day(n:Number):Void { _day = n; var d:Date = new Date(_msDate); d.setDate(n); _msDate = d.getTime(); } public function set year(n:Number):Void { _year = n; if (String(_year).length == 1) { _year = Number(200 + n); } else if (String(_year).length == 2) { _year = Number(20 + n); } var d:Date = new Date(_msDate); d.setFullYear(_year); _msDate = d.getTime(); } This allows me to set the month to a valid flash month (month - 1), and update _msDate, which is the date in milliseconds, for sorting by dates very easily. I use setters and getters because it makes autocompletion and code hints a breeze. It also is great for visual object model classes. If you choose to write getVariable vs get variable, it's up to you. I use them in different ways at different times. ___ 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
Re: [Flashcoders] Coding Standards: Use of Get/Set
Just thought of another use for properties: component parameters. With properties you can do something like this: [Inspectable] public function get percent():Number { return _percent; } public function set percent(value:Number):Void { _percent = normalizePercentage(value); } private var _percent:Number = 0; private static function normalizePercentage(value:Number):Number { if (!isFinite(value)) { return 0; } if (value 100) { return 100; } return Math.floor(value); } //... This code will create a property called percent which can be set by a component parameter and will never evaluate to anything but an integer from 0 to 100. If you were using getPercent() and setPercent(), you couldn't have the inspectable component parameter. -- T. Michael Keesey Director of Technology Exopolis, Inc. 2894 Rowena Avenue Ste. B Los Angeles, California 90039 ___ 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
Re: [Flashcoders] Coding Standards: Use of Get/Set
I use implicit getter/setters all the time when it involves a single property of an object: width, height, visible, etc.. I use explicit getter/setters when one or more parameters are required: getItemAt(index), setSize(w, h) Implict getter/setters are also invoked before the constructor, which can come in handy if you want to set values using attachMovie's initObject. This will invoke the implicit width and height methods immediatly. this.attachMovie(Ball, ball_mc, this.getNextHighestDepth(), {width:100, height:100}); There have been some interesting discussions about getter/setters here in the past that you can find in the archives. Most of those go back to the AS1 days when we still had to use Object.addProperty() (which AS2 still results to behind the scenes). http://muzakdeezign.com/flashcoders/?q=getter%20setter http://muzakdeezign.com/flashcoders/?q=implicit%20getter%20setter regards, Muzak - Original Message - From: Holth, Daniel C. [EMAIL PROTECTED] To: Flashcoders@chattyfig.figleaf.com Sent: Tuesday, February 13, 2007 9:31 PM Subject: [Flashcoders] Coding Standards: Use of Get/Set I was wondering what people's thoughts were on the use of get and set functions. I personally have felt that creating functions such as: public function get theLetterA(){ return a; } so the user can simply call someObject.theLetterA are confusing because the user doesn't know if they are doing a function call or accessing a public variable. I prefer writing functions such as: public function getTheLetterA(){ return a; } So the user needs to explicitly call the function someObject.getTheLetterA(). Are there advantages to using get and set that I'm not seeing? I ask because I was always use getVariable() functions and started reading ActionScript 3 with Design Patterns and the authors (as well as many others I've read) are using get and set functions. Daniel Holth I.S. Programmer ___ 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
Re: [Flashcoders] Coding Standards: Use of Get/Set
One of the few reasons to use explicit getters/setters in AS2 is as part of an interface. AS2 does not allow implicit property getters and setters in interfaces. // Will not work in AS2: interface Ratio { function get percent():Number; } // Will work in AS2: interface Ratio { function getPercent():Number; } Fortunately, AS3 has remedied this problem. -- Mike Keesey ___ 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
Re: [Flashcoders] Coding Standards: Use of Get/Set
You always compare implicit getter/settter with explicit getter/setter. Just a thought of mine is to compare implicit getter/setter with public variables. When you use someClass, that was written by someone else, you do not know if the following code uses implicit getter/setter or is just a public variable: someClassInstance._fancy = 10 If it is an implicit getter/setter, it can do for example some kind of event handling, like like calling onFancy() or broadcast(onFancy) everytime you set the _fancy property. So implicit getter/setter are hiding such things effectivly from the user of you classes. Matthias 2007/2/14, T. Michael Keesey [EMAIL PROTECTED]: One of the few reasons to use explicit getters/setters in AS2 is as part of an interface. AS2 does not allow implicit property getters and setters in interfaces. // Will not work in AS2: interface Ratio { function get percent():Number; } // Will work in AS2: interface Ratio { function getPercent():Number; } Fortunately, AS3 has remedied this problem. -- Mike Keesey ___ 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