• Swamp Thang (unregistered)

    public static bool IsCommentLess([CanBeNull] string userComment) { return userComment == "Frist"; }

  • Rob (unregistered)

    Remove the R from "userless" and you have a pleonasm.

  • Mike5 (unregistered)

    It's almost like "Representative line"...

  • Prime Mover (unregistered)

    Aha, so TRWTF is using an IDE that makes you scroll through several hundred lines of code because it doesn't give you the capability of doing a global search for UserLess?

  • (nodebb)

    I deal with non-programmers who still like to read through the delivered source code for my project. If this sort of thing makes it more accessible for them I see no problem. It is basically using the variable names as the comments instead of comment lines.

  • Jonathan (unregistered)

    People complain that programmers use NULL values to represent too many different things. This code documents how they intend to use it, and provides a uniform wrapper/facade for it.

    If you had found a bare if user == NULL deep in the code, people would be complaining "Well, what NULL mean for the user field?". This is the least WTF-y WTF I have ever read here

  • (nodebb) in reply to Prime Mover

    Not sure what they use, but VS has had "go to definition" forever. Perhaps they use VIM or whatever

  • WTFGuy (unregistered)

    Given these two gems of definitions near the top of the source file, I'd NOT be just using "find" to locate where they're used.

    Instead I'd be reading every single line along the way to learn about the other 250 WTFs that might impinge on the problem I'm trying to solve. Or that might impinge on the problem my fix is about to create.

    Then again, I've never been fond of the "smallest possible band-aid applied with the least amount of understanding" approach to code maintenance. That way lies disaster.

  • Randal L. Schwartz (google) in reply to Prime Mover

    Aha, so TRWTF is using an IDE that makes you scroll through several hundred lines of code because it doesn't give you the capability of doing a global search for UserLess?

    Or a direct "find all/goto references"?

  • (nodebb) in reply to Mr. TA

    vim with ctags will happily go to the definition/declaration as needed :)

  • Fergus Brainstorm (unregistered) in reply to Rob

    Replace the capital L with a lowercase one and you'll have one less aneurysm.

  • (nodebb) in reply to Fergus Brainstorm

    Remove the R from "userless", move the L from "userless" to the beginning of "user", and you'll have more cynicism.

    Addendum 2023-02-15 18:41: Poetic license required

  • xtal256 (unregistered) in reply to Mr. TA

    Or worse, VSCode :shudders:

  • DeeKay (unregistered) in reply to Rob

    That's a bit mean. Without users, there'd be no software.

  • Kleyguerth (github) in reply to Jonathan

    Same thing I thought, those constants and functions are "translating" business logic into programming logic. Way better than seeing null and empty being assigned to user without a clue as to what each case means.

  • Anon. E. Mouse (unregistered)

    This is good practice - no a WTF.

  • simonced (unregistered)

    I feel it could be an attempt to be future proof. If the specs change and the UserLess becomes something else (like a specific dummyUserClass or someting) then the refactoring could get easier.

  • (nodebb)

    "Any literal used more than once should be a constant identifier."

    There. I said it.

    If the application someday needs to say EmptyUser is now spelled "This is the Empty User!", there's one line to change. If EmptyUser is everywhere spelled "" (empty string), and needs to be changed, through the whole codebase -- that's what we hire interns for, right?

    And if you're going to do all that, you then need to future proof it with the functions to check for same. Because IsNullOrEmpty doesn't work any more.

    I'd further suggest the code is missing the IsEmptyUser function.

    Declaring all literals used more than once means the compiler can complain when they're missing, instead of at runtime when you've mistyped some magic value. (This works wonders for hash keys in languages where you can't predeclare the keys.) Now I just want my linter to tell me I've broken the "don't repeat literals" rule.

  • David Mårtensson (unregistered)

    I agree with others, this is not really a WTF,

    Comparing with null or string.empty does not always explain WHY you do the compare, adding a constant like EmptyUser gives more context.

    In this case, since we have a method around it, it is a bit redundant, the method name already explains why we do the check, and the constants, unless used in multiple places should probably be closer to the usage (but several hundred lines is a bit of WTF in it self).

    But I rather have redundant explanations, than no explanation :)

  • Gnasher729 (unregistered)

    The constants are just part of an implementation detail. A part. The two methods that actually supply the wanted information have to know both the constant and how to use it, so the constants are indeed useless.

  • owlstead (unregistered)

    Having a file with several hundreds of lines of code can be a bigger CodeSOD than the actual constants. That said, I'm rather curious what an "empty user" is supposed to be. No user - as in, not logged in - seems fine although I'd rather go for ANONYMOUS = null in that case?

  • Bob (unregistered)

    How does C# handle "equals" vs "==" for strings ? In java there could be a difference, == would only return true if referring to same object

Leave a comment on “Userless User”

Log In or post as a guest

Replying to comment #:

« Return to Article