• 516052 (unregistered)

    So basically if 0 than one color, else another. Honestly this looks to me like something that could make perfect sense in any number of contexts. And the color being the same could just be that at some point someone decided that the colors should not be different after all but wanted to keep the code in there just in case people changed their mind.

  • Malte (unregistered)

    PHP has = for assignments and == for comparisons, right? Two major problems in one line.

  • L (unregistered)
    $bgc = $tno ? '#FFFFFF' : '#FFFFFF'; // UUUUUUUUUUUUUUU

    fixed

  • Hmmmm 🤨 (unregistered)

    It's a powerful signal. It's saying, "no matter what you think about tno, I'm setting bgc to #FFFFFF!" Who knows what sort of hijinx the next programmer might try to pull off if that line weren't in there, keeping everyone in line.

  • ScottTheAccountant (unregistered)

    Huh. I've seen that exact same pattern in some of my hacky javascript from back in the day.

  • Steve (not that one) (unregistered)

    Reminds me of a student who kept writing statements like (in FORTRAN): A = A When asked why the response was "I want to make sure it takes."

  • Jonathan (unregistered) in reply to Malte

    It's an assignment statement. "?:" is a ternary operator, as the punny title points towards.

  • (nodebb) in reply to 516052

    So basically if 0 than one color, else another. Honestly this looks to me like something that could make perfect sense in any number of contexts. And the color being the same could just be that at some point someone decided that the colors should not be different after all but wanted to keep the code in there just in case people changed their mind.

    Yes, but ....

    In short, the ternary shouldn't be here, not just because both branches are the same thing, but because there shouldn't logically be any branching at all.

    As Remy points out, there shouldn't be any branching at all. No decision making, just set the color! "... in case people change[d] their mind" they could put in a new decision. My guess is, ChangeMyMind guy will probably want something other than white, anyway.

  • Argle (unregistered)

    I seem to recall a quote on this very site about needing a barrier to entry before using any programming language. And here we are with the language with no barrier to entry.

  • 516052 (unregistered)

    As Remy points out, there shouldn't be any branching at all. No decision making, just set the color! "... in case people change[d] their mind" they could put in a new decision. My guess is, ChangeMyMind guy will probably want something other than white, anyway.

    I think he meant to say that since the tern does nothing therefore it should not be there. Where as I pointed out that we only know it does nothing at this point in time and that there could in fact have been a point where it did before the code was disabled.

  • Malte (unregistered) in reply to Jonathan

    Right. I did read the code wrong, my brain inserted brackets like

    ($bgc = $tno) ? '#FFFFFF' : '#FFFFFF';

  • Darren (unregistered)

    This looks very much like code that comes from a developer who just knows that at some point in the future their manager is going to want to be able to have a different background colour. It's code that's written from experience of having to deal with ever-changing specifications and manglement instructions.

  • (nodebb) in reply to Darren

    This looks very much like code that comes from a developer who just knows that at some point in the future their manager is going to want to be able to have a different background colour. It's code that's written from experience of having to deal with ever-changing specifications and manglement instructions.

    We don't know. It could be "predictive coding" as you suggest, or it could be "we don't want different colors anymore". In either case this line should be commented out, with a hint of the reason. It doesn't need to be there because it does nothing, so why bother including it?

    ` // Just in case they decide to change colors:

    ` // We aren't changing colors anymore:

  • MangusPI (unregistered) in reply to Argle

    I seem to recall a quote on this very site about needing a barrier to entry before using any programming language. And here we are with the language with no barrier to entry.

    While I understand these feelings, I think it's very important to think things through, as we need to be real careful about pushing for any kind of regulation for what one can do on their own computer. We already have governments trying push age restrictions into operating systems, which is bad enough. These sort of ideals are very much contrary to free and open computing and getting to this sort of regulation can very easily lead down a dystopian path that I don't think any of us really want.

  • Jonathan (unregistered) in reply to Malte

    Yeah, that's too easy to do. I think the fact that that would leave an expression that calculated a value and then did nothing with it pushed me towards the (assumedly) intended meaning.

    That said, if I encountered the fragment

    $bgc == $tno ? '#FFFFFF' : '#FFFFFF';

    I'd have no idea if it needs parens to be interpreted the way you wrote it. I like ternary ?: - it's concise and gets the job done. But oh my the precedence issues it raises!

  • Tomman (unregistered) in reply to Jonathan

    "I'd have no idea if it needs parens to be interpreted the way you wrote it. I like ternary ?: - it's concise and gets the job done. But oh my the precedence issues it raises!"

    Yes, that can be a real gotcha. While most C-ish languages evaluate ?: right to left, like (C1 ? V1 : (C2 ? V2 : V3)), PHP (IIRC, fixed in 8.x) went left to right, like ((C1 ? V1 : V2) ? V3 : V4) throwing off anyone used to any other language (C/C++/Java/C#/JavaScript/Switft/Perl/Ruby/etc) which adheres to the former.

  • 516052 (unregistered) in reply to MangusPI

    I don't want regulations on what you can do in your private life. But I do want restrictions on what you can do commercially. Nobody should be regulating my right to sketch buildings in a notebook for fun. But if I want those things built in stone and people living in them I sure as hell should be forced to get a certification in architecture. Same here.

    And it does not have to be prohibitively complex either. We can have tiers. Your website assembling script monkey needs a different level of permit than the guy building software for an airplane or worse a bank. But we need SOMETHING.

  • Jonathan (unregistered) in reply to Tomman

    Oh, I think I remember seeing people complain about PHP acting that way. I wonder if that's why I associate ternary ?: with precedence issues? Sometime with coding I don't remember the specific accident, all I know is that I have a scar in a vague area.

  • erffrfez (unregistered)
    Comment held for moderation.
  • Tomman (unregistered) in reply to Jonathan

    I remember reading of it over a decade ago at https://web.archive.org/web/20180102221920/http://phpsadness.com/sad/30 (using the Wayback Machine as the original site appears to be gone), among other places where it was pretty routinely talked about it, as it seem to trip up a lot of people.

Leave a comment on “Terning White as a (Style)Sheet”

Log In or post as a guest

Replying to comment #706303:

« Return to Article