Hi Brad,
there is no definite answer from my side, just stating the obvious -
sometimes that can be a help, too.
I've been curious for awhile about why C supports some of its binary
operators in an op= format, but not others. For example, why are &=
and |= supported by C, but not &&= and ||=?
If anyone has any insight into the rationale for this, please let me
know. My sense has been that such operators would occasionally be
useful, and I've considered adding them to my own C-like languages,
but want to be sure I'm not overlooking something subtle.
The "supported" operators are the binary operators for arithmetic
and bitwise operations. IMO, reasons are
- the behaviour and types of operands and result is clear or easy to
define
- these operations are used rather often, so a shortcut makes sense
- for early none-too-intelligent compilers, this was a help to generate
assembler code which was faster if there were corresponding
operations (e.g. on a Motorola 68xx I've been playing with,
adding two values and storing the result in a different value
took one cycle longer than adding one value to another)
- in the same vein: this is AFAIK not true for logical operations and
the like
Now, introducing &&=, ||=, ===, ->=, .=, ... in general may be
a nice idea if you need it a lot; even ?=: is an option.
For the logical AND and OR as well as for ==,>=,<=, I think that
the readability of your code might suffer, apart from the
higher probability of errors by typing not enough or too many
&,|,=.
The ->= is also prone to the latter problem, if you manage to
forget the >.
For <=,>= there are <== and >== but what is there for <,> ?
Maybe someone else can contribute a little bit more.
So, the only "real" downsides are that you have to teach it to the
compiler and that you'll be one of a very small group to use
the resulting language in full :-)
Cheers,
Michael