|
|
|
| Non-WTF Job: C++ Developer at Good Grievance (Ronkonkoma, NY) |
| « Prev | Page 1 | Page 2 | Next » |
|
You mean like this
~Tim Captcha: creative -- Not Very! |
Re: The Long Road to Clean Up
2007-01-11 09:07
•
by
joe.edawrds@imaginuity.com
(unregistered)
|
|
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 |
Re: The Long Road to Clean Up
2007-01-11 09:20
•
by
dave_v
(unregistered)
|
You need to write shorter code to achieve that goal. |
|
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!) |
Where? All I know is new System.IO.FileInfo(fullpathname).Name; |
|
too bad that also / can be used as a path separator...
|
Re: The Long Road to Clean Up
2007-01-11 09:35
•
by
IceFreak2000
|
System.IO.Path.GetFilename(fullpathname) |
|
I've never used .Net, so can someone tell me what the @ in front of the string means?
|
Re: The Long Road to Clean Up
2007-01-11 09:49
•
by
wonko
(unregistered)
|
|
well, with .NET it is quite okay to trust on backslashes as path separator I guess...
|
|
I don't get the WTF.
|
Re: The Long Road to Clean Up
2007-01-11 09:51
•
by
derobins
(unregistered)
|
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. |
Re: The Long Road to Clean Up
2007-01-11 09:58
•
by
Fabian
(unregistered)
|
Not if you want to use mono in a linux environment. |
Re: The Long Road to Clean Up
2007-01-11 10:00
•
by
leeg
(unregistered)
|
It means someone was thinking of Cocoa when they wrote the framework, |
To name two: - Reimplementing a system function - Iterating through an array and repeatedly overwriting a variable, instead of just assigning it once (see the first reply) |
Thank you. |
|
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. |
|
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.
|
To clarify, that's nothing to do with .NET. It's a feature of C# string literals. |
Re: The Long Road to Clean Up
2007-01-11 10:36
•
by
Anonymous
(unregistered)
|
Why does he use @"\\" then, shouldn't that be either @"\" or "\\" to separate paths? Could be just a typo in the article though? |
Re: The Long Road to Clean Up
2007-01-11 10:38
•
by
Jon Skeet
(unregistered)
|
|
Nope, he wanted two backslashes - this is a regex, don't forget.
|
|
I found this in my first weeks at a new job:
Which, of course, can be replaced by: filename = IO.Path.GetFileName(filename) String processing version of this array wtf... |
Re: The Long Road to Clean Up
2007-01-11 10:44
•
by
Inkstain
(unregistered)
|
Because the "\" is an escape character in regular expressions, he was escaping the slash. |
|
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. |
|
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. |
|
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! |
Re: The Long Road to Clean Up
2007-01-11 11:18
•
by
SpiritOfGrandeur
(unregistered)
|
Single quotes are for character literals, while double quote are for strings. CAPTCHA: initech (huh?) |
|
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. |
LOL |
|
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.
|
Re: The Long Road to Clean Up
2007-01-11 12:04
•
by
AdT
(unregistered)
|
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!) |
|
The way he's doing string splits is a bit odd. ignoring the System.IO.Path.GetFileName() string[] parts = fullPath.Split('\'); CAPTCHA : pizza ... yum |
|
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(); |
|
Wow, this is familiar. I think I can do you one better though.
//find which site we're using: 1. Note that none of these uses of the regular expression engine are even necessary. 2. In fact, you don't even need to use strpos for that inner if condition. You can just compare directly with == . 3. Using "continue" is also totally unnecessary. 4. Just so the readers knows, "count($site_arr) - 2" is always, always, always 2. 5. In fact, the base path is always /var/www. Enjoy. |
|
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.
|
|
Nice to see he's making .NET even more cross-platform than it was before.
|
Re: The Long Road to Clean Up
2007-01-11 12:40
•
by
Neomojo
(unregistered)
|
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. |
Re: The Long Road to Clean Up
2007-01-11 13:00
•
by
spamparranoid
(unregistered)
|
|
Has anybody ever found their own code on here before? Has anybody admitted to it?
|
Re: The Long Road to Clean Up
2007-01-11 13:41
•
by
Chris
(unregistered)
|
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) |
|
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. |
Re: The Long Road to Clean Up
2007-01-11 15:02
•
by
Franz Kafka
(unregistered)
|
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? |
Re: The Long Road to Clean Up
2007-01-11 15:10
•
by
Mike
(unregistered)
|
Or, just use fullPath.LastIndexOf("\") to return, conveniently enough, the last index of the specified character. |
Re: The Long Road to Clean Up
2007-01-11 15:23
•
by
Chris
(unregistered)
|
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) |
Re: The Long Road to Clean Up
2007-01-11 15:54
•
by
Lonely Programmer
(unregistered)
|
|
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!?!? |
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. |
Re: The Long Road to Clean Up
2007-01-11 17:26
•
by
Crotchety Old Guy (on a SunOS 4.1.3 box)
(unregistered)
|
|
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) ; |
Re: The Long Road to Clean Up
2007-01-11 18:01
•
by
another Steve
(unregistered)
|
|
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?
|
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. |
Re: The Long Road to Clean Up
2007-01-11 18:28
•
by
Cowboy Curtis
(unregistered)
|
Which is exactly the question he answered. @ turns off escaping in a string literal, and the extra slash was to get past the escaping of the regex engine. |
Re: The Long Road to Clean Up
2007-01-11 18:29
•
by
Artemus Harper
(unregistered)
|
|
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") |
Re: The Long Road to Clean Up
2007-01-11 18:44
•
by
Javier Martín Domínguez
(unregistered)
|
Now, that's good humour! |
| « Prev | Page 1 | Page 2 | Next » |