"RokuMarkn" wrote:
The latter. It's bad programming style, and avoiding globals is one of the reasons Object Oriented programming was invented. I discussed this previously here. Other than poor style and difficulty in maintaining the code, it's not going to break anything if you use globals.
--Mark
"Komag" wrote:
Question - If I use "m" for "everything", it would create an additional layer for me, such as "m.cAA.mainMenu.w[1]" vs "cAA.mainMenu.w[1]". Everything would have this extra layer. Would that slow things down, since there is another dictionary lookup happening, or am I totally understanding that wrong?
"EnTerr" wrote:
Luckily in B/S whatever comes naturally - laziness, do less typing - is also faster. Working with a local variable ("x") is an order of magnitude (> 10x) faster than "dotting" as m.x (regardless whether for global or object member). SImplifying a little bit here: m.x is just syntax sugar for m["x"]. Using global functions and local variables is fast, anything that involves a dot - not so much. Don't get all crazy on me now and banish object use completely. Optimize later, you may not need it.
"NewManLiving" wrote:Yeah... no. There is no way for such references to be resolved in advance in dynamic languages like Lua or BrightScript, where X.Y is just a shortcut for X["Y"] and not a numeric offset inside a record. You don't know what's in `m` till you get to `m`.
It would all depend on how the compiler resolves references. If it's a good compiler then it will resolve the reference at compile time. It would be nice to have an official word.
"NewManLiving" wrote:That's the way to do it, yep. Luckily here laziness in typing co-insides with efficiency.
As a side note. If I have something like m.a.b.c in a loop or where I use it over a number of times I presently resolve it myself. l_var = m.a.b.c.
"EnTerr" wrote:"NewManLiving" wrote:Yeah... no. There is no way for such references to be resolved in advance in dynamic languages like Lua or BrightScript, where X.Y is just a shortcut for X["Y"] and not a numeric offset inside a record. You don't know what's in `m` till you get to `m`.
It would all depend on how the compiler resolves references. If it's a good compiler then it will resolve the reference at compile time. It would be nice to have an official word.
"TheEndless" wrote:"EnTerr" wrote:
There is no way for such references to be resolved in advance in dynamic languages like Lua or BrightScript, where X.Y isjust a shortcut for X["Y"] andnot a numeric offset inside a record. You don't know what's in `m` till you get to `m`.
According to my experimentation and the explanation from RokuMarkn here, you are incorrect... viewtopic.php?f=34&t=83110&p=476841#p476844