views:

119

answers:

8

It is my understanding that, the conditional operator ( condition ? consequence : alternative ) is often referred to as both the “tertiary operator” and the “ternary operator”.

What is the difference between these terms?

+4  A: 

I've never heard about the "tertiary" operator, only "ternary". My guess is it's an abuse of language.

fbonnet
+1  A: 

One of them is incorrect. Ternary comes from the fact, there are three arguments used (binary operators use two arguments). Tertiary comes from third and is incorrect.

Mchl
+3  A: 

The Tertiary is a geologic period 65 million to 1.8 million years ago.

Seriously, "tertiary" means "of third rank", not necessarily in value, but maybe sequentially, as in primary, secondary and tertiary education. You want a term that relates to involving three arguments, and that's "ternary", and goes with "binary" and "unary".

chryss
It's like Wikipedia. First I am reading about Ternary, then suddenly I am learning about geological periods.
Jeff Davis
+8  A: 

It should be called the "conditional operator". "Ternary operator" means it accepts three operands. Since it is the only common operator that does that, it's sometimes called "the" ternary operator. The fact that there's only one is a coincidence. "Tertiary operator" is even more wrong. It means something like "third most important operator".

recursive
A: 

From Wikipedia:

In computer science a ternary operator (sometimes incorrectly called a tertiary operator) is an operator that takes three arguments.

I've never heard it called the "tertiary operator." So, the difference is, using one will make you look like a newbie. I guess.

Adam Backstrom
A: 

one is correct and one is incorrect

a ternary operator is an operator with 3 inputs eg a ? b : c , it has arity of 3

a tertiary operator would just mean the 3rd operator? this doesn't really have any significance

jk
+3  A: 

"Conditional operator" is the correct name. It is a ternary operator, the only one in many languages, which is why it is sometimes referred to as the ternary operator.

I don't think it's correct to call it "tertiary." That word means something like "the third option," somewhat like primary and secondary would be first and second.

Bill the Lizard
supercat
@supercat: Range checking is a good example. I don't know how many times I've wanted to write `if( a < b < c )...` I can't think of any problem that requires a ternary operator that can't be solved by writing a function though, so that's probably why you don't see more of them.
Bill the Lizard
@Bill the Lizard: Indeed, the ternary operator in C is just about the only useful thing I can think of that an operator can do which a function can't, at least not without a style of lambda-expression support that AFAIK no language provides (it might be useful to allow a function to accept as its argument a delegate which will return a specified value; the argument to such a function will only be evaluated if the function calls the delegate).
supercat
A: 

If it is called tertiary, it is erroneously so.

Tertiary means "third [level]" whereas ternary means "having three parts." These are not programming definitions -- just what the words mean.

Clearly, the operator is ternary (1 ? 2 : 3;), but tertiary makes no sense in this case.

Jay