• King (unregistered)

    This is the FristTimeISee(article) code like this.

  • (nodebb)

    IsCodeConfusingOrStupid(code) == false

  • Tinkle (unregistered)

    They was just a Yoda coder.

  • Officer Johnny Holzkopf (unregistered)

    Formal proof: ¬ ( ∅ ∨ "" ) → "" ∨ ∅ is not unfalse, because "not" reverses ALL THE THINGS!

  • (nodebb)

    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.

  • Hal (unregistered)

    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.

  • (nodebb) in reply to Mr. TA

    For a lot of code, IsCodeConfusing(code) and IsCodeStupid(code) should both unconditionally return true.

    Addendum 2024-08-28 09:31: Well, except if coded like in this WTF, where they should return false. Unconditionally.

  • (nodebb) in reply to d-coder

    The new name is actually slightly reasonable. Who can remember if Null or Empty comes first? This way they both work.

    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.)

    But the "!"... I got nothing.

    Me neither. I cannot imagine the sort of thought process that could write code like that.

  • (nodebb)

    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.

  • (nodebb) in reply to davethepirate

    so, malicious compliance?

  • (nodebb) in reply to Steve_The_Cynic
    so, malicious compliance?

    If it is, then it's commendable. Assuming they did it while walking out the door.

  • Duke of New York (unregistered)

    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.”

  • (nodebb)

    That is indeed very malicious compliance, because that is code smells galore.

        if (cond) 
        { 
            do stuff 
        } 
        else 
        { 
            throw (or return)
        }
    

    is a major code smell. I'd rather see

        if (!cond)
        {
            throw (or return)
        }
    

    but anybody who writes

        if (!cond)
        {
            do one thing
        }
        else
        {
            do other thing
        }
    

    deserves to be burnt because you're mentally processing a double negative when you get to the else block.

  • (nodebb) in reply to CodeJunkie

    If it is, then it's commendable.

    No, deliberately making the codebase worse is never commendable. Especially if it's out of spite.

  • Chris O (unregistered)

    So... IsEmptyOrNull is not NullOrEmpty

    Yeah, that makes sense

  • (nodebb)

    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:

    public virtual bool IsEmptyOrNull(string param1)
    {
            return param1 is string ? ((bool?)typeof(string).GetMethod("IsNullOrEmpty")?.Invoke(null, new[] { param1 })) ?? false : false;
    }
    
  • Jim Jam (unregistered) in reply to MaxiTB

    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.

  • Greg (unregistered) in reply to thosrtanner

    I've ran into code that was something like

    if ( doesnotcontainsomething != false ) { // do some stuff } else { // do some other stuff }

  • TheCPUWizard (unregistered)

    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.

  • (nodebb) in reply to Duke of New York

    It’s like when you ask someone “Is this seat taken?” and they answer “Sure, go ahead.”

    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.

  • BStew (unregistered)

    This is when I start digging into commit history.. because I have to know what they thought they were fixing.

Leave a comment on “IsEmptyOrNullOrNullOrEmpty”

Log In or post as a guest

Replying to comment #:

« Return to Article