- 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
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.
Admin
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);
Admin
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!
Admin
string.ToString().ToString()
you know.. just in case.
Admin
Its a multi-layered WTF:
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.
Admin
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
Admin
Admin
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?)
Admin
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
Admin
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 FileI 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.
Admin
I've found that the MSDN documentation for .NET is fairly reasonable, as long as you use Google to search it of course.. ;)
Admin
Another way to do what he wated in .NET (without using IO.Path.GetFileName(x)): result=parts[parts.Split("\").UBound()];
Admin
That's just horrible and wrong in so many ways. Decidedly Lovecraftian...
Admin
strrchr(fullPathName, '\') + 1;
Too bad this isn't C.
Admin
WTF is:
static { typical construct }
syntax?
C, NOT C++, programmer here, wondering...
Admin
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).
Admin
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:
Admin
Or any other language.. in PHP I'd use strrpos.
Admin
i++ ????????? a slight typo, should be perhaps ptr++ ? :p
Admin
Admin
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.