Does Python need a '>>>' operator?
Alex Martelli
aleax at aleax.it
Sun Apr 14 03:44:47 EDT 2002
Martin v. Loewis wrote:
> Roy Smith <roy at panix.com> writes:
>
>> Any operator can get replaced by a function call. It's just a matter of
>> what's more convenient to write.
>
> Indeed, and so it is desirable to have infix shorthand notations for
> the frequent operations. However, as the number of infix operators
> grows, the convenience loses: you now have to start remembering line
> noise.
Very well put. Indeed, given the small amount of bit-twiddling in
typical Python usage, I think & ~ | ^ are already overboard -- they
make a lot of sense in C, a very low-level language that is used a
LOT for bit-twiddling, but, in Python, named built-in functions might
have been more appropriate in hindsight (fewer precedence levels to
remember) -- if not, even, functions in a separate module.
A simple histogram of non-alphameric tokens in Lib/*.py only partially
conforts this thesis:
0 18495 )
1 18495 (
2 16820 .
3 15467 :
4 15327 ,
5 12989 =
7 4487 ]
8 4487 [
9 2426 +
10 1434 ==
11 1044 -
12 699 %
13 488 `
14 481 *
15 342 !=
17 305 <
18 280 }
19 280 {
20 256 >
21 150 >=
22 128 <=
23 117 &
24 100 /
25 80 +=
26 73 ;
27 67 |
28 34 >>
29 29 **
30 27 <<
31 21 //
35 9 ~
[ cut here ]
I'll have to get a better / wider / more representative corpus of
Python sources before my dimly-remembered background in computational
linguistics can be used here, I guess -- these numbers are just too
small (and from a probably non-representative sample). Hmmm, maybe
Parnassus... It's all academic, of course, anyway. But even though
we're looking at code so bit-oriented than it bitmasks (&) more than
it divides (or just a bit less, if you count both / and //), bitwise
xor is hardly popular in it -- _that_ much we can already state:-).
Alex
More information about the Python-list
mailing list