Suggestion for "syntax error": ++i, --i

Christian Ergh christian.ergh at gmail.com
Mon Dec 13 17:35:54 CET 2004


Ah, ok, i misunderstood you. Well, to mark it as a syntax error sounds 
good, and at the Moment I would not know a case where this conflicts 
with a implementation.
Chris
Petr Prikryl wrote:
> Hi Christian,
> 
> The suggestion is to mark PREFIX version ++i as
> syntax error. It is not related to the postfix 
> version of the ++ operator. For prefix in/decrement,
> there is no extra variable behind. But again,
> it is not related to the suggestion. The postfix
> version is already marked as "syntax error".
> The suggestion is to do the same with the prefix
> version of the operators that are not used in Python.
> 
> Petr
> 
> "Christian Ergh" wrote...
> 
>>Hmm, i never liked the i++ syntax, because there is a value asignment 
>>behind it and it does not show - except the case you are already used
> 
> to it.
> 
>> >>> i = 1
>> >>> i +=1
>> >>> i
>>2
>>
>>I like this one better, because you see the assignment at once, it is 
>>easy to read and inuitive usability is given - in my opinion.
>>Chris
>>
>>
>>
>>
>>Petr Prikryl wrote:
>>
>>>Hi,
>>>
>>>Summary: In my opinion, the C-like prefix
>>>increment and decrement operators (++i and --i)
>>>should be marked as "syntax error".
>>>
>>>
>>>Current situation: try... (Python 2.4 (#60, ...))
>>>
>>>
>>>>>>i = 1
>>>>>>i
>>>
>>>1
>>>
>>>
>>>>>>i++
>>>
>>>  File "<stdin>", line 1
>>>    i++
>>>      ^
>>>SyntaxError: invalid syntax
>>>
>>>
>>>>>>++i
>>>
>>>1
>>>
>>>
>>>>>>--i
>>>
>>>1
>>>
>>>
>>>Reason for how ++i and --i behaves in Python is 
>>>that it is probably treated as (-(-i)) and (+(+i))
>>>respectively.
>>>
>>>Rationale: My guess is that many Python users
>>>do use other languages at the same time. 
>>>The C-family languages do use the prefix increment
>>>and decrement operators. When used in Python
>>>no warning appears -- the code simply does not work
>>>as expected. In the same time, there is probably no
>>>reason to use the increment and decrement 
>>>prefix operators. On the other hand, the newcommer
>>>or the programmer that "types ++i automatically 
>>>because of brain synapses say he/she should..."
>>>is not warned until something does not work.
>>>
>>>Con: The situation must be recognized by the parser
>>>(i.e. someone have to implement it).
>>>
>>>Pro: No runtime overhead except of the detection
>>>of the situation. As Python is a good candidate
>>>to be used as the language for teaching, the "syntax
>>>error" would be the pedagogical plus.
>>>
>>>Personal experience: Many things in Python work
>>>intuitively. My C++ experience "forced me" to use
>>>++i as described above. I use iteration more these
>>>days and I know about the ++i problem invisibility 
>>>in Python. But I had to learn by mistake. The ++i
>>>behaviour is not intuitive for me.
>>>
>>>Your opinion?
>>>
>>>



More information about the Python-list mailing list