- Feature Articles
- CodeSOD
-
Error'd
- Most Recent Articles
- Stop Poking Me!
- Operation Erred Successfully
- A Dark Turn
- Nothing Doing
- Home By Another Way
- Coast Star
- Forsooth
- Epic
- 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
This is the FristTimeISee(article) code like this.
Admin
IsCodeConfusingOrStupid(code) == false
Admin
They was just a Yoda coder.
Admin
Formal proof: ¬ ( ∅ ∨ "" ) → "" ∨ ∅ is not unfalse, because "not" reverses ALL THE THINGS!
Admin
The new name is actually slightly reasonable. Who can remember if Null or Empty comes first? This way they both work.
But the "!"... I got nothing.
Admin
The core problem here is to many people don't understand 'null' as a concept, and to many implementations (looks at C) have an implementation that confuses the topic.
A null pointer, its not that it does not have a value, its that it isn't a valid one. There is nothing inherent in the environment that is tracking the thing is undefined, that is there no shadow/compiler managed variable that tracks the thing in question is undefined; just that the standard say NULL == 0; which is also a value..
The sensible thing to do in the OOO world is to have .isZeroLength?, .isNull?, and for string-y and variant or simple object like things an .nullOrEmpty? the names are not critical but those are three things you need, to code clearly in a way that expresses understanding and intent about data being worked with. Lets be real honest here though most of the procedure around this stuff is always going to be a little of a WTF because of two things - text protocols and interchange formats. Does ?x=&y=Taft in a querystring mean X is null or does it mean X is '', ditto in a csv William,,Taft, is MrTaft's middle name '', nonexistent, or unknown/undefined? Either we are going to need some more bool fields to track these details or we are going to have to make assumptions..
In my actual experience by the time it makes sense to reach for whatever the equivalent of .nullOrEmpty? is because there is already a choice that has been made to ignore corner cases, kludge around upstream control flow that is missing, or mask what probably should be some kind of data exception.
Admin
For a lot of code,
IsCodeConfusing(code)
andIsCodeStupid(code)
should both unconditionally returntrue
.Addendum 2024-08-28 09:31: Well, except if coded like in this WTF, where they should return
false
. Unconditionally.Admin
OK, maybe, but it should probably be written as an extension method or something to make the syntax as close as possible.
Or maybe, just maybe (ha ha ha ha ... ha ha ha) developers should just actually learn to use their tools correctly.
(Now I'm going to go outside and laugh myself silly at what I just wrote...)
(OK, I'm back. I feel weak.)
Me neither. I cannot imagine the sort of thought process that could write code like that.
Admin
Probably it used to be if (!IsEmptyOrNull(myinput)) and then someone came along with some "Coding Standards" where you couldn't have negative logic in an if statement. Someone decided to be snarky and remove all of the NOT symbols and move the logic to a wrapper function.
Admin
so, malicious compliance?
Admin
If it is, then it's commendable. Assuming they did it while walking out the door.
Admin
It’s a subtle issue of what the meaning of “Is” is. You might assume that the function should answer assertively whether its argument is null or empty, but the proper interpretation is interrogative “Is?” with an implicit context that “not null or empty” is desired. It’s like when you ask someone “Is this seat taken?” and they answer “Sure, go ahead.”
Admin
That is indeed very malicious compliance, because that is code smells galore.
is a major code smell. I'd rather see
but anybody who writes
deserves to be burnt because you're mentally processing a double negative when you get to the else block.
Admin
No, deliberately making the codebase worse is never commendable. Especially if it's out of spite.
Admin
So... IsEmptyOrNull is not NullOrEmpty
Yeah, that makes sense
Admin
I don't get it, why not making the method virtual? If you already hate maintainability, why not just kill performance as well?
In fact, I can do better:
Admin
Nice attempt, but still not perfect. You should have thrown an exception if param1 is a string, immediately catch it, log, rethrow, catch it again, then do .ToString upon it, convert each character to upper case in a loop... And perhaps use a bunch of nested ternaries, returning same result regardless of input.
Admin
I've ran into code that was something like
if ( doesnotcontainsomething != false ) { // do some stuff } else { // do some other stuff }
Admin
With short circuit "NullOrEmpty" is different then "EmptyOrNull" and the latter form can not e evaluated becuase "Empty" is meaningless when "Null" so checking for that first is an error.
Admin
I am not an English native speaker, so take it with a grain of salt... But I just can't imagine the exchange to go this way.
Admin
This is when I start digging into commit history.. because I have to know what they thought they were fixing.