Page 2 of 2 First 12
  • Jump to page:
    #16
  1. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,616
    Rep Power
    4247
    Originally Posted by ManiacDan
    Wait...lack of the -- and ++ operators makes it more sane?
    Some argue that less is beautiful and since the language has += and -= operators, there is no need for -- and ++, as they can be simulated like this:
    x += 1
    x -= 1

    The nice thing about these operators is that += and -= can be used to increment (or decrement) by any quantity, not just 1 (e.g. x += 5). Their argument is that C (and C derived languages) support both += and ++ operators and second operator is merely a special purpose case of the first. Granted that ++ can be used in the middle of an expression involving other operators, whereas += cannot, but the difference in speed/efficiency isn't that big for an interpreted language. There is one more big reason why python doesn't support ++ which involves references, immutable objects and how the language runtime works, but I'd rather elaborate on that in the python forum if anyone is interested.

    In addition to this, the whole issue of pre-vs-post increment is avoided completely, as are ambiguous expression constructs like the example in the original poster's post. This makes the code simple, readable and unambiguous.

    Python also avoids the ?: operator for reasons of simplicity, which many other languages support. Interestingly, PHP evaluates ?: differently than most other languages, so this is one of those gotchas that bite people when they go between languages.
    Last edited by Scorpions4ever; September 15th, 2012 at 05:43 PM.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  2. #17
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    San Francisco Bay
    Posts
    1,939
    Rep Power
    1313
    Originally Posted by ManiacDan
    Wait...lack of the -- and ++ operators makes it more sane?
    I only have a little bit to add to Scorpions4Ever's post. I agree completely that the lack of these operators promotes readability and simplicity. Another consideration is a deliberate aspect of Python's design that is broader than just the increment/decrement operators, namely that assignment statements do not return values: they are not usable as expressions. (If you're not using their values, "x++" and "++x" are just cryptic alternatives to "x += 1" and thus superfluous.) This has some nice implications: something like
    Code:
    while (x = 1) {
    which is definitely an error in pretty much any language, but will usually parse as valid code, is a syntax error in Python:
    Code:
        while x = 1:
                ^
    SyntaxError: invalid syntax
    Don't get me wrong: I have nothing against languages that decide to make everything an expression, but I also respect Python's stance here. There's no philosophical reason that an assignment should automatically evaluate to something: it is a completely different concept. Assignment is a strictly imperative programming construct, while evaluation is strictly declarative. Python keeps the two separate on the level of statements.

    (Sorry, my purpose wasn't to derail the thread by starting a discussion about Python.)
  4. #18
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    "definitely an error in pretty much any language" j isn't pretty much any language.
    Code:
       while x = 1:
    while (x = 1:)
    Since "x" and "while" are unknown names, j assumes they are verbs of infinite rank,
    = and 1: are known verbs with known ranks.
    The four verbs form a train.
    Since the train has an even number of verbs, the train is a hook, which has implications for data flow.
    But there isn't any data, so j returns the hook rewritten with parentheses to make it a little more obvious that it's a hook.

    Since you've paid attention you probably recognize that the three verbs in parentheses form a train with an odd number of verbs. Right you are! That's a fork, which has implications for data flow.

    In calculus, perhaps advanced, have you ever written
    (f + g)(x)
    (f + g) are three verbs in a row.

    (f + g) x as you've already guessed would be rewritten in algebraic notation as
    f(x) + g(x)

    good.
    Last edited by b49P23TIvg; September 15th, 2012 at 06:37 PM.
    [code]Code tags[/code] are essential for python code and Makefiles!
  6. #19
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0
    seems to be var result = (6 + 5) + (5 + 6);

    since a-- = 6, --a = 5, and so forth
  8. #20
  9. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,866
    Rep Power
    6351
    Originally Posted by wren11
    seems to be var result = (6 + 5) + (5 + 6);

    since a-- = 6, --a = 5, and so forth
    Depends on the language, as we all discussed.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  10. #21
  11. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,616
    Rep Power
    4247
    Originally Posted by ManiacDan
    Depends on the language, as we all discussed.
    Technically, it is not only dependent on the language, it also depends on the compiler and the optimization level settings :). The same C or C++ compiler on the same computer could give you different answers depending on if you tell it to optimize for speed or size or both or no optimizations at all (as the link in the first reply from b49P23TIvg shows)

    Comments on this post

    • ManiacDan agrees
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  12. #22
  13. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,866
    Rep Power
    6351
    Shhh!
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo