• doug (unregistered)

    initialTab = 0; if (isNaN(initialTab)) { initialTab = 0; }

    is probably a merge error.

  • chaosprime (unregistered)

    Today's WTF: reading thedailywtf.com talking about the conditional operator as "the ternary operator".

    Any operator that takes three arguments is a ternary operator.

  • nmare (unregistered) in reply to chaosprime
    chaosprime:
    Today's WTF: reading thedailywtf.com talking about the conditional operator as "the ternary operator".

    Any operator that takes three arguments is a ternary operator.

    from wikipedia:

    Many programming languages that use C-like syntax feature a ternary operator, ?:, which defines a conditional expression. Since this operator is often the only existing ternary operator in the language, it is sometimes simply referred to as "the ternary operator". In some languages, this operator is referred to as "the conditional operator".

  • (cs) in reply to chaosprime
    chaosprime:
    Today's WTF: reading thedailywtf.com talking about the conditional operator as "the ternary operator".

    Any operator that takes three arguments is a ternary operator.

    We all already know this. But since most commonly used languages only have at most one, then it is THE one.

  • ForFoxSake (unregistered)

    I'm always amazed that in most threads you can find brilliant developers and painful idiots but no one in between.

  • (cs) in reply to DCRoss
    DCRoss:
    Algeria Bulgaria Cambodia Dominica Egypt France the Gambia! Aitch-teem-ell, zero. Japan Kazakhstan, Lybia Emm-el, HTML! Norway, Oman, Shell exec, Qatar Russia mysql Turkey Uruguay Vietnam. Handle the error! Yemen Zimbabwe!
    No, no, no, no, no, no! Countries are sung to the tune of the Mexican Hat Dance!
  • (cs) in reply to ForFoxSake
    ForFoxSake:
    I'm always amazed that in most threads you can find brilliant developers and painful idiots but no one in between.

    Well, I just found you to be thoroughly mediocre. Glad I could help.

  • jay (unregistered) in reply to chaosprime
    chaosprime:
    Today's WTF: reading thedailywtf.com talking about the conditional operator as "the ternary operator".

    Any operator that takes three arguments is a ternary operator.

    Any prime number that is divisible by 2 is an "even prime". However, I don't think it creates a great deal of ambiguity to talk about "the even prime", because there is only one.

  • jay (unregistered)

    My humble opinion on the "?:" operator (I'll avoid calling it the ternary operator so I don't offend an earlier poster):

    It's handy when you would otherwise have had to declare a temporary variable, for example, if you are passing a value to a function:

    processAccount(acctNum, balance<0 || monthTxCount>20 ? State.WATCH : State.NORMAL);
    

    Also if it allows you to combine a declaration with an assignment:

    AcctState acctState=balance<0 || monthTxCount>20 ? State.WATCH : State.NORMAL;
    

    Sure, I could have declared the variable and then had an IF statement to assign the value, but that would turn one line into five.

    And/or if the destination involves a complex expression:

    getCustomer(acctNumber).acctState[periodEnd+1)=balance<0 || monthTxCount>20 ? State.WATCH : State.NORMAL;
    

    Sure, I could do that one with an IF, but then both ends of the IF would have to repeat that whole complex expression describing where the value goes, which means that a reader would have to stop and figure out that the expressions are the same in both cases. (And of course, sooner or later someone would come along and change one but not realize he needs to also change the other.)

    I avoid using it when any of the three expressions pass a certain threshold of complexity, because then it just gets hard to read.

    I never, ever nest them. That's hard to read.

    And the absolute worst use of a ?: I've ever seen -- stumbled across this one a couple of months ago:

    boolean status = getStatus() ? true : false;
    
  • jay (unregistered) in reply to chaosprime
    chaosprime:
    Today's WTF: reading thedailywtf.com talking about the conditional operator as "the ternary operator".

    Any operator that takes three arguments is a ternary operator.

    We call the receptionist at our company the "unary operator". Because when she forwards a phone call to you, if you give her more than one argument, she just hangs up on you.

  • jay (unregistered) in reply to ¯\(°_o)/¯ I DUNNO LOL
    ¯\(°_o)/¯ I DUNNO LOL:
    When your only tool is a shell_exec, every problem looks like a shell command.

    And when your only tool is PHP, every problem looks like an opportunity to shoot yourself in the foot.

    When your only tool is PHP, you soon want to shoot yourself in the head.

  • (cs) in reply to da Doctah
    da Doctah:
    DCRoss:
    Algeria Bulgaria Cambodia Dominica Egypt France the Gambia! Aitch-teem-ell, zero. Japan Kazakhstan, Lybia Emm-el, HTML! Norway, Oman, Shell exec, Qatar Russia mysql Turkey Uruguay Vietnam. Handle the error! Yemen Zimbabwe!
    No, no, no, no, no, no! Countries are sung to the tune of the Mexican Hat Dance!

    Second time I've posted this on this site:

    United States, Canada, Mexico, Panama...

  • epv (unregistered) in reply to Ken B

    Why not just use if/else statements? There is nothing wrong with them. Just because it compiles doesn't make it a good idea.

  • Hotline for ternary abuse (unregistered) in reply to jay
    jay:
    My humble opinion on the "?:" operator (I'll avoid calling it the ternary operator so I don't offend an earlier poster):

    It's handy when you would otherwise have had to declare a temporary variable, for example, if you are passing a value to a function:

    processAccount(acctNum, balance<0 || monthTxCount>20 ? State.WATCH : State.NORMAL);
    

    Also if it allows you to combine a declaration with an assignment:

    AcctState acctState=balance<0 || monthTxCount>20 ? State.WATCH : State.NORMAL;
    

    Sure, I could have declared the variable and then had an IF statement to assign the value, but that would turn one line into five.

    And/or if the destination involves a complex expression:

    getCustomer(acctNumber).acctState[periodEnd+1)=balance<0 || monthTxCount>20 ? State.WATCH : State.NORMAL;
    

    Sure, I could do that one with an IF, but then both ends of the IF would have to repeat that whole complex expression describing where the value goes, which means that a reader would have to stop and figure out that the expressions are the same in both cases. (And of course, sooner or later someone would come along and change one but not realize he needs to also change the other.)

    I avoid using it when any of the three expressions pass a certain threshold of complexity, because then it just gets hard to read.

    I never, ever nest them. That's hard to read.

    And the absolute worst use of a ?: I've ever seen -- stumbled across this one a couple of months ago:

    boolean status = getStatus() ? true : false;
    

    We use a convention where ternaries select between to choices of data rather than code (that would be a job for if).

    That said a properly formatted cascading ternary makes for a nice compact look-up table:

             # Condition            # Value
    
    my $post = $comment_number == 1 ? 'Frist psot 111 eleventy-one'
    
             : $comment_number == 2 ? 'The Real WTF'
    
             : $comment_number == 3 ? 'Not really a WTF'
    
             : $comment_number == 4 ? 'FILE_NOT_FOUND'
    
             : $comment_number == 5 ? 'Brillant'
    
             : $comment_number == 6 ? 'Where\'s the wooden table'
    
             : $comment_number == 7 ? 'Needs more XML'
    
             :                        "This wouldn't have happened if they had used $my_favourite_language in the first place" # (default)
    
    ;

    (Thanks to ChrisF)

  • (cs) in reply to epv
    epv:
    Why not just use if/else statements? There is nothing wrong with them. Just because it compiles doesn't make it a good idea.

    Because banning a language construct just because bottom of the barrel idiots use it wrong, is both asinine and counter-constructive. Sure, you can ban it and solve a few problems. Now deal with the other 99% of stupidity these people produce because they have no affinity or feeling for writing good, clean code.

    Meanwhile the loss of all the good use cases get under the skin of your talented and actually qualified developers. And then, before you know it someone tries to be clever about it. And then "life, uh... finds a way":

    public static class Ternary
    {
      public static T Conditional<T>(bool cond, Func<T> pos, Func<T> neg)
      {
        if ( cond ) { return pos(); }
        return neg();
      }
    }
    
    return Ternary.Conditional( foo, ()=> "bar", ()=> "baz" );
  • (cs) in reply to Ragnax
    Ragnax:
    Because banning a language construct just because bottom of the barrel idiots use it wrong, is both asinine and counter-constructive. Sure, you can ban it and solve a few problems. Now deal with the other 99% of stupidity these people produce because they have no affinity or feeling for writing good, clean code.

    Yeah, you completely misunderstood his post.

  • lolatu (unregistered) in reply to A
    A:
    Yes, they really should have been more careful and gone for something like:

    initialTab = 0; while (isNaN(initialTab)) { initialTab = 0; }

    I was just going to post that myself. Defensive programming is important!
  • (cs) in reply to lolatu
    lolatu:
    A:
    Yes, they really should have been more careful and gone for something like:

    initialTab = 0; while (isNaN(initialTab)) { initialTab = 0; }

    I was just going to post that myself. Defensive programming is important!
    int attempts = 0;
    initialTab = 0; 
    while (isNaN(initialTab) || attempts > 10000) { initialTab = 0; attempts++; }
    
  • nmare (unregistered) in reply to Hotline for ternary abuse
    Hotline for ternary abuse:
    We use a convention where ternaries select between to choices of data rather than code (that would be a job for if).

    That said a properly formatted cascading ternary makes for a nice compact look-up table:

             # Condition            # Value
    
    my $post = $comment_number == 1 ? 'Frist psot 111 eleventy-one'
    
             : $comment_number == 2 ? 'The Real WTF'
    
             : $comment_number == 3 ? 'Not really a WTF'
    
             : $comment_number == 4 ? 'FILE_NOT_FOUND'
    
             : $comment_number == 5 ? 'Brillant'
    
             : $comment_number == 6 ? 'Where\'s the wooden table'
    
             : $comment_number == 7 ? 'Needs more XML'
    
             :                        "This wouldn't have happened if they had used $my_favourite_language in the first place" # (default)
    
    ;

    Ok, But why not use a select case statement? Why people need so much to use a "?:" everywhere? it make you feel 1337?

  • (cs)

    Nested ternary operators are OK as long as 1. code is formatted property 2. you shouldn't be using a switch instead and 3. you're not using PHP. Which, thankfully, this person isn't. http://phpsadness.com/sad/30

  • Benjamin (unregistered) in reply to ForFoxSake
    ForFoxSake:
    I'm always amazed that in most threads you can find brilliant developers and painful idiots but no one in between.

    That's because everyone in between has the good sense to shut up.

  • techo's R Us (unregistered)
    for open bra-a-a-acket var h t m          # When Britain first at heav'ns command
    l i-i-i-i-i-n data open pa-arenthesis     # Aroze from out the azure main
    quote h t m l quote close pa-are-enthesis # Arose, Arose, Arose from out the azure main
    close bracket dollar, open bracket data	  # this was their calling, the charter of the land
    open pare-e-e-enthesis quote htm          # and guardian angels sang this strain
    l quote clo-ose pare-enthesis open        # "Rule Britannia, Britannia rule the waves
    parenthe-e-e-sis h t ml                   # Britons never, never, never shall be slaves
    close parenthe-sis open parenthesis       # "Rule Britannia, Britannia rule the waves
    zero clo-o-o-se pare-enthesis             # Britons never, never, never shall be slaves
    

    We could make it fit to anything. I rememebr seeing a show where people were given a random book and had to sing excerpts to different tunes.

  • Rubbard K (unregistered)

    I use ?: when I want an expression's value to be conditional, and if-else otherwise. I avoid nesting them if I need to use parentheses or both branches need to be complex. I think this is excessively verbose:

    if(bar)
     x = foo;
    else
     x = baz;
    

    and should be replaced with

    x = bar ? foo : baz;

    and likewise I'll write

    x = f()? foo : g()? bar : baz;

    instead of

    if(f())
     x = foo;
    else if(g())
     x = bar;
    else
     x = baz;
    
  • fritz with sauce (unregistered) in reply to jay
    jay:
    My humble opinion on the "?:" operator (I'll avoid calling it the ternary operator so I don't offend an earlier poster):

    It's handy when you would otherwise have had to declare a temporary variable, for example, if you are passing a value to a function:

    processAccount(acctNum, balance<0 || monthTxCount>20 ? State.WATCH : State.NORMAL);
    

    Also if it allows you to combine a declaration with an assignment:

    AcctState acctState=balance<0 || monthTxCount>20 ? State.WATCH : State.NORMAL;
    

    Sure, I could have declared the variable and then had an IF statement to assign the value, but that would turn one line into five.

    And/or if the destination involves a complex expression:

    getCustomer(acctNumber).acctState[periodEnd+1)=balance<0 || monthTxCount>20 ? State.WATCH : State.NORMAL;
    

    Sure, I could do that one with an IF, but then both ends of the IF would have to repeat that whole complex expression describing where the value goes, which means that a reader would have to stop and figure out that the expressions are the same in both cases. (And of course, sooner or later someone would come along and change one but not realize he needs to also change the other.)

    I avoid using it when any of the three expressions pass a certain threshold of complexity, because then it just gets hard to read.

    I never, ever nest them. That's hard to read.

    And the absolute worst use of a ?: I've ever seen -- stumbled across this one a couple of months ago:

    boolean status = getStatus() ? true : false;
    
    or
    printf("The process has completed with %d error%s\n", numErrors, ((numErrors!=1)?:"s":"");
    
  • fritz with sauce (unregistered) in reply to jay
    jay:
    chaosprime:
    Today's WTF: reading thedailywtf.com talking about the conditional operator as "the ternary operator".

    Any operator that takes three arguments is a ternary operator.

    We call the receptionist at our company the "unary operator". Because when she forwards a phone call to you, if you give her more than one argument, she just hangs up on you.

    we call ours the urinary operator

  • (cs)

    hmmm (not my code)

    Public Function getFinanceCredit() As Money
    	Return (If(isEdited(), (If((Not usePercentage()), editedFixedAmount, (If((percentageOfBasis Is Nothing), NullMoney.NULL_AMOUNT, basis.multiply(percentageOfBasis))))), NullMoney.NULL_AMOUNT))
    End Function
    
  • Geoff (unregistered) in reply to nmare
    nmare:
    Hotline for ternary abuse:
    We use a convention where ternaries select between to choices of data rather than code (that would be a job for if).

    That said a properly formatted cascading ternary makes for a nice compact look-up table:

             # Condition            # Value
    
    my $post = $comment_number == 1 ? 'Frist psot 111 eleventy-one'
    
             : $comment_number == 2 ? 'The Real WTF'
    
             : $comment_number == 3 ? 'Not really a WTF'
    
             : $comment_number == 4 ? 'FILE_NOT_FOUND'
    
             : $comment_number == 5 ? 'Brillant'
    
             : $comment_number == 6 ? 'Where\'s the wooden table'
    
             : $comment_number == 7 ? 'Needs more XML'
    
             :                        "This wouldn't have happened if they had used $my_favourite_language in the first place" # (default)
    
    ;

    Ok, But why not use a select case statement? Why people need so much to use a "?:" everywhere? it make you feel 1337?

    Because Java (for example) is sometimes a pain when you are trying to assign to a final field, and conditionals/ternaries (nicely formatted if nested) fit the bill.

  • SkUrRiEr (unregistered) in reply to TheIrritainer
    TheIrritainer:
    $isFrist = (is_null($isFrist)) ? 0 : $isFrist;

    I had a colleague who used that anti-pattern. After carefully and methodically annihilating it from the code base, seeing it again MAKES ME WANT TO CLAW MY EYES OUT!!!!!!

    Thanks, hope you have a nice day!

  • (cs) in reply to jay
    jay:
    And the absolute worst use of a ?: I've ever seen -- stumbled across this one a couple of months ago:
    boolean status = getStatus() ? true : false;
    

    I see your worst one, and I'll raise you one I saw nearly twenty years ago...

    if( some_condition )
      (condition2) ? variable = value : 0;
    else
      something_else;
  • gallier2 (unregistered) in reply to Steve The Cynic

    [quote user="Steve The Cynic"]

    if( isEdited() )
    {
      if( !usePercentage() )
        return editedFixedAmount;
      else if( percentageOfBasis == null )
        return NullMoney.NULL_AMOUNT;
      else
        return basis.multiply(percentageOfBasis);
    }
    else
      return NullMoney.NULL_AMOUNT;
    [/quote]

    Or alternatively, in English-like: [quote]If the thingy was edited, then use the percentage times the basis if we are using a percentage and one is available, or if we are not using a percentage, use the fixed amount. If none of the above conditions are met, use the null amount.[/quote] In general, I'd prefer to invert the is-null test so that the positive "use-something" conditions are clumped together, and I'd prefer a function "useFixedAmount()" that is equivalent to "!userPercentage()" so that the test looks more related to the code in the branches, but it's reasonably clear. [quote]

    if( isEdited() )
    {
    if( useFixedAmount() )
    return editedFixedAmount;
    else if( percentageOfBasis != null )
    return basis.multiply(percentageOfBasis);
    else
    return NullMoney.NULL_AMOUNT;
    }
    else
    return NullMoney.NULL_AMOUNT;
    [/quote] Better?[/quote]

    Even better, thanks to the return, there's no need for else clauses.

    if( isEdited() )
    {
      if( useFixedAmount() )
        return editedFixedAmount;
    
      if( percentageOfBasis != null )
        return basis.multiply(percentageOfBasis);
    }
    return NullMoney.NULL_AMOUNT;
    
  • (cs) in reply to techo's R Us
    techo's R Us:
    for open bra-a-a-acket var h t m          # When Britain first at heav'ns command
    l i-i-i-i-i-n data open pa-arenthesis     # Aroze from out the azure main
    quote h t m l quote close pa-are-enthesis # Arose, Arose, Arose from out the azure main
    close bracket dollar, open bracket data	  # this was their calling, the charter of the land
    open pare-e-e-enthesis quote htm          # and guardian angels sang this strain
    l quote clo-ose pare-enthesis open        # "Rule Britannia, Britannia rule the waves
    parenthe-e-e-sis h t ml                   # Britons never, never, never shall be slaves
    close parenthe-sis open parenthesis       # "Rule Britannia, Britannia rule the waves
    zero clo-o-o-se pare-enthesis             # Britons never, never, never shall be slaves
    
    We could make it fit to anything. I rememebr [sic] seeing a show where people were given a random book and had to sing excerpts to different tunes.

    Yes... but the point is... ANYTHING can be MADE to fit ANYTHING.

    That doesn't mean that it naturally "fits", which is what is meant when you say "oh look... these words fit to that tune".

    If you say that about something that doesn't naturally fit, but which can be made to do so in a clunky and unsatisfactory way, then you're saying nothing of value, and you're sounding like an idiot while you do it.

  • qbolec (unregistered) in reply to eViLegion

    You can find it easier to fit your speach into a tune using https://play.google.com/store/apps/details?id=com.smule.autorap&hl=pl

  • Yazeran (unregistered) in reply to jay
    jay:
    chaosprime:
    Today's WTF: reading thedailywtf.com talking about the conditional operator as "the ternary operator".

    Any operator that takes three arguments is a ternary operator.

    Any prime number that is divisible by 2 is an "even prime". However, I don't think it creates a great deal of ambiguity to talk about "the even prime", because there is only one.

    Well I gyuess I'm in a somewhat whacked state today, as I read the shell line in the article as if ($horror = ...
    instead of if ($error = ... Which seemed somehow more correct.

    And now I read your line as "the evil prime"....

    I guess I need more coffee

    Yazeran

    Plan: To go to mars one day with a hammer.

  • Neil (unregistered)

    The best thing about ternary expressions is that you've got so many ways of writing them. For example you might hate using the ! operator in a ternary condition, which results in code like this:

    public Money getFinanceCredit() {
    return isEdited() ? usePercentage() ? percentageOfBasis ? basis.multiply(percentageOfBasis)
    : NullMoney.NULL_AMOUNT
    : editedFixedAmount
    : NullMoney.NULL_AMOUNT;
    }
    or alternatively you might hate nesting ? : between ? and :, which results in code like this:
    public Money getFinanceCredit() {
    return !isEdited() ? NullMoney.NULL_AMOUNT :
    !usePercentage() ? editedFixedAmount :
    !percentageOfBasis ? NullMoney.NULL_AMOUNT : basis.multiply(percentageOfBasis);
    }

  • Rob G (unregistered) in reply to Ramchandra Apte

    I really wish you'd never mentioned this!

  • not else (unregistered)

    I'm a fan of Edsger Dijkstra and "grew up" on structured programming. By using if blocks the steps are clearly defined, reducing the chance of inserting operations incorrectly between the return statements.

    result = NullMoney.NULL_AMOUNT
    if isEdited()
      if useFixedAmount()
        result = editedFixedAmount
      elsif percentageOfBasis != null
        result = basis.multiply( percentageOfBasis )
      endif
    endif
    return result
    
  • nmare (unregistered) in reply to not else
    not else:
    I'm a fan of Edsger Dijkstra and "grew up" on structured programming. By using if blocks the steps are clearly defined, reducing the chance of inserting operations incorrectly between the return statements.
    result = NullMoney.NULL_AMOUNT
    if isEdited()
      if useFixedAmount()
        result = editedFixedAmount
      elsif percentageOfBasis != null
        result = basis.multiply( percentageOfBasis )
      endif
    endif
    return result
    

    This is exacly why you should not use a "?:" in a normal situation! Code is harder to maintain.

  • jay (unregistered) in reply to nmare
    nmare:
    Hotline for ternary abuse:
    We use a convention where ternaries select between to choices of data rather than code (that would be a job for if).

    That said a properly formatted cascading ternary makes for a nice compact look-up table:

             # Condition            # Value
    
    my $post = $comment_number == 1 ? 'Frist psot 111 eleventy-one'
    
             : $comment_number == 2 ? 'The Real WTF'
    
             : $comment_number == 3 ? 'Not really a WTF'
    
             : $comment_number == 4 ? 'FILE_NOT_FOUND'
    
             : $comment_number == 5 ? 'Brillant'
    
             : $comment_number == 6 ? 'Where\'s the wooden table'
    
             : $comment_number == 7 ? 'Needs more XML'
    
             :                        "This wouldn't have happened if they had used $my_favourite_language in the first place" # (default)
    
    ;

    Ok, But why not use a select case statement? Why people need so much to use a "?:" everywhere? it make you feel 1337?

    Or a nested IF? What's the advantage of the ?: there?

  • (cs) in reply to jay
    jay:
    Or a nested IF? What's the advantage of the ?: there?

    You wouldn't happen to use SFDC's Apex, would you?

  • Muzer (unregistered)

    Auld Lang Syne (see page source code/comments) definitely works a lot better for me - I can't get Rule Britannia to fit at all (verse or chorus).

  • Not Safe for Whales (unregistered) in reply to Hotline for ternary abuse
    Hotline for ternary abuse:
    We use a convention where ternaries select between to choices of data rather than code (that would be a job for if).

    That said a properly formatted cascading ternary makes for a nice compact look-up table:

             # Condition            # Value
    
    my $post = $comment_number == 1 ? 'Frist psot 111 eleventy-one'
    
             : $comment_number == 2 ? 'The Real WTF'
    
             : $comment_number == 3 ? 'Not really a WTF'
    
             : $comment_number == 4 ? 'FILE_NOT_FOUND'
    
             : $comment_number == 5 ? 'Brillant'
    
             : $comment_number == 6 ? 'Where\'s the wooden table'
    
             : $comment_number == 7 ? 'Needs more XML'
    
             :                        "This wouldn't have happened if they had used $my_favourite_language in the first place" # (default)
    
    ;

    (Thanks to ChrisF)

    How dare you!

    You forgot Irish Girl! CAPTCHA = mara

  • Blab (unregistered) in reply to eVil

    Maybe comedy shouldn't be analyzed...

  • The Big Picture Thinker (unregistered)

    There is a well-known bug in the order of operations of PHP ternary operators.

    Always use parentheses for nested ternaries in PHP, or this will happen:

    http://www.phpsadness.com/sad/30

  • stew (unregistered) in reply to Niko
    Niko:
    TRWTF is, as usual, PHP.

    <example of PHP's conditional operator behavior>

    So while technically accurate, I see no actual relevance to the article, as that particular example wasn't written in PHP.

    But we get it: you don't like PHP. A remarkably audacious stance that I'm glad you felt necessary to share.

  • Arancaytar (unregistered)
    This particular line can be sung to the tune of “Rule Britannia”.

    for (var html in data["html"]) $(data["html"][html][0]).html(data["html"][html][1]);

    I'm not sure how the hell you need to pronounce HTML for that to work. Is the dollar silent?

  • Arancaytar (unregistered) in reply to Not Safe for Whales
    Not Safe for Whales:
    Hotline for ternary abuse:
    We use a convention where ternaries select between to choices of data rather than code (that would be a job for if).

    That said a properly formatted cascading ternary makes for a nice compact look-up table:

             # Condition            # Value
    
    my $post = $comment_number == 1 ? 'Frist psot 111 eleventy-one'
    
             : $comment_number == 2 ? 'The Real WTF'
    
             : $comment_number == 3 ? 'Not really a WTF'
    
             : $comment_number == 4 ? 'FILE_NOT_FOUND'
    
             : $comment_number == 5 ? 'Brillant'
    
             : $comment_number == 6 ? 'Where\'s the wooden table'
    
             : $comment_number == 7 ? 'Needs more XML'
    
             :                        "This wouldn't have happened if they had used $my_favourite_language in the first place" # (default)
    
    ;

    (Thanks to ChrisF)

    How dare you!

    You forgot Irish Girl! CAPTCHA = mara

    I was going to suggest switch, but it turns out PHP can't even take advantage of jump tables, and will convert it to chained ifs anyhow.

Leave a comment on “Ternary Over a New Leaf”

Log In or post as a guest

Replying to comment #:

« Return to Article