I can't imagine why my example wouldn't work, as it's basically just a supremely stripped down version of Spelling (you might want to take a look at that). I can't see anything I've missed, to be honest. I might've screwed up the variable numbering (one too many underscores?), or there might be a typo somewhere there, but that's all I can think of. I'll look into it the next time I'm in game (I'll make a temporary mod out of my example).
Since I'm off to bed though, I'll leave this one open to the crowd. Anyone, anyone, Beuller?
And yes indeed, Seerah. Cramming junk into the global namespace is generally a bad practice, even Programming in Lua tells us so. The only people who really do it anymore are Blizzard (sorry Blizz, but it's the truth!) or people who're new to mod coding. Everyone picks up on this eventually though and their mods are all the better for it.
It seems like even Blizzard is learning with some elements though, like finally eliminating args. Now iif only they'd go back to all of their Blizzard_ mods and rewrite those to not use so many global variables, functions, and tables. I think it's those setting a bad example that's giving people the wrong idea.
Edit: Almost forgot to mention...
Originally Posted by Slakah
Yeh I get locals and globals I just personally try and use tables as sparingly as possible, I'm still fairly new to coding and thus I use terms in the wrong places :P.
|
Me too, I don't like crowding things up with tables, that's generally a bad practice too. That's why I like reusing tables as much as possible. Garbage collection is great, but if you have tables upon tables with tables in them, then the memory use of the mod is going to climb exponentially. Whenever RegisterEvent is involved though, there has to be a table
somewhere to accomodate for the frame. Ace creates its own frame (and frames are basically tables with special values), XML based frames are the same, and CreateFrame() is also basically the same.
So, like I said, if the table has to be created... then one might aswell use it. If one doesn't need a table, then a whole slew of locals is better.