- 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 looks more like C#...
FRIST!
Admin
FLIRST! I T HINK THIS IS PHUNNEY
Admin
So, only integers are numeric? So when I count dollars and cents, I'm not using... numbers? Huh?
Admin
The uppercase method names gives a clue as to it being C# and not Java.
Admin
so the real WTF a usual is that people write far too much code to do string parsing, usually because the library doesn't directly support every case you wish to manage.
Might not be the best way to do these but they probably filled a purpose needed at the time to get up and running fast.
Putting them into a separate generic place is a good idea, perhaps StringParsingFunctins might be a better one.
Java was always poor at string parsing unless your string is exactly the "one and only" match for the type.
Admin
It's C#. Main clue being that there's no such type as a "bool" in Java (in Java it's "boolean")
Admin
There is no WTF here. These functions give you flexibility to handle cases that apply to your situation that the built-ins may not have. Putting them in one class supports easy refactoring. Also, this is a common and reasonable solution when the best available programmer is someone unfamiliar with all of the built in functions of a language. We get paid to get a good enough job done as efficiently as possible. Writing the world's greatest code is often contrary to that. The side effect is that experienced programmers often have to go in and clean up someone else's mess to add new features that the original planners could not have possibly foreseen. It is what we are paid to do. Deal with it or pick another career.
Admin
no... TRWTF is that everything he wrote is supported directly by the string library (except that null string thing). The null string thing can be handled like this: var someVal = stringArg ?? ""; basically... this fool needed to look busy so he set about reinventing the wheel day in and day out. I suppose it beats spending all day on wtf.com :p
Admin
double.TryParse(...) and other such interfaces make adequet substitutions as well.
Admin
True... but implicit with the role of programmer is a subtle expectation of having at least some degree of common sense.
Captcha: transverbero - a verb that looks one way but goes another.
Admin
I agree with Mr. Time and Space here. Code monkeys, as a breed, are far too eager to start shooting down everybody else's thinking. I believe it's because a lot of us have insecurities about our own abilities and by shooting first all the time it deflects attention from our own weaknesses and makes us feel better about ourselves. It's the one part of this field that really irks me. It's in other fields, too, but it seems to be rampant around programming in general.
Admin
c/c++ use bool ;P... though member signatures are different.
Admin
That's exactly what I was talking about in my last post. This person did something slightly different than I would have, therefore they are a complete idiot devoid of any common sense whatsoever. Wow - get over yourself dude.
Admin
I like the fact that -12 somehow isn't numeric.
Admin
you are taking this quite personally. You rename a handful of CLR functions in your past? :p
So this isn't a WTF like an infinate recursion loop... but there is nothing wrong with laughing at someone for basically renaming library functions or writing inferior ones to use in place of those that are built in.
Admin
Someone should have taught this guy how to use temporary variables:
string trimmedValue = value.ToString().Trim();
But the level of paranoia is really high.
Admin
What I find truly frightening is this
public static string ReturnEmptyStringIfNullElseValue(string value)
// MY PARAMETER, which is strongly typed as a string // IS NOT NULL, so now I just need to make sure it is // STILL A STRING! return value.ToString().Trim();
Admin
Admin
I find it funny how close to python code the method name "ReturnEmptyStringIfNullElseValue" is.
Admin
And I should become a career counselor :)
Admin
I don't see a WTF in the first method. I have one of those myself (in VB.NET, where there is no ?? operator). Of course, you could write it with the ?? operator, but not too many people know about that one.
edit - I now know that I can use the If() method in those cases. You learn something new everyday.
As far as the others, what is the built-in function for removing $ and , from strings to get an integer value?
I'll give you a WTF for the IsNumeric function. If he didn't want to use TryParse, then he could have included the VB library and called VB's old IsNumeric function.
Admin
The lack of a ternary operator is one of my biggest pet peeves in VB. That and the general lack of operator overloading.
Admin
UNICORNS!!!!!
*edit, no this is not spam...
Admin
int i = a < b ? 1 : 2; Dim i = If(a < b, 1, 2)
Public Shared Operator +(lhs As Integer, rhs As Integer) As Integer Return lhs + rhs End Operator
Admin
If() is computationally the same as the ternary operator, but it is not a ternary operator. The ternary operator is cleaner in terms of syntax, in my opinion.
Admin
hey, if this is a Remy post were are the HTML comments? Unicorns are not enough, you should now that Remy
Admin
You can do this in one line in Haskell
Admin
It's a little hard to insert good HTML comments in a CodeSOD.
Admin
Seriously? I'm a tester (OK, an SDET) and even I know that C# has a null coalescing operator. Any developer who can't even be bothered to familiarise themselves with simple features of their chosen language needs to get a new job. I hear the helpdesk are hiring.
Admin
maybe string.IsNullOrEmpty() did not occur to him.
Admin
There are redundant ToString() calls throughout the code. There's also a fear of having a local copy of the data you're working on.
The only WTF I see is the duplication of IsNumeric(). Everything else is simply inefficient but unlike what some posters have said it does NOT simply redo the library.
Admin
I'm just saying it would be more productive if people could point out the flaws of others without having to call them idiots or morons. I mean, I could sit here say "you're an idiot because you can't spell the word infinite" but it would be more constructive to stay focused on the correct way of doing it and not wasting time denigrating the person that you are trying to correct. Too many people act as though they have never made a mistake or done something in a less-than-optimal way, which is ridiculous.
Admin
+1
btw, how's your son?
Admin
From an immediate viewpoint the only one that really looks WTF'y is the last one.
I'm a C++ programmer and don't know C# and how those functions are total rewrites. It's difficult to know exactly what they are doing anyway. What are all these '$' signs doing there? Parsing amounts of money?
I'm sure the C# library has much better string parsing options than C++ (istringstream, oh dear is that the best we can do? boost::lexical_cast wrapper of that throwing unhelpful exception when it fails..)
Now let me explain a concept: objects get printed to strings. But strings don't get loaded into empty objects, strings are parsed by factories which create objects. And it isn't a one-to-one relationship in either direction.
Incidentally the lack of a hexadecimal point is a WTF in C++ and C# although I think C99 supports it.
Admin
By my recollection the TryParse() methods were not introduced until .NET 2.0. For all we know this code was written in .NET 1.0 or 1.1, in which case you pretty much had to roll your own IsNumeric (unless you leveraged the Microsoft.VisualBasic namespace, which I personally preferred not to do).
The real WTF is that developers never take into account under what circumstances the code was written. Maybe the developer was using an older version, maybe his boss was hounding him to "just get it done."
There are plenty of things in this business to make fun of, but these examples aren't as egregious as the story makes them out to be.
Admin
That first function is horrendously over complicated for what it says it does.
notNullString = ReturnEmptyStringIfNullElseValue(someString);
notNullString = someString ?? string.Empty;
Now it might just be because I actually know the language, but I find the second version much more readable.
Admin
Also, its a function, so both arguments will be evaluated.
In C# you can write:
(a == 1) ? b() : c();
In VB
IIf(a = 1, b(), c())
will call both b() and c(), but only return one result!
Admin
The given functions are not perfect. But there is no WTF. The writer of that code might lack experience or tuition. Anyway, the code shall work, is readable and not horrible inefficient.
Since that the real WTF is the fellow 'Ben'. His mention those examples as WTF is an proof that Ben is a arrogant, autocratic goof.
A self-opinionated mind is one of the saves ways into programers hell.
Admin
I'm sure it's no laughing matter.
Admin
Java/C# With First Letter Of Function Capatalized. Twitch.
NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOoooooooooooooooooooooooooooooo.............
Admin
Ok, an obvious WTF is calling value.ToString() when value is already a string. I assume that all classes inherit from Object() and must have a ToString() method so string also has one, which probably just is implemented as "return this;"
It is quite common in C++ too to have a template to convert things to string and then provide an overload / specialization for strings. At least in C# you don't have the WTF'ery of having to deal with two types of character that might form a string.
Incidentally in C++ if you do this
It is not just inefficient for T=std::string, it doesn't work properly..
and parsed will be just "Hello"
Doing this for a large array of ints is bad too in that you create a stringbuf for every single one and don't reuse it.
Admin
What if this code was written before nullable types were added to the language?
Admin
It's better not to program than to program in that jiberish.
Admin
Obviously. And I enjoy very much ... mocking my own stupidity every opportunity I get. Spelling is usually my problem however... and it has lead to some rather funny situations involving application wide updates and renames. Flatulantly for me... Microsoft added some safeguards for just such an eventuality.
I suppose I don't remember calling anyone an idiot on this thread however.
Someone wrote that the user was not substituting pre-existing functionality... and I argue that every method was a substitution of pre-existing syntax and/or built in library methods. So hurry up and (CAPTCHA: AUGUE) with me.
Admin
Usually bozos like that are not qualified for ANY IT job.
Admin
Admin
But calling string.ToString() is indefensible. Whiskey. Tango. Foxtrot.
Admin
He was using TryParse methods, therefore he was using at least 2.0.
I can see entering .NET using VB, but sticking with it after 10 fucking years of development is just plain stupid - even if the company can't or doesn't allow the switch (move the fuck on). If you're still with VB.NET, you are a moron and incompetent programmer by definition.
"Just get it done" attitude would need to result in inline "if null set "" else set value" pattern - versus writing some confusingly named and what-the-fuck-that-this-function-really-do-let-me-look-it-up-every-time-cause-it-is-impossible-to-remember-ever functions.
What other excuses can you think of?
Admin
Also, the "out" keyword is only used in C# I believe. Not java or c/c++.
Admin
Stated it before and will state it again: Bob and i are not related!
Neither am i his son nor is he my uncle!