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

Discussion in 'Python' started by Terry Reedy, Dec 13, 2004.

  1. Terry Reedy

    Terry Reedy Guest

    "Petr Prikryl" <> wrote in message
    news:...

    >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
     
    Terry Reedy, Dec 13, 2004
    #1
    1. Advertising

  2. "Terry Reedy" <> wrote in message
    news:...

    > You could propose to the author of Pychecker that he include, if possible,
    > an option to check for and warn about '++', '--'.


    It does already.
     
    Richard Brodie, Dec 14, 2004
    #2
    1. Advertising

  3. Richard Brodie <> wrote:
    > "Terry Reedy" <> wrote in message
    > news:...
    >
    > > You could propose to the author of Pychecker that he include, if possible,
    > > an option to check for and warn about '++', '--'.

    >
    > It does already.
    >
    >


    $ cat plusplus.py

    def main():
    i = 1
    return ++i

    $ pychecker plusplus
    Processing plusplus...

    Warnings...

    plusplus.py:4: Operator (++) doesn't exist, statement has no effect

    --
    Nick Craig-Wood <> -- http://www.craig-wood.com/nick
     
    Nick Craig-Wood, Dec 15, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Balaji
    Replies:
    3
    Views:
    10,201
  2. Petr Prikryl

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

    Petr Prikryl, Dec 13, 2004, in forum: Python
    Replies:
    7
    Views:
    375
    Doug Holton
    Dec 21, 2004
  3. Petr Prikryl
    Replies:
    4
    Views:
    348
    Mel Wilson
    Dec 14, 2004
  4. Good Night Moon
    Replies:
    9
    Views:
    319
    Rick DeNatale
    Jul 25, 2007
  5. Mark Richards
    Replies:
    3
    Views:
    348
    Tad McClellan
    Nov 18, 2007
Loading...

Share This Page