lua-users home
lua-l archive

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

David Manura <> writes:
>> Yeah; "band", "bor" etc are hardly _pretty_, but they're at least
>> somewhat familiar and normal-looking.  AND, OR, etc, just stand out
>> absurdly in code, and scream for attention.
> With code having lots of bitops, I'd probably do things like
>   local OR = bit.bor or bit32.OR  -- prefer JIT-optimized ops
>   local AND = or bit32.AND
>   local NOT = bit.bnot or bit32.NOT
>   ...
>   if not t or NOT(OR(x,y)) == 1 and AND(z,w) == 0 then ... end

Hmmmm, the uppercase names seem not only equally ugly when used
without a package-prefix, but actually kind of confusing -- in such a
case, the only difference between "and" and "AND" is case and
position, and it's generally a poor idea to use names differentiated
only by case.  Just imagine a newbie reading this code....

Compare that to:

    local bor = bit.bor or bit32.bor  -- prefer JIT-optimized ops
    local band = or
    local bnot = bit.bnot or bit32.bnot
    if not t or bnot(bor(x,y)) == 1 and band(z,w) == 0 then ... end
I think that's not only prettier, but much more clear as well:  the
"b" prefix makes the "bittiness" of the operations more obvious at a

[Of course one is free to rename things when assigning to local
variables, and I suspect many people will do that ... but it's a shame
the "official" names are so ugly.]


Twice, adv. Once too often.