- 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
So you're telling me C# does not have support for Globs? Now that's the REAL wtf
Admin
return "NOTFOUND";
Hey, i was looking for "NOTFOUND"!
Admin
It's amazing that there are "developers" that doesn't know that pattern matching exists.
What's even more amazing is that there a lot of "developers" that know that it exists but choose not to use it because "it's too complicated".
Admin
I do not think pattern matching is applicable. However, file name expansion is which may or may not be implemented in a certain programming language.
Admin
I like the displaced else in the middle, where two levels are indented by two spaces instead of four. Gives the whole thing a human touch.
Admin
Were we always able to scroll the code samples with ridiculously long lines? Exciting.
People who don't now how to use a search engine should stay away from code.
Admin
Should have just used a string-array and a loop. Or something of the sorts.
Admin
Another example of loopy code would have been less loopy.
Admin
vomit I really have to avoid reading TDWTF right after eating...
There are so many things this coder could have done instead of this... this... I can't think of a word to describe whatever the fuck this shit is, actually. The coder has actually exceeded the power of human language to describe how stupid something is..
Admin
I noticed the wandering else too.
Admin
A loop might be faster to write (for a human) and easier to maintain, but it takes significantly longer to run. (Several ppm in this case, I assume.)
Error message: File "C:\Users\PWolff\AppData\Local\Temporary Projects\tdwtf_20160322\bin\Debug\NOTFOUND" not found.
(Error message when trying to log in: Illegal arguments: string, object )
Admin
Even assuming we must do this by a succession of tests for every possibility, apparently someone has an allergy to else-if.
Admin
NO O O O O O O
Admin
Maybe just asking where the file was?
Admin
Considering it is trying to walk down what I assume are all the directories this could have easily been handled by recursion. But to recurse this code we need to curse it first! Though it already seems belgiumed to start with.
Admin
"Belgiumed" ?
Admin
It's amazing just how much code some people can write without thinking "there MUST be a better way".
This approach possibly made sense with two variants (although the else-phobia is striking). Three maybe, if two are already implemented and you're very lazy. But this? Wow. Although it's a nice LOC inflation method...
(So nice to be able to comment normally again!)
Admin
He/She wrote an excellent piece of code to auto-generate this C# code
Admin
Read today's news.
Admin
So...clearly the programmer can indent. But can the programmer do anything other clever tricks?
Admin
Presumably a reference to the US Hitchhiker's Guide...
Admin
... and then what happens is that during the lifetime of the application, the program fails to find a particular file that ought to be somewhere in there. Not a problem, says the programmer, just got to add another if-then-else to the code to take on that new file location.
Pretty sure there are standard 3rd-party library routines that will find (and return the path of) a file that exists anywhere in a directory tree in one line, but that would of course fall foul of NIH ...
Admin
Eh, the code itself isn't that bad.
Sure, you could put the directories into an array and iterate through them until you find the file, but beyond being easier to maintain the list of folders that's not all that much better.
Pattern matching isn't going to work because the possible sources span multiple drive letters, but even ignoring that the patterns in System.IO.File and System.IO.Directory aren't regex but wildcard patterns. Sure, you want to search
"g:\\isdn\\a\\"
and"g:\\isdn\\b\\"
, but maybe you don't want to be searching"g:\\isdn\\temp\\"
. It's also impossible to tell if the order the folders are searched is important. Is there a reason that"g:\\isdn\\a\\"
must be searched before"g:\\isdn\\b\\"
? Who knows?TRWTF is that multiple input folders that are statically defined in the program. It should be defined at runtime in a configurable setting of the program, or else have a single fixed value pointing to a dedicated data input folder. Anything else is just behavior that's going to be incomprehensible to anyone that isn't familiar with the source code.
Admin
So… why does the bit with
"j:\\isdn\\a\\"
have different indenting to the rest of that code?Admin
--> BaconBits:
It's possible to philosophise endlessly as to whether this folder needs to be searched before that folder, and whether specific folders need to be searched and others specifically don't, but I'm prepared to bet bucks to beans that the app just wants to be able to find a certain file wherever it happens to be, and so in order to do that, it just searches through all the folders there are. Stupidly.
Admin
The real wtf? ISDN.
Compared to ISDN, this code is a model of clarity.
Admin
"It should be defined at runtime in a configurable setting of the program, or else have a single fixed value pointing to a dedicated data input folder."
Actually that is not a universal truth at all. It makes sense to make an application configurable if there is a use case for the user to actually configure it. Otherwise, you are just opening a door to issues that you did not foresee.
Maybe this list of folders evolves outside of the release process of your application. But if it is not the case, it is absolutely valid to hardcode values.
Admin
Looks like C# programmers don't support globs.
Admin
Admin
You need to prefix that code with a variable called prefixes. Sigh. I tried for over a minute to make that less lame but failed.
Admin
@Quite:
There's no way to know that, though. I've seen plenty of code that looks stupid, but actually is written to conform to how it has to behave.
@Bort
Not every C# app supports LINQ. Without LINQ, your elegant one-liner evaporates. Either way you're still supporting a giant list of 60 odd folder names across a dozen drives. That is what's stupid.
Admin
% find /* -depth -name my_file >> file_location.txt.
Doesn't even need compilation. (and yes I know it's possible to issue shell commands from compiled code. Or at least it used to be)
Admin
--> Quite
Yes indeed, and even if the search order is important it could have been handled by using a ordered list where you specify the order, you know an array gasp... :-) and then bailing out of the loop with a last/break or whatever once the file has been found....
Yazeran
Plan: To go to Mars one day with a hammer.
Admin
Yes in reference to THHGTTG but it seems as of today we have officially achieved the fact that B*****m is now a bad word. Now I'm just waiting for the Heart of Gold to pop in, I'll just take cover in case the weather forecast calls for whales.
Admin
"There's no way to know that, though. I've seen plenty of code that looks stupid, but actually is written to conform to how it has to behave."
Exactly. What this code is trying to accomplish is the bigger WTF than how it attempts to accomplish it. What, was the network drive mounted as "first available letter" and it kept changing, or is it different on every system that mounts it?
Admin
"Josh H. inherited some C# code that puts a lot of ̶t̶h̶o̶u̶g̶h̶t̶ wasted effort into that. A lot. "
FTFY
Admin
My dimwit coworker has an equally limited imagination and chooses to use arrowheads in a language with deterministic destruction. She's never nested them quite so deeply though.
Admin
"What, was the network drive mounted as "first available letter" and it kept changing, or is it different on every system that mounts it?"
Could be either, but I would guess the latter. To me, the code looks as if it was originally set up for one drive letter, and then one day a user mapped the network drive to the next letter and they had to add those cases in. And then someone else mapped their drive a few letters further on and they said "OK, let's just add in all the drive letters up to there."
Admin
WTF? I can has file NOTFOUND but not TRUE or FALSE?
Admin
You don't like less-than signs for "quoting"? I'll try braces. Though no matter what I use, it looks funny in code.
} if (fileExistsFlag) } return longFileName; } else } return "NOTFOUND";
WTF? I can has file NOTFOUND but not TRUE or FALSE?
Admin
Actually it was greater-than signs that you didn't like. You let the braces stay where you deleted greater-than signs, but still broke the line breaks. Do you allow BB-code? Sorry I don't remember what BB-codes you used to allow; you used to have a link to explain them but no more.
Admin
Yay! There's enough space in the margin to the right of this code to write a proof of my theorem!
Admin
Must ... go ... deeper ...
Admin
Replace the if-else with ?:
Admin
Let me guess,
fileName
is config.xml and every department needs a different config, has a different set of network drives mounted, and/or is full of special snowflakes who need it customized for them.Admin
This is what you get, when you pay for number of lines of code.
Admin
I take it repeat/until loops don't exist in C#.
Admin
You don't even need the margin. Just write your proof in the indentation.