[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: In praise of globals
- From: Dimiter 'malkia' Stanev <malkia@...>
- Date: Tue, 16 Apr 2013 11:14:37 -0700
You can tell the programs written by the supporters of this ideology.
They start out something like this:
local pairs, ipairs, print, tostring, getmetatable, setmetatable
= pairs, ipairs, print, tostring, getmetatable, setmetatable
Yeah, that's going a little far. Everyone knows what ipairs is -- no
need to localize it.
I think the point here is to avoid being "monkey patched" - e.g. someone
might chagne what pairs, ipairs, ... do affecting your module.
Effectively what Dirk is trying to say - is that there is so much global
state, that you might have to learn with it.
To fully isolate from global state, the first thing you have to do is to
capture (e.g. "un-free") all global functions, vars, etc.
I only wish there was easier way to do that in lua/luajit, a pattern
along the line of "local something = something" to be just "import
something" or "use something" or something like it.