A Bug By Any Other Name ...
Albert van der Horst
albert at spenarnc.xs4all.nl
Fri Jul 17 16:53:36 EDT 2009
In article <mailman.2664.1246857607.8015.python-list at python.org>,
Gabriel Genellina <gagsl-py2 at yahoo.com.ar> wrote:
>En Mon, 06 Jul 2009 00:28:43 -0300, Steven D'Aprano
><steve at remove-this-cybersource.com.au> escribi?:
>> On Mon, 06 Jul 2009 14:32:46 +1200, Lawrence D'Oliveiro wrote:
>>
>>> I wonder how many people have been tripped up by the fact that
>>>
>>> ++n
>>>
>>> and
>>>
>>> --n
>>>
>>> fail silently for numeric-valued n.
>>
>> What do you mean, "fail silently"? They do exactly what you should
>> expect:
>>>>> ++5 # positive of a positive number is positive
>>
>> I'm not sure what "bug" you're seeing. Perhaps it's your expectations
>> that are buggy, not Python.
>
>Well, those expectations are taken seriously when new features are
>introduced into the language - and sometimes the feature is dismissed just
>because it would be confusing for some.
>If a += 1 works, expecting ++a to have the same meaning is very reasonable
>(for those coming from languages with a ++ operator, like C or Java) -
>more when ++a is a perfectly valid expression.
>If this issue isn't listed under the various "Python gotchas" articles, it
>should...
In algol 68 there was one thing strictly forbidden: putting two
operators behind each other:
x := y** -b .comment must be x := y**(-b) .comment
This is quite a sensible rule, especially when, like in Python,
two special characters can be run together to denote a different
operator.
Examples abound : +:= **
A consequence is that 'a*-b'
would be illegal. It would become 'a*(-b)'
Worse is that x=-q would be illegal.
Because unlike in algol 68 in python whitespace is relevant,
we could get by with requiring whitespace:
x= -q # okay
a<b and -a<c and -b < -d # okay
8 ** -2 # okay
Once a c-addict is forced to write
+ +a
she will realize that probably the operator is + is applied to
+a, and that a ++ has no meaning.
>--
>Gabriel Genellina
Groetjes Albert
--
--
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
More information about the Python-list
mailing list