- 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
Not sceond uncomment
Admin
This post is not unamusing
Admin
Yeah, right.
Admin
The real WTF is why, given that the original code can only set portUnAvailable to False, code that can set it to True is presented as equivalent.
Admin
The title is great :D "Never Don't Stop Not Doing This" -> "Never Don't Start Doing This" -> "Always start doing this"?
Admin
"Don't stop" doesn't generally mean "start", it more often has the meaning of "continue". But the point is well taken. Did Remy intend to over-negate or did he just get tripped up?
Admin
NOT the same code....
The first snipped can only set the existing value to false.... the supposedly "easier" can cause a value which was previously false to become true.
Admin
I know that the suggested fix isn't exactly the same, but I'm guessing whoever wrote the original code was so confused that the fix would actually be correct.
Admin
TRWTF is that he used Python, which even allows such constructs, instead of the vastly superior Microsoft.NET Framework, which is superior in every way. My brain is very smart and my mother definitely loves me.
Admin
It does look a bit over negated.
Never Don't Stop Not Doing This => Always Do Stop Not Doing This => Stop Not Doing This => Carry on doing this.
Admin
There's an application I "inherited" that uses a boolean env variable called "DO_NOT_USE_CACHE". I always have to think a little longer whenever I want to toggle cache behavior.
Admin
Could also have used "If port Is Not Nothing". "x Is Not Nothing" is a Visual Basic idiom meaning exactly "Not (x Is Nothing)"; it isn't trying to negate the truthiness of Nothing.
Admin
"Don't stop" would mean "continue," but that's not the part Artoooooor replaced. Their replacement was "stop not doing" to "start doing," which sounds right to me.
Admin
Am I the only one that's annoyed that it's not called portUnavailable? Because last I checked, the word is "unavailable" and not "un available" or "un-available".
Admin
There is sometimes a good use case for negative logic.
I remember an application which produced a generic report for a whole bunch of customers, customisable in various ways.
One day we were given a requirement for one particular customer for which we were not to include a specific section. In order to implement the minimal change which did not involve hardwiring the customer's ID was to expand our registration database to include a new flag. The default behaviour, for customers who did not include that flag, was for that section to be generated. If the flag was set, the section was not included.
Hence the need to negative logic: the flag was true in the case of "don't include X section".
Admin
In japanese if you ask someone "Did you not see this?" and the answer is "Yes" they literally mean that they did not see whatever you're asking about. So learn a bit of japanese and this will stop looking weird to you.
Admin
When I have to deal with things of that nature I tend to name the flag "skip_x" which makes it a bit more obvious that it powers the removal of some kind of logic or content.
Admin
Admin
Should still have been positive logic: "exclude X section".
Admin
Clearly Visual Basic is lacking an
Is Something
operator.Admin
Reframing the question to be positive logic is usually worth doing, especially if tests done on the flag are frequently of the "double negative" type (for clarity, the example code uses keywords rather than C/C++ operator symbols):
if ( not don't-include-X ) produce-X
becomes:
if ( not exclude-X ) produce-X
Admin
Isn't Visual basic
IsNot
a single keyword? Also, I'm not 100% sure it existed from the start -- perhaps it was added after the first version of VB.Net?Also, the correct code would be something like
portUnAvailable = portUnAvailable And (port is Nothing)
. And I don't care whether the parentheses are truly necessary or not.Admin
The effect of the code in the article can be achieved with the assignment
Admin
This is the reason why I usually suggest avoiding negations in variable/method names.
If Not portIsUnAvailable
requires much more cognitive effort to parse thanIf portIsAvailable
Admin
Over in MathematicsLand, " x is positive" and "x is not negative" are in fact different conditions. Then again, how many of you software jocks have ever stopped to consider that " if x <= y" is really shorthand for "if x < y || x ==y " ?
Admin
I'm really trying hard to imagine a scenario where you have a port, which could actually be Nothing, but you need to keep track of whether it's available or not... I'm guessing there's way too much intertwined logic in these functions.
Admin
Regarding the above report flag as a general example, my suggestion is thus:
The flag is documented as "exclude-report", default is to be "off". Then as soon as the flag, along with other options, is read the program reverses the flag so that the internal logic uses "if include-report ..."
Admin
Also, suggested title update: Never Don't Stop Not Doing Nothing Unlike Something Other Than This
Admin
My favorite is still SQL Server's NOCOUNT property.
SET NOCOUNT ON
Means don't provide counts. It would be much more intuitive to have SET COUNT OFF for such a case.
Admin
I couldn't fail to disagree with you less!
[Credit to Raymond Smullyan]
Admin
It's not Python, it's Visual Basic.
Admin
It seems like it's used after you call a function that returns a port number, and if it can't it returns Nothing, then we set a boolean to remember whether it was successful and it's OK to use the port. I guess code that checks the PortUnAvailable variable could just check Port directly, but some programmers like to have a simple boolean that caches the test.
Admin
Nobody isn't never going to write no code unlike this, nowhere and for no reason.
Admin
There are some languages in which it's quite normal to chain multiple negations together, half a dozen or more in the same sentence. As a speaker of one of those languages, I still can't understand that code without writing down an explicit simplification.
Admin
"My favorite is still SQL Server's NOCOUNT property. SET NOCOUNT ON Means don't provide counts. It would be much more intuitive to have SET COUNT OFF for such a case."
The flip side is the concept that the default for all options should be OFF, and you explicitly need to turn options ON
Admin
Has Anyone Really Been Far Even as Decided to Use Even Go Want to do Look More Like?
Admin
They don't actually present it as equivalent. Note the sentence immediately after the fragment saying: "Then again, without context, that might be wrong".
Admin
I wish I did not see this.