FAQ
For quite a lot applications it would be nice to be able to treat bool as a
one bit (unsigned) integer, making all these operations such as & and |
well defined. It might be possible that these are implemented differently
under the hood, but that looks like a nice abstraction to the programmer.
Having an equal syntax for bit manipulation with *all* primitive types is
better than having one syntax for almost all types, except for bool which
has a special syntax only, that also has special semantics (short-circuit).

Imagine contexts where you'd like to evaluate a boolean formula. Writing
such code with != for ^ makes the code more difficult to understand for
some people who do not think about != being equal to ^ in the beginning. In
my opinion, code is much easier to read if the syntax for boolean / bit
functions is uniform across all types.

Am Freitag, 1. März 2013 20:35:32 UTC+1 schrieb Kevin Gillette:
I believe that the spec would be unnecessarily complicated if & or | were
no longer simply a bitwise op. otoh, those bit ops would do the right thing
if applied to booleans, and xor could also work if the bit values of true
and false are completely defined per implementation (rather than partially
defined, like ”false consists of all zero bits, true is anything else”).
However, most other arithmetical operators wouldn't work, so to allow this,
the spec would have to be complicated more than it'd initially seem: such
as making booleans ”nominal numerics” and all int types ”ordinal numerics”,
with certain operators applicable to both.

Still, floats and complex values don't have ask the same applicable
operators as ints, iirc, but at the same time I agree that the presence of
& and && for booleans would be too confusing, and there would no doubt be
zealous abusers, citing savings in characters and not understanding the
short circuit behavior.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 6 of 21 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 1, '13 at 7:02p
activeMar 3, '13 at 2:38a
posts21
users9
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase