python: bug or feature?

Bernhard Herzog herzog at online.de
Thu Aug 10 16:50:28 EDT 2000


hzhu at localhost.localdomain (Huaiyu Zhu) writes:

> On 10 Aug 2000 12:52:14 +0200, Bernhard Herzog <herzog at online.de> wrote:
> >
> >hzhu at localhost.localdomain (Huaiyu Zhu) writes:
> >
> >> This just shows that the current arrangements of logical operators and
> >> bitwise operators is a misfeature.  Bitwise operations do not deserve
> >> cryptic symbols,
> >
> >But matrix operations do? ;-)
> 
> I see the smilie.  But to protect the innocent from being misled: :-) I was
> talking about the _arrangement_ between them.  & | ~ ^ are cryptic when you
> try to visually link them to (and) (or) (not) (xor).

Well, ~ for not is pretty common in maths, I'd say. & for and is at
least easy to remember, although ^ would look more like the symbol used
in maths. | for or and ^ for xor is indeed not obvious at all.

> I understand why they might need a different level from logical operators.
> But why not just one bitwise level?  Is the individual precedence levels for
> bitwise operators so obvious that users could avoid using parenthesis and
> ckecking docs?  Does the language really need four separate precedence
> levels just for bitwise operation?

Ah, I see. That ~ has a higher precedence than the binary operators
should be expected, I think. Unary operators generally bind stronger
than binary ones. That & binds stronger than | is also a common
convention, although this is certainly less known than the higher
precedence of the multplicative operators when compared to the additive
operators.

But anyway, what's the problem with each of these operators having their
own predence level? If you're unsure what the precedence is you can
insert parenthesis to make things clear. It is a bit inconvenient if you
read someone else's code that makes use of the precedence levels because
you'd have to look them up if you're not sure, but since in my
experience bitwise boolen expressions are usually quite simple this
doesn't happen very often.

-- 
Bernhard Herzog   | Sketch, a drawing program for Unix
herzog at online.de  | http://sketch.sourceforge.net/



More information about the Python-list mailing list