• 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.

  • Daniel Migowski (unregistered)

    Yes, it really is a wtf to name a function with the first letter up:

    -> Logger.TraceError

  • (cs)

    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.

  • (cs)

    Alex, The title should be: Converting Apples to 734552

  • 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.

  • Andy (unregistered) in reply to ParkinT
    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.

  • (cs) in reply to Charlie
    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!"

  • Nick (unregistered)

    Of course, if a valid input to the control is "0"...

  • (cs)

    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.

  • (cs)

    So are all future submissions going to be printed out emails photographed on a wooden table?

  • Mac (unregistered) in reply to Daniel Migowski
    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

  • James (unregistered)

    Not a WTF! It's converting user input to a double or an int.

  • 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.

  • (cs) in reply to real_aardvark
    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.

  • aeternus (unregistered) in reply to real_aardvark
    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.

  • dkf (unregistered) in reply to James
    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!)

  • BlueCollarAstronaut (unregistered) in reply to James

    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).

  • (cs)

    the real wtf(tm) is that neither Tony nor Alex own an OCR scanner.

    or did I miss the point?

  • Simon Bradley (unregistered) in reply to Daniel Migowski
    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.

  • RON (unregistered) in reply to ParkinT
    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.

  • (cs)

    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.

  • (cs) in reply to Charlie
    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?

  • RON (unregistered) in reply to real_aardvark
    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.

  • James (unregistered) in reply to dkf

    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 :-)

  • Anonymous (unregistered) in reply to java.lang.Chris;
    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.

  • Sven (unregistered) in reply to aeternus
    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.

  • RON (unregistered) in reply to java.lang.Chris;
    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.

  • (cs) in reply to brazzy
    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?

  • nausea (unregistered)

    I do love a good wooden table...

  • foo (unregistered) in reply to RON

    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;
      }
    }
  • 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...

  • Look at me! I'm on the internets (unregistered) in reply to brazzy
    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.

  • Look at me! I'm on the internets (unregistered) in reply to RON
    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.
  • 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.

  • fanguad (unregistered) in reply to RON
    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.

  • Anon (unregistered) in reply to foo

    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.

  • Anon (unregistered) in reply to Look at me! I'm on the internets
    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

  • Jim (unregistered) in reply to morry
    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...?

  • RON (unregistered) in reply to java.lang.Chris;
    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.

  • RON (unregistered) in reply to Look at me! I'm on the internets
    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.

  • dolo54 (unregistered)

    NO NO THE REAL WTF IS... wait for it...

    snailmail!

  • (cs) in reply to RON
    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?

  • (cs) in reply to foo
    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.
  • (cs) in reply to fanguad
    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.

  • NS (unregistered) in reply to java.lang.Chris;

    Use the anchors. You can make any form resize gracefully if you try.

  • (cs)

    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.

  • monkeytrousers (unregistered)

    I don't think there is anything wrong with using String.Replace(" ",""). Using String.Trim is less efficient

  • Murf (unregistered)

    Isn't the real WTF that the guy sent an email code-sample by post?

  • (cs) in reply to Murf
    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!

  • 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? ;-)

Leave a comment on “Converting Apples to Oranges”

Log In or post as a guest

Replying to comment #:

« Return to Article