• my name (unregistered)

    frist: as it is written, in the null check this.mode is assigned null secnod: mode always evaluates to invalid

  • Zatapatique (unregistered)

    Another WTF: nothing is done with the default value 4. Why don' t they set this.mode to 4 when the input is null?

  • Bogolese (unregistered)

    if (mode == null) { this.mode = mode; return ; }

    ^^^ THAT'S your WTF!!!!! ^^^

  • (nodebb)

    Did they not understand that and is a commutative operation?

    Two points here:

    1. If by "and" here, you meant &&, then I sure as hell hope they didn't understand that it's commutative, because && isn't commutative. Sure, the overall value doesn't depend on the order of the two values, but there's a difference between the behaviour of f(params) && g(params) and g(params) && f(params), so the order matters, and so the programming operation isn't commutative. (Yes, I agree that the fundamental logic operation is commutative, but && does shortcut evaluation, so the programming operation is not.)

    2. The correct thing to complain about is not "commutative" anyway, but rather "associative". All those extra parentheses indicate a failure to understand that the logic operation of && is associative, that is, that (a && b) && c and a && (b && c)and a && b && c are equivalent.

  • Tim Ward (unregistered)

    OK, so I normally say "if you can't remember the operator precedence rules for the language you're using this afternoon, FFS do not look them up, just put the brackets in. Because of the next poor sod who's going to read your code and who also doesn't remember the operator precedence rules."

    But ... surely ... "shortcut logical operators are left associative" applies across all languages, so doesn't need spelling out?

  • Chronomium (unregistered)

    Ah yes, the ancient times when Java didn't have enums, and the fight to be allowed to fix that in today's age.

  • Frodo B. (unregistered)

    they could have just used an Optional type, which is arguably the "right" option here.

    Optional is specifically intended as a RETURN type, not a PARAMETER type. Proof by authority: Brian Goetz.

    https://stackoverflow.com/questions/26327957/should-java-8-getters-return-optional-type/26328555#26328555

  • (nodebb)

    How about the WTF of not using a simple arithmetic check, since the valid values are a contiguous set of integers.

    if (mode < 0 || mode > 6)
    
  • (nodebb) in reply to Steve_The_Cynic

    Short-circuiting order of evaluation is irrelevant when the conditions have no side effects, like simple equality conditions. But you're right, this is an issue of associativity, not commutativity.

  • (nodebb) in reply to Barry Margolin

    Short-circuiting order of evaluation is irrelevant when the conditions have no side effects, like simple equality conditions.

    That did occur to me, about two milliseconds after I pressed "Submit". Oh well.

  • (nodebb)

    And there I just wondered why people would need the Delta nuget to handle etags over DB queries. Turns out some developers don't even understand basic boolean logic these days, not to mention that there are more conditional operators beyond equality checks.

Leave a comment on “What a More And”

Log In or post as a guest

Replying to comment #:

« Return to Article