Getting rid of bitwise operators in Python 3?

Grant Edwards grante at visi.com
Sat Sep 22 01:19:42 EDT 2007


On 2007-09-22, Carl Banks <pavlovevidence at gmail.com> wrote:

> Anyone with me here?  (I know the deadline for P3 PEPs has passed; this 
> is just talk.)

Not me.

> Not many people are bit-fiddling these days.

I do.

> One of the main uses of bit fields is flags, but that's not
> often done in Python because of keyword arguments and dicts,
> which are lot more versatile.  Another major use, talking to
> hardware, is not something oft done in Python either.

I do it all the time.

Bit fiddling is also required for implementing communications
prototocols.

> It seems like this occasional usage wouldn't justify having built-in 
> operators on its own.  And with the int/long unification, it makes a bit 
> less sense to think of integers as a bit field.  Python has these 
> operators because of its heritage, but Python continues to move away from 
> the bad habits of its ancestors (integer division and so on), and I 
> wonder if this isn't another one.
>
> Of course I'm not suggesting to get rid of bitwise operations altogether; 
> just make them builtin functions: "x & 1" becomes "bitwise_and(x,1)" and 
> so on.
>
> Is it worth it to make such a change?  It would remove a lot of operators 
> (11 by my count), vastly simplifying syntax,  Which, IMHO, is no small 
> thing.

If you don't want to use the bitwise operations, then ignore
them.  Presto!  Simpler syntax.

> Obviously, how widespread their usage is would matter.  But keep in mind 
> it would also be easy to convert the code automatically, because the 
> Python parser could reliably find all bitwise operations reliably.

The resulting code wold be fugly.

-- 
Grant




More information about the Python-list mailing list