- 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
public static bool IsCommentLess([CanBeNull] string userComment) { return userComment == "Frist"; }
Admin
Remove the R from "userless" and you have a pleonasm.
Admin
It's almost like "Representative line"...
Admin
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?
Admin
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.
Admin
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 hereAdmin
Not sure what they use, but VS has had "go to definition" forever. Perhaps they use VIM or whatever
Admin
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.
Admin
Or a direct "find all/goto references"?
Admin
vim with ctags will happily go to the definition/declaration as needed :)
Admin
Replace the capital L with a lowercase one and you'll have one less aneurysm.
Admin
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
Admin
Or worse, VSCode :shudders:
Admin
That's a bit mean. Without users, there'd be no software.
Admin
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.
Admin
This is good practice - no a WTF.
Admin
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.Admin
"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.
Admin
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 :)
Admin
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.
Admin
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?Admin
How does C# handle "equals" vs "==" for strings ? In java there could be a difference, == would only return true if referring to same object