[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: strict.lua
- From: Steve Litt <slitt@...>
- Date: Fri, 30 Mar 2012 04:37:49 -0400
On Fri, 30 Mar 2012 02:27:49 -0500
Coda Highland <chighland@gmail.com> wrote:
> On Fri, Mar 30, 2012 at 1:52 AM, steve donovan
> <steve.j.donovan@gmail.com> wrote:
> > On Fri, Mar 30, 2012 at 1:56 AM, Coda Highland
> > <chighland@gmail.com> wrote:
> >> Well, the whole idea of doing it with the command line flag is that
> >> you can turn it on during development and then not have the
> >> overhead of having a metatable on _G in production use.
> >
> > Ah, but strict.lua does not actually cost you anything, because _G's
> > __index only gets fired if the symbol is _not_ found, which is an
> > error condition.
> >
> > steve d.
> >
>
> Well, __newindex too, but on the assumption you don't create many
> global variables I suppose that's a valid point.
>
> /s/ Adam
Hi Adam,
I was all set to say that if you have lots of globals, you don't care
about safety anyway and almost certainly wouldn't use strict.lua. Then
I remembered the point you made a few posts back in this thread --
strict.lua can also be used as a debugging tool. I should know that
better than anyone. I'm careless and make a typo every 2 lines of new
construction, which I then have to find and fix. Finding them is a heck
of a lot easier if the error happens on the typo, rather than a few
subroutine calls later, so strict.lua would be the ideal debugging tool
for me.
To me, the first question I'd ask when trying to decide whether whether
to leave strict on in production is to ask how fast my code needs to
be. If I were writing a realtime game, I'd need all the speed I could
get. But if I were writing a wordprocessor, the program needs only
enough speed to beat the bottleneck, and the bottleneck is the 100 WPM
the user is typing, which any reasonable algorithm on any computer less
than a decade old can do easily, so heck, I'd leave it in.
One benefit of leaving it in is that it's entirely possible your
testing didn't exercise everything in your program, and there's an
undeclared variable in the untested part. In production without
strict.lua, you might get intermittent crashes way far away from the
undeclared variable use. With strict.lua, production crashes give a
very helpful error message pointing right to the problem.
Personally, I'm going to use strict.lua every time, and if later I
perceive a speed problem, I'll take it out and see how much faster
things go.
Thanks
SteveT