- 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
You mean like this
~Tim
Captcha: creative -- Not Very!
Admin
string strPoster = "a/b/c/d/e/f/g/h/fist!"; string retval = ""; foreach( string s in strPoster.Split( "/" ) ) retval = s; Console.WriteLine( retval ); // CAPTCHA: craptastic
Admin
You need to write shorter code to achieve that goal.
Admin
Looks like the predecessor was bored at work (we've all been there at least once) and was entertaining him/herself by finding creative ways to do the mundane.
captcha: java (Hey! I resent that, Alex!)
Admin
Admin
too bad that also / can be used as a path separator...
Admin
Admin
I've never used .Net, so can someone tell me what the @ in front of the string means?
Admin
well, with .NET it is quite okay to trust on backslashes as path separator I guess...
Admin
I don't get the WTF.
Admin
It means you don't interpret \ as escaping another character. @"\n" is interpreted as the string containing two characters '' and 'n' and not a string containing a single newline.
Admin
Not if you want to use mono in a linux environment.
Admin
It means someone was thinking of Cocoa when they wrote the framework,
Admin
Admin
Admin
Yeah the loop is a real WTF, but due to the mass of lib functions in .net, I am sure most of us reimplementet at least one of them.
J.
Admin
Not to mention the use of Regex instead of just fullPathName.Split(Path.DirectorySeperatorChar), the use of ToString() on probably a string and ofcourse the overwriting of the same variable to keep the last one.
Admin
Admin
Why does he use @"\" then, shouldn't that be either @"" or "\" to separate paths? Could be just a typo in the article though?
Admin
Nope, he wanted two backslashes - this is a regex, don't forget.
Admin
I found this in my first weeks at a new job:
Which, of course, can be replaced by:
String processing version of this array wtf...
Admin
Because the "" is an escape character in regular expressions, he was escaping the slash.
Admin
This isn't a WTF.
In terms of Big-O, his solution is probably equivalent to the array construction routine.
Modern API sets are big, so it may have been faster for him to regex and iterate in thirty seconds rather than research for ten minutes for an equivalent call, especially if it's in another package.
Furthermore, you can readily tell what he's doing in the code. No obfuscation by stupidity.
Admin
It could be worse, they could have offshore developers actively creating and indexing into arrays for no reason.
versus the shorter but somehow inferior I wish I was kidding.Admin
While I understand the function of the @ for string literals, I find this syntax a bit of a clutter... Why not stick to single and double apostrophe convention used in many languages (php, ruby, and others)?
captcha says it's bedtime. But I'm wide awake!
Admin
Single quotes are for character literals, while double quote are for strings.
CAPTCHA: initech (huh?)
Admin
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.
Admin
LOL
Admin
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.
Admin
Explanation #1: In Cish languages, that syntax is already used for character constants, and might thus lead to confusion. Explanation #2: That syntax wasn't invented in Redmond and is actively used by child-eating wild-eyed open source communists.
Captcha: billgates (I swear!)
Admin
The way he's doing string splits is a bit odd.
ignoring the System.IO.Path.GetFileName()
string[] parts = fullPath.Split('');
CAPTCHA : pizza ... yum
Admin
There is nothing wrong in not knowing some nitty little function a FCL might have (because it is mostly language dependent) ... and I dont beleive in smiling at somebody's lack of language specific skills (unless ofcourse he's rated himself 10/10 on that particular language)
The "WTF" factor really was this -- foreach (string part in parts) result=part.ToString();
Admin
Wow, this is familiar. I think I can do you one better though.
Enjoy.
Admin
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.
Admin
Nice to see he's making .NET even more cross-platform than it was before.
Admin
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.
Admin
Has anybody ever found their own code on here before? Has anybody admitted to it?
Admin
LOOOOOOOOOOOOOOOOL ! Are you kidding or trolling ? Seems not, so i can not help but quick reply :o)
Even though you he does not know the existence of the getFileName method, any young developer would know that it exists somewhere. You may spend 10 minutes finding it, but then you do not spend 100 times 1 minute to write this code plus 50 times 15 minutes to debug it !
Even more, instead of looking for it, this guy creates a regex. Regex is not such a lightweight object, i don't know in .NET but in java the string would go throug a regex compiler, and anyway a regex interpreter is overkill if what you want is just find the last .
So, even though you want to develop it by yourself, you can simply reverse scan the string looking for . Once you find it (or not then you stop at index 0), then you can extrapolate the filename.
This WTF is the result of a massively tired and/or stupid developper. The former can easily be cured by some hours of sleep, i suspect curing the later can take substantially more effort during the course of years, for no guaranteed result...
Your exercise for WTFing over a WTF (WTF^2 seems to be your IT level): you write the corresponding code 10 times ;o)
Chris
PS : Alex, i think you should open a new website namely www.thedailywtfwtf.com in order to take advantage of the numerous WTFs in the forums. Or at least have a special dedicated page, we could even easily vote for comment "promotion", just add a "WTF" button next to the "comment" and "quote" ones, i would loooooooooooooove it ! :o)
Admin
If you must use a Regex, why not @".*\" ?
I don't know .NET but if they are like C,Perl,Java,vi,sed regular expressions than match everything up to and including the last backslash.
Admin
The first time I had to do Path processing, I went into the Java libs and dug around and found some stuff that helped, mainly because it's a royal pain. I don't recall whether I wrapped that stuff in a class or not, but why would anyone just go reimplement that?
Admin
Or, just use fullPath.LastIndexOf("") to return, conveniently enough, the last index of the specified character.
Admin
But the goal is to develop it by yourself, and not to use these library methods that you need to search for 5 minutes in the documentation ;o)
Admin
Isn't Intellisense Wonderful? Not only can you see what methods and properties are available, you can get it to type it for you.
And yes, I realize that there are people masochistic enough to write C# code in Emacs, but still!
Ooooh - poprocks? Where's my Coke!?!?
Admin
Somebody a few posts up claimed that the @ in front of a string means "dont escape any characters in this string" -- completely wrong of course, but it spurred somebody else to ask why the string was @"\" if @ turns off escaping.
My favorite WTFs are the ones written in these comments.
Admin
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:
char *ptr = fullPathName; while( (ptr++) != 0); while((ptr-1) != '/' && --ptr != fullpath ); result = new String( ptr) ;
Admin
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?
Admin
I would hate to think how many miles you would walk for a complex solution.
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.
Admin
Admin
Although it makes no sense in this case, I've seen it used as a lazy man's way of asserting that the string is not null.
captcha: billgates (my "boss")
Admin
Now, that's good humour!