Comment On Converting Apples to Oranges

In high school I'd spend most of my time in math class playing with my calculator. It had all sorts of fancy conversion functions that were mostly accurate, and simplified work that I'd rather not do myself. One undocumented (and fun) feature was that the conversion functions weren't limited in scope, meaning that I could, for example, convert hours to milliliters or inches to degrees celcius. [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: Converting Apples to Oranges

2007-05-30 09:04 • by Cyrus (unregistered)
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.

Re: Converting Apples to Oranges

2007-05-30 09:06 • by Daniel Migowski (unregistered)
Yes, it really is a wtf to name a function with the first letter up:

-> Logger.TraceError

Re: Converting Apples to Oranges

2007-05-30 09:08 • by ParkinT
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.

Re: Converting Apples to Oranges

2007-05-30 09:09 • by ParkinT
Alex,
The title should be: Converting Apples to 734552

Re: Converting Apples to Oranges

2007-05-30 09:18 • by Charlie (unregistered)
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.

Re: Converting Apples to Oranges

2007-05-30 09:26 • by Andy (unregistered)
139231 in reply to 139227
ParkinT:
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.


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.

Re: Converting Apples to Oranges

2007-05-30 09:32 • by real_aardvark
139232 in reply to 139229
Charlie:
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.

Add meaningful explanation.
Stir.
Repeat until warm.

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!"

Re: Converting Apples to Oranges

2007-05-30 09:38 • by Nick (unregistered)
Of course, if a valid input to the control is "0"...

Re: Converting Apples to Oranges

2007-05-30 09:43 • by Kemp
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.

Re: Converting Apples to Oranges

2007-05-30 09:43 • by Chemisor
So are all future submissions going to be printed out emails photographed on a wooden table?

Re: Converting Apples to Oranges

2007-05-30 09:45 • by Mac (unregistered)
139237 in reply to 139226
Daniel Migowski:
Yes, it really is a wtf to name a function with the first letter up:

-> Logger.TraceError

Actually its called a coding standard. The generally accepted C# standard is just different from Javas is all

Re: Converting Apples to Oranges

2007-05-30 09:45 • by James (unregistered)
Not a WTF!
It's converting user input to a double or an int.

Re: Converting Apples to Oranges

2007-05-30 09:49 • by nightfist (unregistered)
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.

Re: Converting Apples to Oranges

2007-05-30 09:49 • by brazzy
139241 in reply to 139232
real_aardvark:

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?

He's actually converting the CONTENTS, the user input, of the control to double or int.

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.

Re: Converting Apples to Oranges

2007-05-30 09:51 • by aeternus (unregistered)
139242 in reply to 139232
real_aardvark:
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.


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:
- pass textbox.Text instead of textbox
- use TryParse
- name the method "ReadControlTextAsDouble"
but all in all I think this submission doesn't qualify even as a lame wtf.

btw. I'm not sure how it compiles (assuming it's .net) because Control doesn't have a Text member, it must implement ITextControl.

Re: Converting Apples to Oranges

2007-05-30 09:53 • by dkf (unregistered)
139243 in reply to 139238
James:
Not a WTF!
It's converting user input to a double or an int.
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!)

Re: Converting Apples to Oranges

2007-05-30 09:57 • by BlueCollarAstronaut (unregistered)
139244 in reply to 139238
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).

Re: Converting Apples to Oranges

2007-05-30 10:00 • by morry
the real wtf(tm) is that neither Tony nor Alex own an OCR scanner.

or did I miss the point?

Re: Converting Apples to Oranges

2007-05-30 10:00 • by Simon Bradley (unregistered)
139247 in reply to 139226
Daniel Migowski:
Yes, it really is a wtf to name a function with the first letter up:

-> Logger.TraceError


Log (as it was in the submission) is a class, and TraceError is a static method implemented by that class.

Re: Converting Apples to Oranges

2007-05-30 10:03 • by RON (unregistered)
139248 in reply to 139227
ParkinT:
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.


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.

Re: Converting Apples to Oranges

2007-05-30 10:11 • by db2
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.

Re: Converting Apples to Oranges

2007-05-30 10:11 • by java.lang.Chris;
139250 in reply to 139229
Charlie:
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.


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?

Re: Converting Apples to Oranges

2007-05-30 10:14 • by RON (unregistered)
139251 in reply to 139232
real_aardvark:
Charlie:
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.

Add meaningful explanation.
Stir.
Repeat until warm.

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!"



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.

Re: Converting Apples to Oranges

2007-05-30 10:16 • by James (unregistered)
139252 in reply to 139243
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 :-)

Re: Converting Apples to Oranges

2007-05-30 10:20 • by Anonymous (unregistered)
139253 in reply to 139250
java.lang.Chris:
And what's with the fscked up capitalisation in C#/.Net?


CamelCase with InitialCaps has been standard Microsoft style since the Windows 1.0 API, and they've kept it through C, C++, and .NET.

Re: Converting Apples to Oranges

2007-05-30 10:23 • by Sven (unregistered)
139254 in reply to 139242
aeternus:
btw. I'm not sure how it compiles (assuming it's .net) because Control doesn't have a Text member, it must implement ITextControl.

Control does have a text member, at least in Windows Forms. ITextControl is ASP.NET only.

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.

Re: Converting Apples to Oranges

2007-05-30 10:30 • by RON (unregistered)
139256 in reply to 139250
java.lang.Chris;:
Charlie:
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.


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?


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.

Re: Converting Apples to Oranges

