lua-users home
lua-l archive

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

KHMan <> wrote:

> Let me just state for the record that I have no objection to the current Lua 5.3.x behaviour. Corner cases have to be handled; there are no beautiful solutions. So they are handled, but is it a good idea to start habitually relying on corner cases?
> I would just steer well and truly clear of all things slippery. No fractions in loops. No mixed numbers. No out of range numbers. No numbers close to data type limits. Just loops with zero surprises.

Considering it was your example code that kicked off this entire discussion
about the problems with loops I would have thought you would appreciate the
patch I crated and would want to see it applied to the codebase.

At least with my patch one surprise is removed when using min/max integers,
and another when using floating loops and a step size magnitude that is
too small to properly affect the loop variables. Thinking about what Dirk
said as well, one final tweak could be done with floating loops by adding
half the step size to the loop limit variable to ensure the final iteration
is executed in the case where the floating precision drifts.

Granted, these are issues that probably don't come up all that often, but
since the patch is really just a small logic shift it would seem better
to apply it than not. Loops with zero surprises are very nice, especially
if the language helps take care of that and not the developer! ;)