new bitwise module [was Re: Discussion: new operators ...]
Christian Tanzer
tanzer at swing.co.at
Wed Aug 2 01:32:33 EDT 2000
"Neil Hodgson" <neilh at scintilla.org> wrote:
> > Proposing to deprecate the shift and bitwise operators in favor of named
> > functions has no chance without a PEP. I counted three people in all with
> > favorable reactions on c.l.py (Paul Foley surely was, as Alex detected,
> > gently ribbing it by taking the idea to its logical conclusion and
> > reinventing Lisp). That's a start, but not much support yet.
>
> Its generally considered bad form for everyone to contribute "me too"s
> but Tim hasn't seen enough support so:
Let's support Tim, then...
> Me too - bitwise operations should be functions named with sensible
> alphabetic names rather than cryptic "|", "&" and so on.
If you prefer named functions to operators, they are already there:
>>> import operator
>>> dir (operator)
['__abs__', '__add__', '__and__', '__concat__', '__delitem__',
'__delslice__', '__div__', '__doc__', '__getitem__', '__getslice__',
'__inv__', '__lshift__', '__mod__', '__mul__', '__name__', '__neg__',
'__not__', '__or__', '__pos__', '__repeat__', '__rshift__',
'__setitem__', '__setslice__', '__sub__', '__xor__', 'abs', 'add',
'and_', 'concat', 'contains', 'countOf', 'delitem', 'delslice', 'div',
'getitem', 'getslice', 'indexOf', 'inv', 'isCallable',
'isMappingType', 'isNumberType', 'isSequenceType', 'lshift', 'mod',
'mul', 'neg', 'not_', 'or_', 'pos', 'repeat', 'rshift',
'sequenceIncludes', 'setitem', 'setslice', 'sub', 'truth', 'xor']
>>> operator.and_.__doc__
'and_(a, b) -- Same as a & b.'
Defining sensible aliases should not be difficult.
> But compatibility means we've already lost this one.
If that means that you would remove the operator symbols completely, I
sure hope that compatibility will win. I'd rather not go hunting for
all occurrences of `cryptic symbols' and replace them with function
calls.
--
Christian Tanzer tanzer at swing.co.at
Glasauergasse 32 Tel: +43 1 876 62 36
A-1130 Vienna, Austria Fax: +43 1 877 66 92
More information about the Python-list
mailing list