lua-users home
lua-l archive

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


Philippe Lhoste wrote:
> >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.

You mean like a21, a31, a32 and so on as in the original code?
Yeah, that improves readability like 1000%. :-)

[The original author used this solely because Python doesn't
fold constants.]

Magic comes sparingly, and any not-so-magical constants might as
well live inline.

--Mike