lua-users home
lua-l archive

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

Am 30.03.2014 19:57 schröbte Andrew Starks:

I think it's bad, because it might be motivation to not use strict or
to consider it a "hack."

It *is* a hack. An impressive one because it achieves a lot with little code, but on the other hand it modifies a shared resource, so it affects other people's code, and prevents them from setting a metatable on `_G` themselves (or at least makes it harder). And as you already mentioned, there are a lot of alternatives (most of which I consider superior to `strict.lua`), and this is my main motivation not to use `strict.lua` ...


My idea (probably not a new one) is in two parts:

1: `global` keyword is (probably) shorthand for rawset(_ENV, var, val)

Most module writers would probably use `rawset` directly anyway, because it is compatible with Lua 5.x (for x < 3). I think the current approach is `var = nil` somewhere at top level, which is also backwards compatible. So, IMHO, a new keyword would do more harm than good ...

2: _STRICT is a value that is global and defaults to `false` (or nil,
but one must be able to assign it globally).

Why not just preload `strict.lua` instead?! Then people can `require` it if they want to. But I'd rather use something that works offline (at compile time), or at least can be enabled/disabled on a per-chunk basis (maybe as a fallback to the offline tool).