- Feature Articles
-
CodeSOD
- Most Recent Articles
- What a More And
- Hall of Mirrors
- Magical Bytes
- Contact Us
- Plugin Acrobatics
- Recursive Search
- Objectified
- Secondary Waits
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
frist: as it is written, in the null check this.mode is assigned null secnod: mode always evaluates to invalid
Admin
Another WTF: nothing is done with the default value 4. Why don' t they set this.mode to 4 when the input is null?
Admin
if (mode == null) { this.mode = mode; return ; }
^^^ THAT'S your WTF!!!!! ^^^
Edit Admin
Two points here:
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 off(params) && g(params)
andg(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.)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
anda && (b && c)
anda && b && c
are equivalent.Admin
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?
Admin
Ah yes, the ancient times when Java didn't have enums, and the fight to be allowed to fix that in today's age.
Admin
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
Edit Admin
How about the WTF of not using a simple arithmetic check, since the valid values are a contiguous set of integers.
Edit Admin
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.
Edit Admin
That did occur to me, about two milliseconds after I pressed "Submit". Oh well.
Edit Admin
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.
Admin
Order of evaluation still matters in short-circuiting without side effects. Consider the case where the null-check would be included in the if statement. It then needs to come first, otherwise the next check (code!= 1) will fail with an NPE.