KermMartian wrote:
Right, because it's typically unskilled programmers that are looking at advanced code, and especially unskilled programmers that don't have a book or tutorial next to them, because they have no interest in reading someone else's code to learn the language. Please. If you don't understand ?:, you can easily Google "C ? operator" or "C++ ? operator". Third sentence of the Wiki article that is the first result:
Quote:
When not overloaded, for the operators &&, ||, ?: (the Ternary operator), and , (the comma operator), there is a sequence point after the evaluation of the first operand.
And of course, the Ternary operator text is linked to a handy-dandy article about the operator.
Likewise, if you are unable to understand Python ternaries then you are a complete moron who has no business using a computer.
See? That's how useless your response was.
swivelgames wrote:
Once you know how to use it, the ?: ternary is definitely more logical then Python's then/if ternaries.
I disagree. Python's ternaries agree with other Python one-liners like array and dictionary generators:
Code: x=(n for n in foo if bar(n)) # x is an iterator
x = [n for n in foo if bar(n)] # x is a list
x = dict((k,k+1) for k in range(10)) # x is a dict
Quote:
Any programmer will be able to read "If THIS then THAT else OTHER" easier then "THAT if THIS else OTHER". That's just... awkward and untraditional conditional structure.
Only because you are already familiar with the ?: ternary.
Quote:
Besides, how hard is it to memorize how to write a ?: ternary?
).
That is a non-argument. I could just as easily say "Java? Seriously? How hard is it to just memorize JVM bytecode?"
Quote:
As a traditional programmer, it should be pretty easy to understand a ternary like this:
Quote:
x = (y==1) ? 3 : (y==-1) ? 2 : 1;
Rather then one like this: Quote:
x = 3 if (y == 1) else 2 if (y == -1) else 1
True, but Python isn't trying to be a C replacement - never has, never will be. Thus, what a "traditional programmer" expects is entirely irrelevant.
Quote:
You shouldn't sacrifice readability or tradition for something so unorthodox. "X equals 3 if Y equals 1, otherwise X equals 2 if Y equals negative 1, otherwise X equals 1" is much harder to read in code to a programmer, then "If Y equals 1, then X equals 3. Else if Y equals negative 1, then X equals 2. Else X equals 1".
No it isn't, it isn't harder at all - it reads very naturally and logically.
Quote:
You can't exactly break up then/if ternaries very easily, either. At least, not in a way that can be easily readable (as it relates to other conditionals.
And I counter that that is a GOOD thing. Nested ternaries are *bad*. If you are splitting it over multiple lines, then you shouldn't be using a ternary in the first place.