Thread Tools Display Modes
Prev Previous Post   Next Post Next
04/25/14, 06:49 PM   #1
LoquaciousAndroid
Join Date: Apr 2014
Posts: 1
globals, locals, and namespaces, oh my

Apologies for the terrible Wizard of Oz reference, and more apologies if this topic has already been brought up.

I'd like to start by saying that I'm amazed at what this community has accomplished in such a short amount of time. You guys have extended ESO's UI by leaps and bounds since launch, and I love using your addons!

One thing I've noticed while checking out your code is that most of the functions live in global scope. Since lua doesn't have any real namespace support (I'm not counting tables), I humbly suggest either:

- Prefixing your global functions with a "AddOnId_" tag
- Make functions and symbols that don't need to be globally accessible, local instead

The latter is probably a better idea, since accessing locals is much faster than looking something up in _G.

I am mostly bringing this up because when I see a function like initVars declared at global scope, I'm just amazed that it hasn't collided with some other addon I've installed.

Keep in mind that the scope at which something lives is ENTIRELY dictated by the keyword "local":

Code:
local function SomewhatPrivate()
    local localToFunction = 5
    actuallyGlobal = 6
end
In that case, "actuallyGlobal" is completely accessible to any addon...sometimes this is good, sometimes it isn't.

Anyway, thanks for reading. Hopefully this helps promote clean coding, and reduces potential conflicts and random bugs when players decide to use many of the wonderful addons you authors have provided!
  Reply With Quote
 

ESOUI » Developer Discussions » General Authoring Discussion » globals, locals, and namespaces, oh my


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off