So... which is it?

As of July 2006, Google shows over 420k possible hits for the search term ternary operator. The first 20 hits include Wikipedia: ternary operator, and links to the official documentation for several languages (PHP, Java, and Python). Perl's own perlop also refers to the ?: operator as a "ternary operator". Wikipedia tells us that the term 'ternary operator' comes from the mathematical term 'ternary operation'. It's sometimes (according to wikipedia) called a tertiary operator, as it takes three arguments.

If you google for the search term trinary operator, you get (as of today) almost 28k hits, along with the familiar Google helper, "Did you mean: ternary operator." There are no Wikipedia hits for it, though there is a wikipedia hit for 'trinary' (the word, not an operator).

Given that there are nearly 28 thousand references to "trinary operator", versus 420k hits for 'ternary operator' turned up by Google, it's obvious that there is a significant propensity for name confusion. Here at the monastery we occasionally see posts about the ternary operator, where the node's author mistakenly calls it the trinary operator. Occasionally such nodes get retitled as a hazard to navigation and search-ability.

The purpose of this meditation is to clarify which term is correct in the context of Perl's ?: operator, as well as to provide a quick-reference node title that will be found anytime someone searches for either ternary or trinary here at the Monastery. This should serve as a pre-emptive aid to navigation, reducing the temptation to retitle 'trinary' nodes. I post this as a Meditation, despite its strong "PerlMonks Discussion" flavor because I believe the discussion has merit beyond the scope of only pertaining to the Monastery's goings-on.

So, what's the verdict? Perl's POD, Google's number of hits returned, Wikipedia's blurbs, and the documentation for other popular languages all seem to agree that with regards to the ?: operator, it's called a ternary operator

From a research perspective, those searching for information on the Ternary operator, here at the Monastery, as well as on Google, would probably find additional beneficial posts by searching for the "misspelled" term, Trinary. But the existence of nodes with both 'spellings', and the associated ambiguity shouldn't detract from the fact that Perl has a ternary operator, not a trinary operator.

...or maybe I'm just confused, this is a meditation, after all. ;)


Dave


In reply to Ternary operator (there's no Trinary operator ) by davido

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.