Re: [Flashcoders] Singleton as associative array - yucky icky?
What's wrong with the Items-property and then do a Session.Items[ sessionKeyName ]; ? This is also available for the ASP.NET guys. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Singleton as associative array - yucky icky?
nothing wrong with it - and would be the nice way to do it. and probably will be how it ends up... but all of the vb developers i know use the shortcuts where ever possible... Session(key) instead of Session.Items(key), Recordset(field) instead of Recordset.Fields(field), etc. i'm just trying to cater to their habits of using the shortcuts instead of forcing properness on them. :-) g. On 12/30/05, Weyert de Boer [EMAIL PROTECTED] wrote: What's wrong with the Items-property and then do a Session.Items[ sessionKeyName ]; ? This is also available for the ASP.NET guys. -- weblog: broadcast.artificialcolors.com blazePDF: www.blazepdf.com band: www.cutratebox.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Singleton as associative array - yucky icky?
I would say to hell with the VB coders (and I used to be one). What if you want to change your implementation later on? What if this functionality changes with AS3? Without an API, you open yourself up to all sorts of fun stuff that may force the user to have to change their code later on. Be nice to yourself and to your users. You'll be happier in the end, and your guilt will be assuaged (rightly so)! And when was the last time that VB/VBScript catered to anyone in the Java, JavaScript, or ActionScript world? They use completely different syntax, so don't fret about it. Nathan http://www.nathanderksen.com On Dec 29, 2005, at 10:05 PM, g.wygonik wrote: whew! thought i might have missed clever and cool in there! :-) though your comment did bring up some ideas i'll try in the AM. it's all whack in my book right now. like i told Jesse - it works, i'll keep it. time for bed! g. On 12/29/05, Claus Wahlers [EMAIL PROTECTED] wrote: __resolve? nope... not unless there's some super-secret way of using __resolve outside of the normal way. even with a __resolve function in-place in my class, you still get the dreaded Left side of assignment operator must be variable or property. when calling: session(foo) = bar; ah yes of course: non-singleton-version: var session:Session = new Session(); session(foo) = bar; this makes no sense. maybe: session.foo = bar; in combination with __resolve? or maybe even let getInstance return a method of the singleton rather than the instance itself? hmm no then the :Session type would be invalid.. i guess the only way to do that is using the standard dot-notation and __resolve. sorry can't test as2 stuff right now, but maybe it helps somehow ;) cheers, claus. -- weblog: broadcast.artificialcolors.com blazePDF: www.blazepdf.com band: www.cutratebox.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Singleton as associative array - yucky icky?
Well, consider how an object can be manipulated. var myObject:Object = new Object(); myObject.foo = bar; or var myObject:Object = new Object(); myObject[foo] = bar; Those are equivalent syntaxes. Everything basically inherits from Object, so this is valid syntax throughout, including your custom classes. Basically, you are accessing (and apparently creating) properties on the fly, with no type checking, and no compiler validation as to whether the property being accessed actually exists. You can see a bit more of this if you consider the XML class: var myXML:XML = new XML(); myXML.foo = bar; In this case, foo is not a valid property of the XML class, so the compiler spits out an error. However, if you do this: var myXML:XML = new XML(); myXML[foo] = bar; the compiler happily allows it, and a trace on myXML.foo reveals the value bar. One more thing, the LoadVars class takes advantage of the fact that the class is just a collection of properties. It allows for the arbitrary addition of properties using both syntaxes: var myLV:LoadVars = new LoadVars(); myLV.foo = bar; myLV[baz] -= quux; myLV.sendAndLoad(foo.jsp); In many respects, LoadVars is doing what you want to do with your Session class. Fun, eh! Regarding number 2, that is what getters and setters are normally for. With arbitrary properties, someone correct me if I am wrong, but I don't think there is a way of intercepting them all, just specific ones that you have defined. Nathan http://www.nathanderksen.com On Dec 30, 2005, at 9:55 AM, g.wygonik wrote: lol - indeed. :-) i'm just trying to look at possible issues that may come up later on... but this scenario brings up two follow-up questions/concerns: 1 - the fact that Flash (AS2) will happily turn a class into an associative array without any sort of warning. if a coder comes in and uses session[foo], it will work with no errors thrown. can i catch this somehow? should they use this syntax throughout their modules, it will work with no problems, but won't be correct. 2 - can i somehow catch items being added to the class via the ass-array method and properly add them to the Items array instead of the root class? in other words, say a user does use the session[foo] method. can i intercept that call, add the item/value to the Items array and remove it from the class? i thought about some sort of watch, but i wouldn't know what to watch in this case... while i'm going to be setting up a proper API for them to use, in a way this conversation is over from a real world standpoint. but i'd like to figure this out from a theoretical standpoint now. g. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Singleton as associative array - yucky icky?
Correct. __resolve can catch arbitrary function calls, but not arbritary variable assignments. - Original Message - From: Nathan Derksen [EMAIL PROTECTED] To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com Sent: Friday, December 30, 2005 1:20 PM Subject: Re: [Flashcoders] Singleton as associative array - yucky icky? Well, consider how an object can be manipulated. var myObject:Object = new Object(); myObject.foo = bar; or var myObject:Object = new Object(); myObject[foo] = bar; Those are equivalent syntaxes. Everything basically inherits from Object, so this is valid syntax throughout, including your custom classes. Basically, you are accessing (and apparently creating) properties on the fly, with no type checking, and no compiler validation as to whether the property being accessed actually exists. You can see a bit more of this if you consider the XML class: var myXML:XML = new XML(); myXML.foo = bar; In this case, foo is not a valid property of the XML class, so the compiler spits out an error. However, if you do this: var myXML:XML = new XML(); myXML[foo] = bar; the compiler happily allows it, and a trace on myXML.foo reveals the value bar. One more thing, the LoadVars class takes advantage of the fact that the class is just a collection of properties. It allows for the arbitrary addition of properties using both syntaxes: var myLV:LoadVars = new LoadVars(); myLV.foo = bar; myLV[baz] -= quux; myLV.sendAndLoad(foo.jsp); In many respects, LoadVars is doing what you want to do with your Session class. Fun, eh! Regarding number 2, that is what getters and setters are normally for. With arbitrary properties, someone correct me if I am wrong, but I don't think there is a way of intercepting them all, just specific ones that you have defined. Nathan http://www.nathanderksen.com On Dec 30, 2005, at 9:55 AM, g.wygonik wrote: lol - indeed. :-) i'm just trying to look at possible issues that may come up later on... but this scenario brings up two follow-up questions/concerns: 1 - the fact that Flash (AS2) will happily turn a class into an associative array without any sort of warning. if a coder comes in and uses session[foo], it will work with no errors thrown. can i catch this somehow? should they use this syntax throughout their modules, it will work with no problems, but won't be correct. 2 - can i somehow catch items being added to the class via the ass-array method and properly add them to the Items array instead of the root class? in other words, say a user does use the session[foo] method. can i intercept that call, add the item/value to the Items array and remove it from the class? i thought about some sort of watch, but i wouldn't know what to watch in this case... while i'm going to be setting up a proper API for them to use, in a way this conversation is over from a real world standpoint. but i'd like to figure this out from a theoretical standpoint now. g. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Singleton as associative array - yucky icky?
On 12/30/05, Nathan Derksen [EMAIL PROTECTED] wrote: Those are equivalent syntaxes. Everything basically inherits from Object, so this is valid syntax throughout, including your custom classes. Basically, you are accessing (and apparently creating) properties on the fly, with no type checking, and no compiler validation as to whether the property being accessed actually exists. while that is true, i thought that was what the dynamic keyword was to allow, and without it, you'd get some sort of error... In many respects, LoadVars is doing what you want to do with your Session class. well, in ways, yes - in ways, no. it's doing the same on-the-fly variable assignment, but doesn't have any other methods (like addItem) that would put keys/values into a specific class member. it seems that LoadVars just iterates over the object and outputs any property it finds (which is why onLoad=function used to appear in LoadVars data). i was doing iterations over both the class object and the Items member. i'd obviously prefer just to have one place for all props. Regarding number 2, that is what getters and setters are normally for. With arbitrary properties, someone correct me if I am wrong, but I don't think there is a way of intercepting them all, just specific ones that you have defined. indeed there's none that i know of... but i've seen some folks do some strange things with Flash here ;-) as Jesse pointed out, __resolve won't work with variable assignments - so AFAIK, there's no nice way to handle this. g. -- weblog: broadcast.artificialcolors.com blazePDF: www.blazepdf.com band: www.cutratebox.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Singleton as associative array - yucky icky?
On 12/30/05, Nathan Derksen [EMAIL PROTECTED] wrote: while that is true, i thought that was what the dynamic keyword was to allow, and without it, you'd get some sort of error... That's the theory, but as the XML example shows, using the associative array syntax gets around the compile-time checking for that. In many respects, LoadVars is doing what you want to do with your Session class. well, in ways, yes - in ways, no. it's doing the same on-the-fly variable assignment, but doesn't have any other methods (like addItem) that would put keys/values into a specific class member. it seems that LoadVars just iterates over the object and outputs any property it finds (which is why onLoad=function used to appear in LoadVars data). i was doing iterations over both the class object and the Items member. i'd obviously prefer just to have one place for all props. Yah, that's why it is so much cleaner just to have an associative array as a private property within your class, and create addItem(), getItem(), and removeItem() methods to manage that associative array. That way you also don't have to worry about the names of added properties possibly colliding with existing property/method names within the class. Nathan http://www.nathanderksen.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Singleton as associative array - yucky icky?
Flash won't bitch when you do this: my_xml[owner] Flex 1 1.5 will give you a warning. Flex 2 bitches if owner isn't public. - Original Message - From: Nathan Derksen [EMAIL PROTECTED] To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com Sent: Friday, December 30, 2005 2:24 PM Subject: Re: [Flashcoders] Singleton as associative array - yucky icky? On 12/30/05, Nathan Derksen [EMAIL PROTECTED] wrote: while that is true, i thought that was what the dynamic keyword was to allow, and without it, you'd get some sort of error... That's the theory, but as the XML example shows, using the associative array syntax gets around the compile-time checking for that. In many respects, LoadVars is doing what you want to do with your Session class. well, in ways, yes - in ways, no. it's doing the same on-the-fly variable assignment, but doesn't have any other methods (like addItem) that would put keys/values into a specific class member. it seems that LoadVars just iterates over the object and outputs any property it finds (which is why onLoad=function used to appear in LoadVars data). i was doing iterations over both the class object and the Items member. i'd obviously prefer just to have one place for all props. Yah, that's why it is so much cleaner just to have an associative array as a private property within your class, and create addItem(), getItem(), and removeItem() methods to manage that associative array. That way you also don't have to worry about the names of added properties possibly colliding with existing property/method names within the class. Nathan http://www.nathanderksen.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Singleton as associative array - yucky icky?
I forget what MTASC does I think it throws a warning too. - Original Message - From: JesterXL [EMAIL PROTECTED] To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com Sent: Friday, December 30, 2005 2:34 PM Subject: Re: [Flashcoders] Singleton as associative array - yucky icky? Flash won't bitch when you do this: my_xml[owner] Flex 1 1.5 will give you a warning. Flex 2 bitches if owner isn't public. - Original Message - From: Nathan Derksen [EMAIL PROTECTED] To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com Sent: Friday, December 30, 2005 2:24 PM Subject: Re: [Flashcoders] Singleton as associative array - yucky icky? On 12/30/05, Nathan Derksen [EMAIL PROTECTED] wrote: while that is true, i thought that was what the dynamic keyword was to allow, and without it, you'd get some sort of error... That's the theory, but as the XML example shows, using the associative array syntax gets around the compile-time checking for that. In many respects, LoadVars is doing what you want to do with your Session class. well, in ways, yes - in ways, no. it's doing the same on-the-fly variable assignment, but doesn't have any other methods (like addItem) that would put keys/values into a specific class member. it seems that LoadVars just iterates over the object and outputs any property it finds (which is why onLoad=function used to appear in LoadVars data). i was doing iterations over both the class object and the Items member. i'd obviously prefer just to have one place for all props. Yah, that's why it is so much cleaner just to have an associative array as a private property within your class, and create addItem(), getItem(), and removeItem() methods to manage that associative array. That way you also don't have to worry about the names of added properties possibly colliding with existing property/method names within the class. Nathan http://www.nathanderksen.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Singleton as associative array - yucky icky?
On 12/30/05, Nathan Derksen [EMAIL PROTECTED] wrote: Yah, that's why it is so much cleaner just to have an associative array as a private property within your class, and create addItem(), getItem(), and removeItem() methods to manage that associative array. That way you also don't have to worry about the names of added properties possibly colliding with existing property/method names within the class. most definitely - and is the way i'm working it. just sucks that i can't catch a mistake that _might_ be made because of the associative array call. g. -- weblog: broadcast.artificialcolors.com blazePDF: www.blazepdf.com band: www.cutratebox.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Singleton as associative array - yucky icky?
Can you post how they do it in VB? - Original Message - From: g.wygonik [EMAIL PROTECTED] To: flashcoders flashcoders@chattyfig.figleaf.com Sent: Thursday, December 29, 2005 11:33 PM Subject: [Flashcoders] Singleton as associative array - yucky icky? hey all so - i've got a Singleton class (Session) that is storing user info. i've got all my addItem and getItem methods going and all is normal and fine. however, in an effort to be more familiar to ASP/VBScript developers who will be using these classes in the future, i'd like to make a way to do something like: var session:Session = Session.getInstance(); session(foo) = bar; which would set the item foo equal to bar. i can't see that there's a way to do this kind of non-method calling of the class instance. however, i CAN do: session[foo] = bar; and Flash happily (frighteningly?) starts using my class instance as an associative array. i can even update my getItem function to check both the instance object array and the associative array and return the appropriate value. works like a charm. but it seems _terribly wrong_. i thought about a static variable of my main controller class, but don't know if it will function the same - scope and access-wise. it's late and i may be missing something simple, but... thoughts? ideas? harsh criticism? is this okay? is there a better way to handle this (short of just saying this is the API. deal with it!)? thanks g. ps - if anyone reading this cares, i released version 2 of my AFTERTHOUGHT real-time Flash log reading app yesterday. check the blog link below for more info. -- weblog: broadcast.artificialcolors.com blazePDF: www.blazepdf.com band: www.cutratebox.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Singleton as associative array - yucky icky?
sure (note the ASP/VBscript part of my email - not VB ;-) Session(foo) = bar ' store the value Response.Write(Session(foo)) ' write the value :-) g. On 12/29/05, JesterXL [EMAIL PROTECTED] wrote: Can you post how they do it in VB? -- weblog: broadcast.artificialcolors.com blazePDF: www.blazepdf.com band: www.cutratebox.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Singleton as associative array - yucky icky?
var session:Session = Session.getInstance(); session(foo) = bar; which would set the item foo equal to bar. i can't see that there's a way to do this kind of non-method calling of the class instance. __resolve? cheers, claus. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Singleton as associative array - yucky icky?
...dude, in all fairness, it's 12:41 in the morning, but to me, that looks exactly like a static variable... like you had before. Session(foo) = bar ' store the value Same as: Session[foo] = bar ...I'd stick with the static bro if your goal is to satisfy the dot-netterz. - Original Message - From: g.wygonik [EMAIL PROTECTED] To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com Sent: Thursday, December 29, 2005 11:55 PM Subject: Re: [Flashcoders] Singleton as associative array - yucky icky? sure (note the ASP/VBscript part of my email - not VB ;-) Session(foo) = bar ' store the value Response.Write(Session(foo)) ' write the value :-) g. On 12/29/05, JesterXL [EMAIL PROTECTED] wrote: Can you post how they do it in VB? -- weblog: broadcast.artificialcolors.com blazePDF: www.blazepdf.com band: www.cutratebox.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Singleton as associative array - yucky icky?
lol - we'll... EXACTLY!!! it's late - it looks okay - it works... but it just seems wrong to hijack a class instance into an associative array without any warning. eh - maybe i'll just let it go and hope nobody notices ;-) g. On 12/29/05, JesterXL [EMAIL PROTECTED] wrote: ...dude, in all fairness, it's 12:41 in the morning, but to me, that looks exactly like a static variable... like you had before. Session(foo) = bar ' store the value Same as: Session[foo] = bar ...I'd stick with the static bro if your goal is to satisfy the dot-netterz. -- weblog: broadcast.artificialcolors.com blazePDF: www.blazepdf.com band: www.cutratebox.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Singleton as associative array - yucky icky?
uhm, thanks? maybe, perhaps, some Chamomile tea is in order? ;-) i'll go with what i got. i wouldn't have posted except it just rubs me the wrong way to do this. i feel dirty on the inside... eh g. On 12/29/05, JesterXL [EMAIL PROTECTED] wrote: Wrong? Dude, wtf? Why don't you drink some coffee and take a look at what the hell VB is doing (ASP, whatever). It's calling a constructor, passing in a value.. and that value turns into an associative array.. but... the assignment is backwards, and you assign the return value of the constructor instance (that wasn't created because you didn't use new) to an associate array that acts like a getter setter? Oh... ok... lemme just uh... go do a line of coke, and that makes perfect sense! I can see why you are posting about this on Flashcoders so late at night about brackets vs. parens. If the above makes sense to VB guyz, then hell yeah, do whatever you can to make it easier for them to transition to clarity of code. :: puts gun to head :: -- weblog: broadcast.artificialcolors.com blazePDF: www.blazepdf.com band: www.cutratebox.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Singleton as associative array - yucky icky?
Wrong? Dude, wtf? Why don't you drink some coffee and take a look at what the hell VB is doing (ASP, whatever). roffle. it's 4am and i might have smoked some funny cigarettes already. anyways, at least it feels wrong. but then.. vbscript.. ehrm.. ok.. *ducking* cheers, claus. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Singleton as associative array - yucky icky?
VBScript?! LOLLOL - Original Message - From: Claus Wahlers [EMAIL PROTECTED] To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com Sent: Friday, December 30, 2005 1:06 AM Subject: Re: [Flashcoders] Singleton as associative array - yucky icky? Wrong? Dude, wtf? Why don't you drink some coffee and take a look at what the hell VB is doing (ASP, whatever). roffle. it's 4am and i might have smoked some funny cigarettes already. anyways, at least it feels wrong. but then.. vbscript.. ehrm.. ok.. *ducking* cheers, claus. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Singleton as associative array - yucky icky?
If it makes you feel any better, that shiz doesn't work in AS3! So uh... AS2 was like designed to have both dyanic variants AND strict-typing... all in the same language. So, don't feel dirty, feel appropriate. ... and be ready to teach VB guys AS3. - Original Message - From: g.wygonik [EMAIL PROTECTED] To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com Sent: Friday, December 30, 2005 1:03 AM Subject: Re: [Flashcoders] Singleton as associative array - yucky icky? uhm, thanks? maybe, perhaps, some Chamomile tea is in order? ;-) i'll go with what i got. i wouldn't have posted except it just rubs me the wrong way to do this. i feel dirty on the inside... eh g. On 12/29/05, JesterXL [EMAIL PROTECTED] wrote: Wrong? Dude, wtf? Why don't you drink some coffee and take a look at what the hell VB is doing (ASP, whatever). It's calling a constructor, passing in a value.. and that value turns into an associative array.. but... the assignment is backwards, and you assign the return value of the constructor instance (that wasn't created because you didn't use new) to an associate array that acts like a getter setter? Oh... ok... lemme just uh... go do a line of coke, and that makes perfect sense! I can see why you are posting about this on Flashcoders so late at night about brackets vs. parens. If the above makes sense to VB guyz, then hell yeah, do whatever you can to make it easier for them to transition to clarity of code. :: puts gun to head :: -- weblog: broadcast.artificialcolors.com blazePDF: www.blazepdf.com band: www.cutratebox.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders