lua-users home
lua-l archive

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

Mike Pall <mikelu-1102 <at>> writes:
> Rule #437: Never hoist out constants (if possible)!

This seems like a big limitation to me -- is there any way to
work around it?

Hoisting calculations out of loops is a big efficiency win when
the calculation is based on any other variable.  Telling
programmers to hoist non-constant calculations but *not* hoist
constant calculations seems like too much mental burden, especially
when a hoisted constant calculation *looks* like it should be
at least as efficient as not hoisting.  There's also the 
readability/maintainability benefits of giving constants a name.

I feel like you may be unduly influenced by the fact that
constant hoisting is currently not efficient, and extrapolating
from there that it is not good programming practice.  But I think
that it is widely recognized as good programming practice, at
least in my experience from numerous code reviews I have been
through.  Ideally there would be a way to make it efficient
instead of having to tell programmers over and over that the
efficiency of hoisting is the opposite of what they expect.

Is the debug API the issue here?  Without funny business going
on it seems that LJ should be able to recognize that a variable
is only assigned once.