• (cs) in reply to Old Geezer
    Old Geezer:
    This isn't a WTF.

    This to is a WTF. No the real WTF isn't that he reimplemented a framework function. (Maybe he wasn't allowed to use that portion of the framework, maybe this wasn't a path"

    What array contruction routine are you referring to? This code constructs an array, then iterates over it to retrieve the last element. AND while its doing that, it (presumably) creates a new set of strings from each string.

    Sure it might be a minor WTF, but is a WTF nonetheless.

  • Liz (unregistered)

    The really funny thing is, I read this DailyWTF, then went to a program I wrote yesterday and replaced

    string filename = inputFile.Substring(inputFile.LastIndexOf("\")+1);

    with

    string filename = Path.GetFileName(inputFile);

  • Shanwise (unregistered) in reply to Liz

    I like the Title of the Comments section

    <title>The Long Road to Clean Up The Daily WTF - The Daily WTF</title>

    The Daily WTF needs cleaning up?? Surely not!

  • (cs) in reply to TickleMeElmo
    TickleMeElmo:
    My favourite part is the final string.ToString() call. I can picture the developer pausing to reflect at the end of his job on whether there was any way to make it just a *little* worse.

    string.ToString().ToString()

    you know.. just in case.

  • Asif Youcare (unregistered) in reply to another Steve
    another Steve:
    Agreed - this is one of the least exciting WTFs I've seen. The code isn't laughable or dangerous - just inefficient and shows he doesn't know the libraries well. Slow news day?

    Its a multi-layered WTF:

    1. He ignored the library function that does exactly what was wanted.
    2. He used (slow) regex to get the last component.
    3. He looped through the array rather than indexing the last element.

    The coder was thoroughly incompetent.

    In .NET and java development it is essential to have a good grasp of the supplied libraries because they can do so much for you.

    The regex I can forgive, but it is still substandard.

    The looping is totally unforgivable. What sort of coder doesn't know how to access the last element of an array?

    This is a worthy and sad WTF.

  • (cs)

    I guess a couple of these comments explain why there is always a certain amount of bullshit software in the windows world that just absolutely never accepts / as a path separator.

    THOU SHALT NOT EMULATE UNIX

  • I have the hat to this day. I have the hat. (unregistered) in reply to Old Geezer
    Old Geezer:
    No obfuscation by stupidity.
    filename = IO.Path.GetFileName(filename);
    is obfuscated??
  • Michael (unregistered) in reply to Neomojo
    Neomojo:
    lynn:
    Most people probably don't know about the 'Path' class. I found it in a blog 1.5 years ago and started to use it. I makes life so much easier. I have been using .Net since late 2001.

    I think in all fairness most people learning .Net have so much to tackle (ASP.net/WebForms/ASMX/ADO.net and now WPF and WCF) that a gem like the Path class is just not on the radar.

    Maybe it's just me (A few things are. Peanut butter, ham and ketchup sandwiches, for example.) but when I'm trying to do something in .Net (or PHP), my first thought is "has it already been done?"

    I agree that there are a lot of namespaces, objects and functions to browse through, but generally (as with the Path class) they're in intuitive places. If only it were true always, and not just generally.

    The problem of course is having documentation, that is well designed. Class maps, function defs, etc. And most importantly easily searchable. (not 50, 000, 000 hits for the word 'path').

    I'm versed in several languages and several frameworks/libraries but i've really only found semi decent documentation with gnu libraries, sgi and java. No wonder that he missed it in .net .

    captcha: random (hmm, does anyone think that this captcha is truly random?)

  • Wow (unregistered) in reply to savar

    If you'd rather not use @"\", you could use "\\".

    Of course, I think it's a little less obvious that "\\" will match a single backslash character.

    CAPTCHA: clueless

  • TheOtherJosh (unregistered)

    My python code is probably wtf worthy:

    in one function:

    self.files=glob.glob(os.path.join("games", self.storydir, "*.*"))
    

    and in the other function:

    def path(self, filename):
            """Get the proper path for a file given in script."""
            filename=os.path.join("games", self.storydir, filename).lower()
            for File in self.files:
                    if File.lower() == filename:
                            return File
    

    I have a reason for all this though. The scripts this program parses and interprets were created in Windows and thus the files requested are in whatever case the developer cared to use. In other operating systems, filename case is important so I solve this issue by handling it all in lowercase.

  • Chris (unregistered) in reply to Michael
    Michael:
    I'm versed in several languages and several frameworks/libraries but i've really only found semi decent documentation with gnu libraries, sgi and java. No wonder that he missed it in .net

    I've found that the MSDN documentation for .NET is fairly reasonable, as long as you use Google to search it of course.. ;)

  • Martin Paternoster (unregistered)

    Another way to do what he wated in .NET (without using IO.Path.GetFileName(x)): result=parts[parts.Split("\").UBound()];

  • Mikkel Høgh (unregistered)

    That's just horrible and wrong in so many ways. Decidedly Lovecraftian...

  • Different Anonymous (unregistered)

    strrchr(fullPathName, '\') + 1;

    Too bad this isn't C.

  • clayne (unregistered) in reply to Thuktun
    Thuktun:
    It could be worse, they could have offshore developers actively creating and indexing into arrays for no reason.
    static final char charArray[] = new char[94];
    static {
        for (int i = 0; i < 94; i++) {
            charArray[i] = (char) (0x21 + i);
        }
    }
    

    // ...

    return charArray[random.nextInt(94)];

    versus the shorter but somehow inferior
    return (char) ( random.nextInt( 94 ) + 0x21 );
    I wish I was kidding.

    WTF is:

    static { typical construct }

    syntax?

    C, NOT C++, programmer here, wondering...

  • (cs) in reply to clayne
    clayne:
    Thuktun:
    It could be worse, they could have offshore developers actively creating and indexing into arrays for no reason.
    static final char charArray[] = new char[94];
    static {
        for (int i = 0; i < 94; i++) {
            charArray[i] = (char) (0x21 + i);
        }
    }
    

    // ...

    return charArray[random.nextInt(94)];

    versus the shorter but somehow inferior
    return (char) ( random.nextInt( 94 ) + 0x21 );
    I wish I was kidding.

    WTF is:

    static { typical construct }

    syntax?

    C, NOT C++, programmer here, wondering...

    In Java, anything you put inside a static{} block inside a class definition gets executed exactly once when the class definition is loaded from disk (arm-wavy; "loaded from disk" isn't quite right but I don't feel like checking the spec) into the virtual machine.

    For example, in C, you are allowed to do this:

    int foo[5] = {1, 2, 3, 4, 5};

    to make a global variable with preinitialized values.

    You can do pretty much the same in Java (in fact I think exactly the same syntax works). However, you can ALSO make a "global" variable (static duration and class scope) which has arbitrarily complex initialization. You can do this either by writing a method that generates the desired values, then declaring the variable as:

    static int[] foo = makeFoo();

    or by doing something like this:

    static int[] foo; static { foo = new int[5]; for (int i = 0; i < 5; i++) foo[i] = (int) (Math.random() * 100); }

    In this case, each class loader (essentially, each running copy of the program) will get ONE SINGLE list of 5 random numbers, which are guaranteed to be prepared before the variable "foo" is accessed by any "normal" means (that is, other than from another static initializer).

  • Tony103b (unregistered)

    I think your all looking in the wrong direction.

    In my experience the filename is normally shorter than the path, so go backwards:

    'Get Filename off path for i=len(strPath) to 1 step -1 if mid(strPath,i,1)="" or mid(strPath,i,1)="/" then strFilename=right(strPath,len(strPath)-i) exit for end if next i

    Also note that:

    1. Library functions 'Split()' also have loops and most iterate forwards
    2. I can't think of anything more expensive than creating an array of strings to do this simple thing, just think of the garbage collection.
    3. Even the class method (not available in my language) may perform worse if the internal representation of the path is a string
  • (cs) in reply to Different Anonymous
    Different Anonymous:
    strrchr(fullPathName, '\\') + 1;

    Too bad this isn't C.

    Or any other language.. in PHP I'd use strrpos.

  • AnoymousCoward (unregistered) in reply to brendan
    brendan:
    Crotchety Old Guy (on a SunOS 4.1.3 box):
    You spoiled kids these days with your fancy schmancy library calls.

    In my day, we walked 10 miles through the snow and then wrote something like this:

    I would hate to think how many miles you would walk for a complex solution.

    Crotchety Old Guy (on a SunOS 4.1.3 box):

    char *ptr = fullPathName; while( (ptr++) != 0); while((ptr-1) != '/' && --ptr != fullpath ); result = new String( ptr) ;

    first

    while( (ptr++) != 0); while((ptr-1) != '/' && --ptr != fullpath );

    should be

    char *last = NULL; for(;*ptr;i++) if (*ptr == '/') last = ptr; ptr = last;

    Second the C library already gives you a the strrchr function for doing this:

    char *ptr = strrchr(fillPathName, '/'); if (ptr) result = new String(ptr);

    @orginal post: striker has the best sollution to the wtf.

    i++ ????????? a slight typo, should be perhaps ptr++ ? :p

  • Anonymous (unregistered) in reply to pepethecow
    pepethecow:
    Relying on just the \ is a bug, depending on the source of the path string. Both / and \ are valid path delimiters in Windows. (Maybe not in Win9x) I believe all Windows functions will report paths using the \, however.
    "/" has been valid as the directory separator since the old DOS days (at least since DOS 3.3). This is obviously copied from unix via CP/M. Only that COMMAND.COM (and cmd.exe, still) interprets it as an option leader, and hence won't pass it through. And the GUI's (except Firefox/Win32 and NTEmacs) don't like to admit that "/" can be used as a directory separator.
  • cheap jerseys (unregistered)

    cheap NFL JerseyLewis says the Magic knew they could beat the Cavaliers in the Eastern Conference Finals when the the two teams cheap kobe jerseymet for Game 2. cheap Paul Smith ShoesIt took a miracle shot from LeBron James to beat Orlando cheap nfl jerseys cheap nfl jerseys Bucks are looking very closely at every point guard available in the draft would make youcheap g star [/url think Sessions [url=“www.cityoriginal.com”]replica jerseys walk, but it's far replica NFL jerseys, NHL jerseys too early to know. In truth, the Bucks nfl jerseysthemselves haven't f teams are starting to think about what cheap diesel [/url Villanueva would look like in their [url=“www.cityoriginal.com”]nba jerseysuniforms. One of them might be the Cleveland Cavaliers. cheap NFL Jersey mlb jerseys cheap nfl jerseys James' no-show after Game 6, we're finally getting down to business. Dwight Howard nfl jerseys [/url and Kobe Bryant will lace them up o decide [url=“www.cityoriginal.com”]cheap uggsthe best team in cheap north face jacketthe NBA. The Magic swept the season cheap jerseysseries from the Lakers, one of that feat (Charlotte was the other) cheap nhl jersey Raptors are they'd cheap tommy bahamaalso like to another selection there. With teams like L.A., Chicago, and Minnesota cheap nhl jersey [/url selling that area, they're replica [url=“www.cityoriginal.com”]NFL jerseys, NHL jerseys likely to find someone they can work with.cheap nba jersey Portland, Houston failed to shifts lebron james jersey back to Houston for Game 6 on Thursday as the Rockets scurry to make Jordan jerseysadjustments cheap nhl jerseys of the Blazers cheap ugg boots Grizzlies, and it's been mentioned that that pick could be had as well. Most teams looking to buy in are looking to buy into cheap ugg bootsthe late first/early second round. Memphis has picks potentially available in both those areas.cheap mlb jerseys Timberwolves use all three of their first round picks this year (6-18-28), and while it's all but certain they'll use cheap true religion jeanstheir #6 pick and probably the #18, that #28 could absolutely be had. For teams looking to buy into that part of the draft (see below), the Wolves cheap nhl jerseys

  • cheap jerseys (unregistered)

    cheap NFL JerseyLewis says the Magic knew they could beat the Cavaliers in the Eastern Conference Finals when the the two teams cheap kobe jerseymet for Game 2. cheap Paul Smith Shoes It took a miracle shot from LeBron James to beat Orlando cheap nfl jerseys cheap nfl jerseys Bucks are looking very closely at every point guard available in the draft would make you cheap g star think Sessions replica jerseys walk, but it's far replica NFL jerseys, NHL jerseys too early to know. In truth, the Bucks nfl jerseysthemselves haven't f teams are starting to think about what cheap diesel Villanueva would look like in their nba jerseysuniforms. One of them might be the Cleveland Cavaliers. cheap NFL Jersey mlb jerseys cheap nfl jerseys James' no-show after Game 6, we're finally getting down to business. Dwight Howard nfl jerseys and Kobe Bryant will lace them up o decide cheap uggsthe best team in cheap north face jacketthe NBA. The Magic swept the season cheap jerseysseries from the Lakers, one of that feat (Charlotte was the other) cheap nhl jersey Raptors are they'd cheap tommy bahama also like to another selection there. With teams like L.A., Chicago, and Minnesota cheap nhl jersey selling that area, they're replica NFL jerseys, NHL jerseys likely to find someone they can work with.cheap nba jersey Portland, Houston failed to shifts lebron james jersey back to Houston for Game 6 on Thursday as the Rockets scurry to make Jordan jerseys adjustments cheap nhl jerseys of the Blazers cheap ugg boots Grizzlies, and it's been mentioned that that pick could be had as well. Most teams looking to buy in are looking to buy into cheap ugg bootsthe late first/early second round. Memphis has picks potentially available in both those areas.cheap mlb jerseys Timberwolves use all three of their first round picks this year (6-18-28), and while it's all but certain they'll use cheap true religion jeanstheir #6 pick and probably the #18, that #28 could absolutely be had. For teams looking to buy into that part of the draft (see below), the Wolves cheap nhl jerseys

  • Counterfeit hater (unregistered)

    Whats up with the spam for counterfeit fake jerseys? Cityoriginal.com sells nothing but fake counterfeit jerseys made in china. Buyer beware. Someone needs to remove this junk.

Leave a comment on “The Long Road to Clean Up”

Log In or post as a guest

Replying to comment #111318:

« Return to Article