- 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
What in the world is this even trying to do? I'm not familiar enough with C# (which I assume this is) to get it's WTF gooey goodness.
As best I can tell though it gets the name of the control, parses it and returns the name in integer form?
Nice wooden table btw.
Admin
Yes, it really is a wtf to name a function with the first letter up:
-> Logger.TraceError
Admin
It is so useful to Parse the name of a control and then return that string converted to a number! So useful, in fact, that a separate function was created; leading me to believe it gets called multiple times throughout the project.
Admin
Alex, The title should be: Converting Apples to 734552
Admin
The guy converted the Text member of the control to an integer/double. These functions were most likely helper functions for use throughout the entire application that he would use when he had TextBoxes on whatever form that needed user input. Using these functions, he could avoid crashing the program because of bad user input and could reuse the code. Probably before Double.TryParse and Int32.TryParse existed.
Admin
It's not parsing the name, but the text portion of the control. So for a textbox it would be the text, for a form it's the title bar, and so on.
Admin
Um... run that past me one more time, please? And could you add a specific example of why anybody would wish to convert a control to a Double? Ever? I mean, I've heard of Santa's little helpers, but this is more a case of Satan's little helpers.
Shame there's no Ordinal. Parse(Control), though. At least that would help in winnowing out people who insist on posting "First!"
Admin
Of course, if a valid input to the control is "0"...
Admin
It gets the text that a user has entered and converts it to a number. Pretty simple stuff. You want the user to enter a seed for an RNG, the number of times they took a leak today, whatever, it's going to be entered as text and you want it eventually as a number.
Admin
So are all future submissions going to be printed out emails photographed on a wooden table?
Admin
Admin
Not a WTF! It's converting user input to a double or an int.
Admin
The problem here is the naming of the methods. The name implies that a control is converted.
The use of this methods is to convert the Text of control (most likly Textbox, Combobox, etc) to an integer.
So the only WTF I see here is the naming of the methods.
Admin
The real WTF is NOT the methods' names or parameter types - that's reasonable in order to keep the get-contents-and-strip-blanks in one place as well, though the names could have been chosen better.
The real WTF is that he didn't use the numerical controls that I am sure even C# has, which make it impossible to enter anything except a number, handle parsing internally and give you the result via a getter method.
Admin
Did you notice the "ctrl.Text" part? He's not converting the control but its text.
Suppose you have a page with n>30 textboxes that you enter some floating-point values into. Using the conversion method you can easily read them into double variables.
Sure, the more elegant solution would be to either:
btw. I'm not sure how it compiles (assuming it's .net) because Control doesn't have a Text member, it must implement ITextControl.
Admin
CAPTCHA: dubya (who thinks this sort of naming convention is a good idea!)
Admin
But one thing that's kind of goofy is that it takes the control as a parameter.
Odds are, someone is not going to want to convert just any ole' control's text to a double or an int (for example a radio button or an imagelist), and it's quite possible that someone might wish to use these for more than just control-bound text. So why not make the methods more robust and have a string parameter, instead. It's kind of confusing, becuase, for all intents and purposes, it seems to be claiming to convert a control to the respective number type (based on the name of the method and it's input). It's not doing that, though, it's parsing a string....It's not only obfuscating that, it's adding extra hoops through which to jump (you can't just pass in a string, your string must be the text property of a control).
Admin
the real wtf(tm) is that neither Tony nor Alex own an OCR scanner.
or did I miss the point?
Admin
Log (as it was in the submission) is a class, and TraceError is a static method implemented by that class.
Admin
He's not parsing the name, he's parsing the .Text field, which every .NET control has (but not every .NET control utilizes).
For text fields, combo boxes, radio controls, labels, etc, .Text returns the text currently displayed in the control.
Admin
If these two methods were declared public, internal, or even protected, I might be inclined to agree with some of the gripes here. But if they're private, then they're intended for consumption only by the class they're defined in. It's just some shorthand methods used to remove bloat from another part of code within the class that probably needs to parse a bunch of user inputs. Sure, they could stand to be named a bit better, but we aren't anywhere near WTF territory.
I do this kind of helper method stuff all the time with code that needs to read a bunch of database fields and gracefully turn the DBNull results into proper null references. We might as well be lambasting the guy for not putting XMLDoc comments on his private methods.
The "catch (Exception e)" should be more specific, though, I'll grant you that.
Admin
How could he use them throughout the entire application when they're private? And what's with the fscked up capitalisation in C#/.Net? Or is that the deliberate differences they introduced to try and hide the fact that C# and .Net are clones of Java and the JFC?
Admin
It's called "data entry". You see, in these things called "computer programs", there are often "text fields" where users enter "data". Sometimes this "data" is in the form of "text", but other times, this "data" can be in the form of "numbers". Now, these "number" things are tricky, because they can be "negative", or "integral", and even sometimes "real". These "real" numbers can be represented in the system in many ways, one of which include "doubles". Granted, "doubles" aren't very accurate for "financial" and "scientific" purposes, but for almost any other purpose, "doubles" are a perfectly valid way of storing "real numbers". This function is in effect a useful, but poorly-named, method of extracting "double" data from a .NET control, for those times when you want "double" data.
Admin
If the functions had been called something like "GetDoubleFromControl" so that the concept was that the user was retrieving a value from the control, I'd have agreed. Instead, they're named like it is some kind of non-standard cast, which is just bizarre.
CAPTCHA: dubya (who thinks this sort of naming convention is a good idea!)[/quote]
Well I agree and returning 0 is a little odd. But if DailyWTF is now just listing poorly named method I think I alone could keep this website going for a year or 2 :-)
Admin
CamelCase with InitialCaps has been standard Microsoft style since the Windows 1.0 API, and they've kept it through C, C++, and .NET.
Admin
The real WTF is stripping the spaces. I could sort of understand doing ctrl.Text.Trim(), but replacing all spaces with an empty string? Apparently parsing "4 2" into 42 is perfectly alright for this app.
Admin
Java's capitalization is retarded (as is everything else in the entire language). .NET fixed it (as it fixed everything that Java got wrong).
End of story.
Admin
It still looks weird to me, though. What sort of application validates all numerical input as "int" or "double"? Wouldn't "Date" or "Currency" or "PressurePSI" be slighly more relevant?
Admin
I do love a good wooden table...
Admin
Its also possible that, despite the names of the functions, the purpose isn't to actually convert the data to a double, but to validate the input so it can be used as a double later on. A bunch of years ago, I came across something similar in some c++ code. I can't remember the exact code, but it was along the lines of:
Admin
Indeed, this is actually useful code, it extracts a number from a textbox parsed from string to double and prevents the system from blowing up from bad input. It is just badly named.
Weirder are the facts that it returns 0 on exceptions and that this functions are private (and non static! nobody has mentioned that). The return values suggest that in the problem domain of the application, 0 is not a valid input either. (Imagine, how many items are you going to buy? You can't buy 0 items, is not a valid transaction.)
The private and not static thing means that these functions are either copy-pasted everywhere they are needed or they are only used in this class. If they are used only for this class then the funky names are even less dangerous.
The quality of some of these submissions is aproaching the quality of the new site name, at least its still better than the forum software...
Admin
Actually, you can't tell from the code behind page what types of controls he's using. He very well could have attached validators to the controls to ensure that only digits were entered.
Admin
Admin
Hehe... in VB you can happily go:
This will accept almost any date and time format, including the number of days since 30 December 1899. Which is a very odd date to call zero, if you ask me.Admin
Wow, there's some solid logic there. I guess I'll be dropping Java and C# now, and picking up a much better language that avoids these problem altogether - Brainfuck.
Variables with names are for wusses.
Admin
Not really a WTF. There may be better ways to do it depending on the context. As somebody else mentioned there are controls that are designed to only take numbers (like the NumericUpDown control) which might be better. Or you could roll your own control to encapsulate all the parsing and error checking, but that might only be useful if you're going to use it a lot. Or you might be able to use data binding and let it handle all the conversions. The function names are a little confusing, but not totally retarded.
Admin
Funny, I just checked it and found it straight away:
http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.text.aspx
Admin
Because OCR is well known for coping ever so well with code, and not introducing more WTFs along the way...?
Admin
Also, just because they're private, that doesn't mean they're not helper functions inside a larger publicly-available utility class, in which case they could be used throughout the entire program.
Admin
Then I suggest you go look again.
System.Windows.Forms.Control.Text.
Admin
NO NO THE REAL WTF IS... wait for it...
snailmail!
Admin
Riiight. In Java, the convention is that a leading upper case character indicates a class, while a leading lower case character indicates an instance or a method - judging by what I've seen no such distinction is made in C#/.Net. As for your claim that Java's "retarded", that doesn't say much for .Net, which is modelled on the JFC with the notable exception of the Windows.Forms stuff. Speaking of which, has MS finally introduced a layout manager that doesn't rely on absolute positioning and handles resizing gracefully?
Admin
Admin
Could you get that attribution right? "Charlie" was the fuckwit who made the retarded comment about Java.
Admin
Use the anchors. You can make any form resize gracefully if you try.
Admin
Can the C# vs. Java capitalization Nazis make peace with the fact that while Log.TraceError is named in the C# convention, at least convertControl2Double is named in the Java convention? I suppose it's also named in the "text messaging" convention as well, since spelling out "To" wastes a whole extra character.
Admin
I don't think there is anything wrong with using String.Replace(" ",""). Using String.Trim is less efficient
Admin
Isn't the real WTF that the guy sent an email code-sample by post?
Admin
Maybe he doesn't have email, or even an internet connection and has websites printed out for him and dropped on his desk every morning. Or perhaps he doesn't even have a computer and writes code in his head and has it dictated to his secretary!
See now that is leet!
Admin
Hi, I've actually seen the context of this code so can provide some insights.