lua-users home
lua-l archive

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


CrazyButcher <crazybutcher@luxinia.de> writes:
>> Sure, but often the goal is not "optimization", but clarity -- if the
>> factored-out expression is long, it can be significantly harder to read
>> code without the factoring-out.   [I.e., "straightforward" doesn't
>> always equal "readable"]
>
> that's why Mike stressed the fact that both ways will work correctly.
> As I was asking for optimal use, it's the kind of reply I wanted.

Er, right, but the _degree_ to which such practices might cause less
efficient code is important in many cases.

Maybe for your usage, you don't care, and just want what's most
efficient, but I think most programmers will to some degree be looking
to understand the tradeoffs involved.  I think most experienced
programmers have a reasonable intuition about these tradeoffs for more
traditional environments (base Lua, C/C++, etc).

In C/C++, I know that while aliasing can sometimes be an issue with such
code, it's generally not a big deal as long the scope is kept small
(e.g., within a loop body, not across a function call, etc), and perhaps
avoiding certain specific circumstances.

It's tempting to think of LuaJIT as "just another compiler" -- and thus
that the tradeoffs might be similar -- but in fact I guess that's not
necessarily true.

Really what I want is some good intuition to latch onto.  With
traditional compilers, one can often get this by examining assembly
output and doing benchmarking, but this seems harder with a JIT
compiler....

-Miles

-- 
The car has become... an article of dress without which we feel uncertain,
unclad, and incomplete.  [Marshall McLuhan, Understanding Media, 1964]