lua-users home
lua-l archive

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


Alexander Gladysh <agladysh@gmail.com> writes:
>>> Rule #437: Never hoist out constants (if possible)!
>
>>> Always write constants inline, otherwise they are treated as
>>> variables, which generates worse code. And, yes, even plain Lua is
>>> able to fold 1/5 into a constant. It's important to write these
>>> unambiguously -- FP arithmetic is not associative!
>
>> Good to know, but bad programming practice from a formal point of view. :-)
>> I always recommend to beginners in programming to replace magic numbers with
>> constants, for readability and consistency. I understand that speed
>> optimizations sometime have to break these nice rules (like manual loop
>> unrolling and such).
>
> My opinion as well.

And mine.

If Luajit has trouble identifying these, perhaps it would be useful to
have some sort of annotation that could be added to tell it?

E.g., in comments or something... (so the code would still be valid Lua code)

-Miles

-- 
Somebody has to do something, and it's just incredibly pathetic that it
has to be us.  -- Jerry Garcia