|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Thu Jun 18, 2009 2:41 am
Question regarding zscript |
I know it isn't required and you can refer to any object located in one class from any other class using just the name/ID. However, does it help any at all to enter the full location, such as @Class/varName or @Class/functionName()? I do this when I have more than one variable or function with the same name because every class has full access to any other class and you need the right variable or function to be referenced. I'm just wondering if it would be better to do it with everything that is assigned a value in or called from that class if it isn't located in that class itself.
|
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Thu Jun 18, 2009 6:10 am |
I'm not sure what you mean by help by that I think it does.
I suspect (although I forget the nitty gritty details) that you can save a few nanoseconds on variable referencing simply because you don't have to look through all the scoping rules to find the correct variable. Syntactically and semantically it probably doesn't matter that much. I prefer to use it, 1) because I think it's a good a habit and 2) because most of the packages I develop I expect to post in the package library. Since you can never be too sure what other variables folks have around, I feel much more comfortable using explicit variables in my scripts.
Now it's possible I completely missed your questions intent, and if I did ignore my ramblings. |
|
_________________ Asati di tempari! |
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Thu Jun 18, 2009 6:47 am |
No you have it right. I was thinking it would be better and a little bit faster too, but wasn't sure if any speed was gained or if it was worth the trouble of writing the extra code. I posted a script in the beta forum where I asked a question regarding "faking" OOP in Cmud and used the full reference location, mainly because I used multiple variables and functions with the same name, but they aren't available to any function outside of the class they are in because of that--at least to the scripts. I'm thinking though, because of the reasons you stated, that I might start doing it with every class where I am referencing anything outside of that class. The only bad part is it can make the code much much larger. However, I think it really helps with readability as a tradeoff.
|
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Thu Jun 18, 2009 5:54 pm |
Actually, it doesn't matter hardly at all. Once a script is compiled, both methods have a direct pointer to the variable record. So CMUD only needs to perform the class lookup once (on compilation).
As far as the lookup during compilation, using the full path requires CMUD to parse the path and split it into a module/class name and the variable name. Then it does an indexed database lookup with the module/class and variable name. If you don't use the full path, then it does a lookup just by name and retrieves a list of all variables with the same name. Then it applies the current class scope to determine which record in the list to use. If you have lots of variables with the same name, then this can add a small bit of time.
So the reasons for choosing the full path or not really have nothing to do with performance. You have both touched upon the other more important reasons to choose one format over another. Using the full path defeats the scoping rules, which isn't necessarily a good thing.
I'd say to use the full syntax if you are developing a package and really know what you are doing. |
|
|
|
|
|