lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, Dec 27, 2010 at 18:46, Patrick Mc(avery
<spell_gooder_now@spellingbeewinnars.org> wrote:
> " I think you are looking for locals inside modules, or upvalues"

> My newest project will probably be under 1K lines of code and would work
> with a poorly designed layout but I want to improve my habits. I do
> understand PIL/modules/upvalues quite well now but I am wondering if there
> are different strategies for managing much larger projects. I understand
> that lightroom is over 100k lines of Lua and there are other large
> applications too. Are there numerous design patterns out there to keep
> people from clobbering variables and organizing this much code?

I maintain several Lua-based projects with maybe 200+ KLOC of
human-written Lua code now (hard to say nowadays with all this
codegeneration etc.)

We do not bother with clobbering variables — aside of global
environment protection of course (which we do statically whenever we
can). But even this is to protect from human errors, not "malicious
design".

One thing that, maybe, helps us is that it is strictly forbidden to
assign anything to global variables anywhere (aside from a couple of
places in bootstrapper code where it is inevitable). Our global
environment protection system ensures that.

Another thing is that all private variables of an object are named
with the underscore ("_") in the end. If, on code review, we catch
someone working with these variables outside of the object, well, um,
we tell him that he should not do that, and he goes to rewrite that.
(I do not think that it actually happened in practice despite that the
rule is not enforced by the tools.)

You do not need to enforce privacy any more than you need, that is a
waste of time, IMO. If you're working on the internal project with
small enough team of programmers who at least minimally sane, these
two rules should keep you from harm privacy-wise. Well, plus what
David Manura just wrote about consistency and minimal scope and tests
— but that is true for any language out there, a minimal sanity level.

Note that we do not use Hungarian notation, mentioned by David, here,
we use type validation instead where it is important:

https://github.com/lua-aplicado/lua-aplicado/blob/master/lua-aplicado/filesystem.lua#L63-65

My 2c.

Alexander.