| « Prev | Page 1 | Page 2 | Page 3 | Next » |
|
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 |
|
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. |
|
Alex,
The title should be: Converting Apples to 734552 |
|
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)
|
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
|
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!" |
|
Of course, if a valid input to the control is "0"...
|
|
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.
|
|
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)
|
Actually its called a coding standard. The generally accepted C# standard is just different from Javas is all |
|
Not a WTF!
It's converting user input to a double or an int. |
|
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. |
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)
|
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)
|
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)
|
|
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). |
|
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)
|
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)
|
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. |
|
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;
|
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)
|
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)
|
|
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)
|
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)
|
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)
|
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
|
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? |
|
I do love a good wooden table...
|
Re: Converting Apples to Oranges
2007-05-30 10:39
•
by
foo
(unregistered)
|
|
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:
|
|
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)
|
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)
|
I just checked the Control class out. There is no .Text field. |
|
Hehe... in VB you can happily go:
Dim D As DateThis 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)
|
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)
|
|
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)
|
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)
|
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)
|
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)
|
Then I suggest you go look again. System.Windows.Forms.Control.Text. |
|
NO NO THE REAL WTF IS... wait for it...
snailmail! |
Re: Converting Apples to Oranges
2007-05-30 11:19
•
by
java.lang.Chris;
|
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
|
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;
|
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)
|
|
Use the anchors. You can make any form resize gracefully if you try.
|
|
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
|
|
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
|
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! |
|
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? ;-) |
| « Prev | Page 1 | Page 2 | Page 3 | Next » |