Re: Python ++ Operator?

Discussion in 'Python' started by Stefan Behnel, Jul 15, 2011.

  1. Chris Angelico, 15.07.2011 10:06:
    > 2011/7/15 Björn Lindqvist:
    >> Pre and post-increments are
    >> almost always confusing unless they are used as the counter-variable
    >> inside for-loops.

    >
    > I agree that they're often confusing (i+++++j) but there are several
    > places where they're handy.
    >
    > array[count++]=value;
    >
    > or the more direct pointer management:
    >
    > *ptr++=value;


    More direct, sure. But readable? Well, only when you know what this
    specific pattern does. If you have to think about it, it may end up hurting
    your eyes before you figure it out.

    Stefan
     
    Stefan Behnel, Jul 15, 2011
    #1
    1. Advertising

  2. Stefan Behnel

    Waldek M. Guest

    Dnia Fri, 15 Jul 2011 23:09:02 +0200, Stefan Behnel napisa³(a):
    [...]
    >> array[count++]=value;
    >>
    >> or the more direct pointer management:
    >> *ptr++=value;

    >
    > More direct, sure. But readable? Well, only when you know what this
    > specific pattern does. If you have to think about it, it may end up hurting
    > your eyes before you figure it out.


    Oh, come on. I don't say the post- and pre-incrementing is
    good or bad, but please don't exagerate.

    Almost any other construction is unreadable to people, who
    don't know this construction, eg. a==1, a+=1
    may be completely senseless to mathematicians.

    Best regards,
    Waldek
     
    Waldek M., Jul 16, 2011
    #2
    1. Advertising

  3. Stefan Behnel

    Nobody Guest

    On Fri, 15 Jul 2011 23:09:02 +0200, Stefan Behnel wrote:

    >> or the more direct pointer management:
    >>
    >> *ptr++=value;

    >
    > More direct, sure. But readable? Well, only when you know what this
    > specific pattern does. If you have to think about it, it may end up
    > hurting your eyes before you figure it out.


    If you have to think about it, you shouldn't even be using C.
     
    Nobody, Jul 16, 2011
    #3
  4. Stefan Behnel

    Robert Kern Guest

    On 7/16/11 4:55 AM, Waldek M. wrote:
    > Dnia Fri, 15 Jul 2011 23:09:02 +0200, Stefan Behnel napisał(a):
    > [...]
    >>> array[count++]=value;
    >>>
    >>> or the more direct pointer management:
    >>> *ptr++=value;

    >>
    >> More direct, sure. But readable? Well, only when you know what this
    >> specific pattern does. If you have to think about it, it may end up hurting
    >> your eyes before you figure it out.

    >
    > Oh, come on. I don't say the post- and pre-incrementing is
    > good or bad, but please don't exagerate.
    >
    > Almost any other construction is unreadable to people, who
    > don't know this construction, eg. a==1, a+=1
    > may be completely senseless to mathematicians.


    No construction is truly intuitive and immediately understandable to everyone,
    but there are constructions that are less easy to understand than others. a==1
    and a+=1 both have few "moving parts" that you have to learn, and they combine
    with other constructions fairly straightforwardly. *ptr++=value has several
    moving parts, each of which are understandable separately, but understanding
    their separate functions does not give immediate understanding of their combined
    meaning. You not only have to learn the meaning of each component, you have to
    separately learn how they combine.

    --
    Robert Kern

    "I have come to believe that the whole world is an enigma, a harmless enigma
    that is made terrible by our own mad attempt to interpret it as though it had
    an underlying truth."
    -- Umberto Eco
     
    Robert Kern, Jul 16, 2011
    #4
    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. Jakob Bieling

    Q: operator void* or operator bool?

    Jakob Bieling, Mar 5, 2004, in forum: C++
    Replies:
    2
    Views:
    584
    Rob Williscroft
    Mar 5, 2004
  2. John Smith
    Replies:
    2
    Views:
    423
    Ivan Vecerina
    Oct 6, 2004
  3. Alex Vinokur
    Replies:
    4
    Views:
    3,051
    Peter Koch Larsen
    Nov 26, 2004
  4. Alex Vinokur
    Replies:
    3
    Views:
    5,029
    Jeff Schwab
    Mar 20, 2005
  5. Tim Clacy
    Replies:
    15
    Views:
    2,689
    Kanenas
    May 30, 2005
Loading...

Share This Page