lua-users home
lua-l archive

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


David Manura wrote:
On Thu, Nov 18, 2010 at 11:23 PM, Miles Bader <miles@gnu.org> wrote:
Nick Gammon <nick@gammon.com.au> writes:
What is the motivation for the ALL CAPS function names in the bit library?
My guess it is to avoid the use of the reserved words "and" and "or".

However it does look UGLY.
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 = bit.band 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



I wonder why no one has suggested bit32.And, bit32.Or ... etc.
Does that look less ugly? At least it doesn't call to mind constants (to me at least).
But I must admit that, after all, you could always do that as
local And = bit32.AND

-- Lorenzo