2007-05-30 10:35 • by real_aardvark
139257 in reply to 139241
brazzy:
real_aardvark:

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?

He's actually converting the CONTENTS, the user input, of the control to double or int.

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.

Oops, my bad. And my apologies.

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?

Re: Converting Apples to Oranges

2007-05-30 10:37 • by nausea (unregistered)
I do love a good wooden table...

Re: Converting Apples to Oranges

2007-05-30 10:39 • by foo (unregistered)
139259 in reply to 139251
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:

bool isNumeric(string some_string)
{
try
{
double atof(some_string);
return true;
}
catch ()
{
return false;
}
}


Re: Converting Apples to Oranges

2007-05-30 10:40 • by rgz (unregistered)
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...

Re: Converting Apples to Oranges

2007-05-30 10:41 • by Look at me! I'm on the internets (unregistered)
139261 in reply to 139241
brazzy:


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.


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.

Re: Converting Apples to Oranges

2007-05-30 10:47 • by Look at me! I'm on the internets (unregistered)
139265 in reply to 139248
RON:


He's not parsing the name, he's parsing the .Text field, which every .NET control has (but not every .NET control utilizes).


I just checked the Control class out. There is no .Text field.

Re: Converting Apples to Oranges

2007-05-30 10:49 • by Shinobu (unregistered)
Hehe... in VB you can happily go:
Dim D As Date

On Error Goto InvalidInput
D = MyTextBox
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.

Re: Converting Apples to Oranges

2007-05-30 10:49 • by fanguad (unregistered)
139267 in reply to 139256
Charlie:
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?

java.lang.Chris;:
Java's capitalization is retarded (as is everything else in the entire language). .NET fixed it (as it fixed everything that Java got wrong).


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.

Re: Converting Apples to Oranges

2007-05-30 10:50 • by Anon (unregistered)
139268 in reply to 139259
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.

Re: Converting Apples to Oranges

2007-05-30 10:53 • by Anon (unregistered)
139269 in reply to 139265
Look at me! I'm on the internets:
RON:


He's not parsing the name, he's parsing the .Text field, which every .NET control has (but not every .NET control utilizes).


I just checked the Control class out. There is no .Text field.


Funny, I just checked it and found it straight away:

http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.text.aspx

Re: Converting Apples to Oranges

2007-05-30 10:54 • by Jim (unregistered)
139270 in reply to 139245
morry:
the real wtf(tm) is that neither Tony nor Alex own an OCR scanner.

or did I miss the point?


Because OCR is well known for coping ever so well with code, and not introducing more WTFs along the way...?

Re: Converting Apples to Oranges

2007-05-30 10:55 • by RON (unregistered)
139271 in reply to 139250
java.lang.Chris;:
Charlie:
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.


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?


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.

Re: Converting Apples to Oranges

2007-05-30 10:58 • by RON (unregistered)
139272 in reply to 139265
Look at me! I'm on the internets:
RON:


He's not parsing the name, he's parsing the .Text field, which every .NET control has (but not every .NET control utilizes).


I just checked the Control class out. There is no .Text field.



Then I suggest you go look again.

System.Windows.Forms.Control.Text.

Re: Converting Apples to Oranges

2007-05-30 11:12 • by dolo54 (unregistered)
NO NO THE REAL WTF IS... wait for it...











snailmail!

Re: Converting Apples to Oranges

2007-05-30 11:19 • by java.lang.Chris;
139280 in reply to 139256
RON:
java.lang.Chris;:
Charlie:
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.


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?


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.


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?

Re: Converting Apples to Oranges

2007-05-30 11:21 • by Saladin
139281 in reply to 139259
foo:
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:

bool isNumeric(string some_string)
{
try
{
double atof(some_string);
return true;
}
catch ()
{
return false;
}
}



People who use an exception handler as part of their business logic make baby Cthulhu cry.

Re: Converting Apples to Oranges

2007-05-30 11:21 • by java.lang.Chris;
139282 in reply to 139267
fanguad:
Charlie:
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?

java.lang.Chris;:
Java's capitalization is retarded (as is everything else in the entire language). .NET fixed it (as it fixed everything that Java got wrong).


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.


Could you get that attribution right? "Charlie" was the fuckwit who made the retarded comment about Java.

Re: Converting Apples to Oranges

2007-05-30 11:37 • by NS (unregistered)
139286 in reply to 139280
Use the anchors. You can make any form resize gracefully if you try.

Re: Converting Apples to Oranges

2007-05-30 11:42 • by Twon
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.

Re: Converting Apples to Oranges

2007-05-30 11:43 • by monkeytrousers (unregistered)
I don't think there is anything wrong with using String.Replace(" ",""). Using String.Trim is less efficient

Re: Converting Apples to Oranges

2007-05-30 11:43 • by Murf (unregistered)
Isn't the real WTF that the guy sent an email code-sample by post?

Re: Converting Apples to Oranges

2007-05-30 11:56 • by KattMan
139295 in reply to 139289
Murf:
Isn't the real WTF that the guy sent an email code-sample by post?


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!

Re: Converting Apples to Oranges

2007-05-30 12:03 • by John (unregistered)
Hi, I've actually seen the context of this code so can provide some insights.

1. The method is private, but it's in a 5000 line mega class.
2. Zero is a perfectly valid input, which means "arse" is too.
3. They convert controls to numbers. Controls. Not data. Not text. Controls. What's next? Forms? DataSets? How about "AssemblyToDecimal"? See where I am going here? ;-)
« PrevPage 1 | Page 2 | Page 3Next »

Add Comment