Topic: Confusing names for alternative operator keywords


Author: Sungbom Kim <musiphil@bawi.org>
Date: Mon, 22 Jul 2002 16:40:58 GMT
Raw View
C++ tries to help programmers with incomplete characters sets
by providing them with alternative keywords:

    and     &&  (logical)
    and_eq  &=  (bitwise)
    bitand  &   (bitwise)
    bitor   |   (bitwise)
    compl   ~   (bitwise)
    not     !   (logical)
    or      ||  (logical)
    or_eq   |=  (bitwise)
    xor     ^   (bitwise)
    xor_eq  ^=  (bitwise)
    not_eq  !=  (relational)

I find this very confusing.

By looking only at the keywords, you cannot easily tell whether they
are bitwise operators or logical operators. For example, 'and' means
logical && but 'and_eq' means bitwise &=. Bitwise & is represented
by 'bitand' but bitwise ^ is represented not by 'bitxor' but 'xor'.
I guess someone who wants to use them should continually consult some
reference to be sure that he doesn't write something wrong.
Furthermore, it would be more confusing if in the future the committee
decides to have a logical XOR operator ^^, which is not very probable
but anyway reveals the inconsistency in the current nomenclature.

I'd like to know the rationale behind these names.

Well knowing that it's too late to change anything, if I were to
design the nomenclature from the beginning I would have chosen
more consistent and extensible names.

Option A: all bitwise operators beginning with 'bit'
          e.g. bitand(&) bitor(|) bitxor(^) bitcompl(~)
               bitand_eq(&=) bitor_eq(|=) bitxor_eq(^=)

Option B: each character represented by one word,
          e.g. and(&) or(|) xor(^) compl(~) not(!)
               and_and(&&) or_or(||) not_eq(!=)
               and_eq(&=) or_eq(|=) xor_eq(^=)

Now that I suggested it, I can see that the current standard
makes one exception in my Option B that 'and' and 'or' should
be given to (probably more used) && and || and that & and |
get 'bitand' and 'bitor' instead. A good way to memorize! :-)

--
Sungbom Kim <musiphil@bawi.org>

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]