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

Terry Reedy tjreedy at udel.edu
Mon Dec 13 17:37:42 EST 2004


"Petr Prikryl" <Prikryl at skil.cz> wrote in message 
news:F7789324060E8A4E9C765780D6B514B8150AD9 at skil01.skil.mistni...

>Summary: In my opinion, the C-like prefix
>increment and decrement operators (++i and --i)

Python is not C.  In Python, ++x and --x are the same as + + x and - - x 
are the same as +(+x) and -(-x) (as you later guessed, and could verify in 
the Ref Manual).  A pair of operators is not an operator, let alone an 
increment or decrement operator.  The pair of operators is just that, a 
pair.  So the premise of this opinion is wrong.

To succeed in Python, one must drop the C mindset and switch to a Python 
mindset.  And there are much deeper issues than this surface syntax one, 
such at the difference in object models.

>should be marked as "syntax error".

I completely disagree.

Unless you also propose to ban syntactical equivalents such as I gave above 
(even worse), you are proposing two nitpicky lexical exceptions to Python's 
general lexical rules.  They would, I believe, be unprecedented.  They are 
certainly senseless within Python itself.  They are also contrary to the 
basic philosophy of Python of avoiding unnecessary exceptions, which 
complicate both the learning of the language and its parsing.

You could propose to the author of Pychecker that he include, if possible, 
an option to check for and warn about '++', '--'.  But it should be 
optional because '++' and '--' could be legitimate and sensible when 
applied to user-class instances.  Consider the (non-circular) Python 
definition of bool (now builtin):

def bool(obj): return not not obj

Terry J. Reedy






More information about the Python-list mailing list