- Feature Articles
- CodeSOD
- 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
When the only tool you have is a hammer ... everything gets damaged.
Admin
Slightly disappointed. When I saw this
I was expecting that at some time shortly after this person started, the team no longer had any regular jobs that ran in the mornings.
Admin
And that he does not do it consistently!
Admin
I waited 3 minutes to post this
Admin
Y'all are gonna hate me, but I always test boolean variables as "if (okay)" and "if (okay == false)". Sometimes the exclamation point is hard to see, but at least I'm consistent.
Admin
I'll do one better. In TS I convert to boolean by using Boolean(test) not !!test. For the same reason, the double exclamation marks is hard to see and may be confused with a single excalamation mark
Admin
Have you considered a career as a lawyer instead?
Admin
In Python, the exclamation mark is a not and hard_to_see != False
Admin
I am going to hate you, because it can be written clearer as
if okayandif !okay.Admin
My first thought looking at this code was that given there are three boolean variables, and different logic to run based on different combinations of values, it may improve readability in this case to say "if (bool1 = true and bool2 = true and bool3 = false) {} else if (bool1 = false and bool2 = true and bool3 = true). {}..." etc. That way you can see at a glance which specific combination is being treated by each block of code. But then I saw the "if not hub_1_ready and not hub_2_ready and job_ran_later == False:" and can only shake my head and walk away.
Admin
Not in every programming language.
Admin
Well no.
But neither can
if (okay),if (okay == false),if not okay,if [ $okay -ne 0 ],if okay == False, orif (okay === true)`. In fact, I don't think there's anything that would work in every programming language.Admin
In Python you can use
notas well as!.Admin
The only sane reason to prefer double negation over a cast/explicit coversion is using a lame language where the latter does not exist. A cast is the semantically correct choice, you want to convert a non-boolean into a boolean, you don't want to take a negation of a negation (which should logically be the original, relying on such an operation to do anything at all is a hack)
Admin
Then why would you hate someone for writing
if (okay)whenif okayisn't valid syntax for the language?Admin
Unless of course you overload the ! operator to do something other than just negating. As in, have a custom class that uses the ! operator to "logically" negate a number of the fields by flipping their internal value to settings opposite of what the setting was. And no, we are NOT just talking about boolean values. We are talking about complex custom object types, well structs since this was old C++, changing their internal state. And yes, the code is naturally not available.
How did I come up with this? I didn't. As to where I found it you don't want to know.
Admin
Operator overloading is one of those ideas that sounds great in theory, but really, really invites danger in practice. If there was a way for the language and compiler to enforce "similar" semantics on overloaded operators as they naturally have, that set of guardrails would prevent the worst abuses. Such as enforcing no side effects. For operators that are typically commutative, e.g.
+enforcing commutivity on the overload, etc.The real value of
SomeMethod( Argument1, Argument2)overArgument1 (some common math symbol goes here) Argument2is the former invites you to wonder howSomeMethodreally works on these argument types, while(some common math symbol goes here)strongly invites you to assume a standard implementation of the math idea you've known since school.Admin
the C preprocessor. Really powerful and a lot of fun to write code with, but absolute hell to maintain.
Admin
The "++" operator would like a word with you.