Re: [Flashcoders] Wherefore the evils of _global?
I suppose it's the use of variables in _global. That's what I avoid. Else, 5 years later, when you've got extensive classes, and something ddoesn't work, it might be because some variables overwrite one another in _global. That'd take almost forever to debug. On 3/24/06, David Stiller [EMAIL PROTECTED] wrote: In the last few days, I've seen a handful of people refer apologetically to use of the _global object. To paraphrase: I'm in a situation where I have to use _global variables, or, We all know _global is a no-no, but I'm tempted to use it in this one weird case, etc. In general, this gives me the impression that it's fashionable here to think of _global as Evil -- or in the very least, yucky. I understand why _root can be troublesome, especially in conjunction with dynamically loaded SWFs, but I do use it in a pinch. I mean, heck, sometimes a movie is just a movie, not a portable app. What I don't understand -- and I hasten to say I have no opinion on the matter, yet -- is why _global is so shunned. After all, _global is exactly where AS2 classes are located. Is this a religious issue? Is it because of how _global gets shared (or not?) among dynamically loaded SWFs? David [EMAIL PROTECTED] ___ 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 -- Ramon Miguel M. Tayag Managing Director Quirkworks ___ 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] Wherefore the evils of _global?
yeah its yuck, though i use it myself here and there for the cheap hack that it can be. i think generally most programming languages (or the prgrammers using those languages) look down upon global vars. i think the idea is that it pretty much destroys encapsulation and object-oriented principles. On 3/23/06, David Stiller [EMAIL PROTECTED] wrote: In the last few days, I've seen a handful of people refer apologetically to use of the _global object. To paraphrase: I'm in a situation where I have to use _global variables, or, We all know _global is a no-no, but I'm tempted to use it in this one weird case, etc. In general, this gives me the impression that it's fashionable here to think of _global as Evil -- or in the very least, yucky. I understand why _root can be troublesome, especially in conjunction with dynamically loaded SWFs, but I do use it in a pinch. I mean, heck, sometimes a movie is just a movie, not a portable app. What I don't understand -- and I hasten to say I have no opinion on the matter, yet -- is why _global is so shunned. After all, _global is exactly where AS2 classes are located. Is this a religious issue? Is it because of how _global gets shared (or not?) among dynamically loaded SWFs? David [EMAIL PROTECTED] ___ 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] Wherefore the evils of _global?
Which is why you make a global namespace. _global.APP = {}; And then you set your global vars to that APP.myglobalvar = foo; -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Rich Rodecker Sent: Thursday, March 23, 2006 2:25 PM To: Flashcoders mailing list Subject: Re: [Flashcoders] Wherefore the evils of _global? yeah its yuck, though i use it myself here and there for the cheap hack that it can be. i think generally most programming languages (or the prgrammers using those languages) look down upon global vars. i think the idea is that it pretty much destroys encapsulation and object-oriented principles. On 3/23/06, David Stiller [EMAIL PROTECTED] wrote: In the last few days, I've seen a handful of people refer apologetically to use of the _global object. To paraphrase: I'm in a situation where I have to use _global variables, or, We all know _global is a no-no, but I'm tempted to use it in this one weird case, etc. In general, this gives me the impression that it's fashionable here to think of _global as Evil -- or in the very least, yucky. I understand why _root can be troublesome, especially in conjunction with dynamically loaded SWFs, but I do use it in a pinch. I mean, heck, sometimes a movie is just a movie, not a portable app. What I don't understand -- and I hasten to say I have no opinion on the matter, yet -- is why _global is so shunned. After all, _global is exactly where AS2 classes are located. Is this a religious issue? Is it because of how _global gets shared (or not?) among dynamically loaded SWFs? David [EMAIL PROTECTED] ___ 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] Wherefore the evils of _global?
What I don't understand -- and I hasten to say I have no opinion on the matter, yet -- is why _global is so shunned. After all, _global is exactly where AS2 classes are located. Is this a religious issue? Is it because of how _global gets shared (or not?) among dynamically loaded SWFs? Because global variables are contrary to the basis of OOP, which is all about abstraction and encapsulation. If you need to store variables somewhere so that they can be reached anywhere, use a singleton, or a static class, or an application object, and so on. ryanm ___ 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] Wherefore the evils of _global?
On 3/23/06, ryanm [EMAIL PROTECTED] wrote: Because global variables are contrary to the basis of OOP, which is all about abstraction and encapsulation. If you need to store variables somewhere so that they can be reached anywhere, use a singleton, or a static class, or an application object, and so on. Uh, a singleton can be just a round-about method of the global namespace, but is exactly the same thing (or at least the way I've seen it used with a __resolve). _global is a perfect place to store application meta data, the stuff you might load from an XML file. Such as urls, configurations, etc. However, I do agree that if you're building anything of significance (in size) you should have a class (as you mentioned classes are global) that can act as a singleton or a static; but the trick is it has each property it will hold defined in it. This way every thing thrown the way of global vars is documented, type checked, and follows some sort of API. This is easy to track and debug. That is the hard thing about straight global, finding where in the world the thing got set or changed when it's being messed up. Tyler ___ 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] Wherefore the evils of _global?
Responding to two, here ... ryanm wrote: Because global variables are contrary to the basis of OOP, which is all about abstraction and encapsulation. If you need to store variables somewhere so that they can be reached anywhere, use a singleton, or a static class, or an application object, and so on. Okay, I'm with you. That jibes with my understanding of OOP in a universal sense. In ActionScript, however, classes *are* properties of the _global object, which is what prompted my question. Programmers in general may agree to avoid global variables in principle, and what I'm hearing is that ActionScript programmers, in a sense, pretend _global isn't being used unless invoked explicitly. Caveat: By pretend, I don't mean AS programmers are fibbers ... it's more like we agree to an anticipatory linguistic contrivance while gearing up for AS3. Right? Same as we speak of strong typing in AS2: technically speaking, AS2 is not strongly typed. Post-colon syntax, at least currently, is a device for accommodating compile-time error messages and code hinting. Tyler Wright wrote: _global is a perfect place to store application meta data [...] if you're building anything of significance (in size) you should have a class [...] This way every thing thrown the way of global vars is documented, type checked, and follows some sort of API. That makes perfect sense. David [EMAIL PROTECTED] ___ 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] Wherefore the evils of _global?
Okay, I'm with you. That jibes with my understanding of OOP in a universal sense. In ActionScript, however, classes *are* properties of the _global object, which is what prompted my question. Programmers in general may agree to avoid global variables in principle, and what I'm hearing is that ActionScript programmers, in a sense, pretend _global isn't being used unless invoked explicitly. Essentially, yes. The fact that classes are stored in _global is kind of like the red-headed bastard child we don't talk about. ;-) Macromedia used an ugly kluge to make it look kind of like a real namespace, so we look the other way and pretend it's not there until they fix it. Just because that's how they did it doesn't make it right, and it doesn't mean it should be part of good AS coding practices. Global space has its place and can be very useful. But it can also be a debugging nightmare, and as such it is best to avoid it except in very simple cases. With an application object you can use getters and setters to track changes and raise events when things change, that way you know who set that global property and why, you can do validation on the values being set, etc. It's not an absolute no-no to use _global, but if you can save yourself some headaches in integration and debugging by going slightly out of your way not to use it, it's time well spent. In my opinion, of course... ryanm ___ 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