• anonymouse (unregistered)

    So you're telling me C# does not have support for Globs? Now that's the REAL wtf

  • Henning (unregistered)

    return "NOTFOUND";

    Hey, i was looking for "NOTFOUND"!

  • Joat (unregistered)

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

  • Chris (unregistered) in reply to Joat

    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.

  • gleemonk (nodebb)

    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.

  • DSPC (unregistered)

    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.

  • Syntaxerror (unregistered)

    Should have just used a string-array and a loop. Or something of the sorts.

  • Ralph (unregistered)

    Another example of loopy code would have been less loopy.

  • Joseph Osako (google)

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

  • JustSomeDudette (unregistered) in reply to gleemonk

    I noticed the wandering else too.

  • PWolff (unregistered)

    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 )

  • CarrieVS (nodebb)

    Even assuming we must do this by a succession of tests for every possibility, apparently someone has an allergy to else-if.

  • Oliver (unregistered)

    NO O O O O O O

  • cjb (unregistered)

    Maybe just asking where the file was?

  • KattMan (nodebb)

    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.

  • Bubba (unregistered)

    "Belgiumed" ?

  • akozakie (unregistered)

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

  • Hans the Great (unregistered)

    He/She wrote an excellent piece of code to auto-generate this C# code

  • JustSomeDudette (unregistered) in reply to Bubba

    Read today's news.

  • CoyneTheDup (nodebb)

    So...clearly the programmer can indent. But can the programmer do anything other clever tricks?

  • draff (unregistered) in reply to Bubba

    Presumably a reference to the US Hitchhiker's Guide...

  • Quite (unregistered)

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

  • BaconBits (nodebb)

    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.

  • dkf (nodebb)

    So… why does the bit with "j:\\isdn\\a\\" have different indenting to the rest of that code?

  • Quite (unregistered) in reply to BaconBits

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

  • Oliver Jones (google)

    The real wtf? ISDN.
    Compared to ISDN, this code is a model of clarity.

  • GordonFreemanK (unregistered)

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

  • Bananafish (nodebb) in reply to anonymouse

    Looks like C# programmers don't support globs.

  • Bort (unregistered) in reply to BaconBits
    Comment held for moderation.
  • Ross (unregistered) in reply to Bort

    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.

  • BaconBits (nodebb) in reply to Bort
    Comment held for moderation.
  • Carl Witthoft (google)

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

  • Yazeran (unregistered) in reply to Quite

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


    Plan: To go to Mars one day with a hammer.

  • KattMan (nodebb) in reply to JustSomeDudette

    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.

  • Dan (unregistered) in reply to BaconBits

    "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?

  • RichP (unregistered)

    "Josh H. inherited some C# code that puts a lot of ̶t̶h̶o̶u̶g̶h̶t̶ wasted effort into that. A lot. "


  • Ulysses (unregistered)

    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.

  • Scarlet_Manuka (nodebb) in reply to Dan

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

  • George B. (unregistered)

    if (fileExistsFlag) return longFileName; else return "NOTFOUND";

    WTF? I can has file NOTFOUND but not TRUE or FALSE?

  • George B. (unregistered)

    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?

  • George B. (unregistered)

    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.

  • Pierre F. (unregistered)

    Yay! There's enough space in the margin to the right of this code to write a proof of my theorem!

  • Bill C. (unregistered)

    Must ... go ... deeper ...

  • MrTerse (unregistered)

    Replace the if-else with ?:

  • Anonymous (unregistered)

    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.

  • Kukuluops (unregistered)

    This is what you get, when you pay for number of lines of code.

  • jgh (unregistered)

    I take it repeat/until loops don't exist in C#.

  • urkerab (nodebb) in reply to Pierre F.

    You don't even need the margin. Just write your proof in the indentation.

Leave a comment on “Finding the File”

Log In or post as a guest

Replying to comment #:

« Return to Article