Larry Wall writes:
> Alternately, we take | and & away from bitwise ops and do something
> more useful with them.

I for one would be extremely happy to see that happen.  Giving the bitwise
operations single-character names, while reasonable in the historical
context of (B and) C, suggests that they're useful way more often than they
actually are.  (That applies particularly for a high-level language like
Perl, in my experience.)

I find the problem particularly apparent when delivering Perl training.
Many problem domains have little if any use for bitwise operations, and few
students have a background leading to familiarity with bitwise ops.  What I
normally do is simply avoid teaching those operators to groups that won't
need them -- but there's often a student who's heard of them and who asks
questions about them.

Vaguely heretical, I know, but I'd be inclined to do something like this:

  Perl 5     Proposed Perl 6
  $x && $y   $x & $y
  $x || $y   $x | $y

  $x & $y    bitand($x, $y)
  $x | $y    bitor($x, $y)

Using functions instead of operators for these operations seems reasonable
to me given how often they're useful.  I'm not especially fond of the names
bitand and bitor, but they're accurate, reasonably short, and have prior art
in C and C++.

Two things about this proposal:

  * This leaves && and || available for other purposes, but I can't off the
    top of my head think of anything else I'd want them for.

  * Does this make it harder to write overloaded bitwise ops for your
    classes?

-- 
Aaron Crane * GBdirect Ltd.
http://training.gbdirect.co.uk/courses/perl/

Reply via email to