- 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 submission is a sorry excuse for a WTF. In my books, bad naming doesn't qualify for a WTF too.
Regarding the removing of the spaces, (trimming removes only initial and trailing spaces, right?) I have a feeling this app was written outside the USA.
In South Africa (and I think France too, maybe other countries) formatting a number uses spaces for the 1000s separator and a decimal comma, not decimal point, e.g. 42786.56 = 42 786,56
Of course this is if you set up your regional settings correctly.
So, if he sets Control.Text to a nicely formatted version of the number, he'd want to remove the spaces before before parsing. I don't think the parser is clever enough to recognise the spaces as 1000s separator.
Admin
This submission is a sorry excuse for a WTF. In my books, bad naming doesn't qualify for a WTF too.
Regarding the removing of the spaces, (trimming removes only initial and trailing spaces, right?) I have a feeling this app was written outside the USA.
In South Africa (and I think France too, maybe other countries) formatting a number uses spaces for the 1000s separator and a decimal comma, not decimal point, e.g. 42786.56 = 42 786,56
Of course this is if you set up your regional settings correctly.
So, if he sets Control.Text to a nicely formatted version of the number, he'd want to remove the spaces before before parsing. I don't think the parser is clever enough to recognise the spaces as 1000s separator.
Admin
Sorry for the double post... damn HTTP 502
Admin
Ok. Now check: System.Web.UI.Control
Admin
That is the fault of Lotus 1-2-3, which screwed up the leap year calculations. For backwards compatibility, Excel still does it that way. VB side-stepped the issue by moving the epoc back a day.
Admin
Layout managers were a horrible idea that invariably led to poorly laid out static forms, let alone resizable ones.
Controls in WinForms can be docked or anchored to any edge or combination of edges of the parent control, allowing one to easily mix static and resizable elements on the form without it looking like crap. They also have flow and table containers when you need them.
Admin
String.Trim only trims leading and trailing space. The code example trims all spaces (but not all whitespace).
They're different in function, so you shouldn't be comparing them.
Admin
He's not converting a control to a number, which is impossible to do. He's converting the textual contents of a control to a number, which is something that I'm sure we've ALL had to do at one point in time or another.
The only "WTF" in the example as submitted is that the function is poorly named. Hardly a WTF at all. Fix the name, refactor, done.
I challenge anyone here to claim that they've never named anything poorly. I'll show you a liar.
Admin
And this has to do with... what?
The "WTF" submission uses the Control.Text property, which shows that he's clearly using a WinForms project, and not a webforms client.
It's all about context.
Admin
And the result can be different: For " 987 325 " -> "987 325" with Trim -> "987325" with Replace Because spaces are separator for thousands in several conventions, Replace can be a better solution
I was playing with generics (you need of course 2.0)
Well, I still don't understand why he is passing the all control to the method.
Admin
FYI - in .NET 2.0+, Text is a property of: System.Web.UI.ITextControl System.Web.UI.WebControls.TextBox System.Windows.Forms.TextBox System.Windows.Forms.TextBoxBase
Aside from the lame naming convention, this isn't that much of a WTF.
Slow day, eh? Taking pictures of paper is fun thought :)
-j
Admin
I'll have to disagree with you on that; MFC had some pretty f'ed up Hungarian notation.
Admin
The function takes a Control as input. It returns a double as output. The output is a different representation of the input. How is that not converting a Control to a number?
Admin
Admin
Admin
Admin
The anchoring concept sounds good enough, and may be a bit easier to use for the standard cases, but I doubt it's any better for more complex cases.
Admin
Seeing the inner workings of the method is muddying the waters a bit. From a "black box" standpoint, these methods take a control in and return a double (or int) out. If the method only needs a string to parse, then it's silly to arbitrarily require that the string be contained in the Text property of a Control object. We could just as arbitrarily create "foo" class and a "bar" class, make the value to be parsed the "Thing" propery of the bar class, and expose the bar as a meber of the foo so that we pass in a "foo", and internally parse the "foo.bar.Thing" string. That example is sort of ridiculous, but it (hopefully?) illustrates the point by following the same pattern as the code.
Admin
Doing it this way does provide some conceivable advantages. For example, in the future some PHB may decided that these methods need to do more than just parse a double/int out of a Control's Text field; maybe he'll want the first method to round all the doubles down to the nearest 1/100 before returning them, or the second to ABS all the ints before returning them. With the method signatures the way they are, the chances of anyone else using them to do what they're doing now is less; therefore should such a PHB make such a change, the chances of the change breaking other areas of the code are less.
I admit that this example is a bit contrived, but managers do pretty fucked up things sometimes.
Admin
Actually, it should be titled "Converting Apples to 0r4ng35"
captcha: pointer - the way is now clear!
Admin
So any function that takes one piece of input and returns another is automatically considered a conversion?
I'm sorry, but that's stupid. The function is named wrong, plain and simple. If the function was called "GetTextContentsOfControlAsDouble", would you still think it was converting a control to a double?
Bottom line, it's named wrong. That's the extent of the WTF as presented. It's not a anywhere near to a real WTF.
Admin
Some of the comments on this thread are the true wtfs.
Admin
I find that many people who have been raised on Java have no clue to how bad it really is. I find also that many linux nerds who hate anything Microsoft with a passion also love Java simply because it's the only competition for .NET.
In fact I've never known anyone who has used C# and wanted to go back to Java, due to it being so awkwardly behind the times.
Let's take generics for example. "But Java has them!" people yell. No they don't. It's a stupid syntactic sugar hack that simply wraps around collections of untyped objects. That's 5 acres of bad.
Or how about the fact that there are two representations of each primitive datatype? You know, one value-type, and one class-type. and all the retarded amounts of boxing and unboxing involved in being able to use primitives?
Let's not forget checked exceptions. Worst. Idea. Ever. All it does is encourage people to write monolithic try-catch blocks that simply eat every exception without actually handling it. Oh and there's that whole thing where knowing every kind of exception a function throws exposes implementation details.
Hey how about that nifty little feature where every class has to be in the classpath? What genius thought that one up?
Let's talk GUI's for a second. Java's GUI toolkits are extremely primitive since they REINVENT the GUI on every platform it's on. They look alien and just plain weird. Oh and there's the little fact of how the GUI's run slow and laggy since they don't have any native OS support either.
Standardization? What a laugh. You're at the whim of Sun, and now, the open sores community. That's a brilliant idea, open up the source of Java so that there ends up being 80 different branches, none of which are compatible with each other. With C#, it's ECMA certified. No problems there.
How about that little thing where all functions are virtual, even when it's plain just not needed? .NET doesn't have that problem.
.NET fixed every stupid thing that Java got dead wrong. But I'm obviously retarded for pointing that out. Thanks.
Admin
To illustrate: a wagonload of cotton rolls in from the field to the gin. The cotton is removed, processed in whatever ways gins process cotton, and then baled and put out on the dock for shipping. Has the wagon now become a stack of cotton bales?
Admin
There are a couple of reasons why people would let a method accept a control as input even if all it needed is a string from the control (there could be a straight string to double version somewhere else in the code):
It saves walking down the path to the actual value in every single method call. Sometimes the path is multiple lines for some of the .net controls, especially if you use indexers with a long path too. The code becomes much clearer if you hide it in the methods.
It hides the (sometimes silly or non standard) naming of properties in components. Without an age or knowledge of what (if anything) it was ported from, it can be hard to say exactly why it's a good idea, but several third party database components use VERY different naming.
And the fact that it's private doesn't really mean anything if it's part of a windows form class.
Admin
It's pretty hard to see a WTF in this submission. The methods could be named better. Nowadays, you'd call double.TryParse(), but this was probably written in .Net 1, before that method existed. But otherwise?
I'd wager that most WinForms and ASP.Net applications in have some similar helper methods to get strongly typed values out of UI controls.
Admin
You may want to check aagain:
http://msdn2.microsoft.com/en-us/library/system.windows.forms.control_members.aspx
Control does indeed have a Text property.
Admin
Can I buy you an "any" sticker for your double-quote key to make it up to you?
Admin
I have one example where layout managers fail horribly. Take three list boxes side by side, they should be equal distant apart from one another and also scale with the form.
What invariably happens here is you get everything set up and anchored thinking your going to look good but when you resize the form, the list boxes grow and start overlapping.
This is where you need to start managing the resizing by hand. Granted layout managers do work very well in other situations, but this is one area where they do not. There is no silver bullet.
Admin
The problem with this is now the function has to know how to walk down the path of every control, or fail on the controls that don't do it they way it expects. best to pass in the actual text and let the function work with that.
Of course if this and the name itself are the only problems, this is a WTF that isn't.
Admin
I didn't even think of joining the Java/.NET holy war until this post.
One could say that strongly-typed languages are behind the times. So what? The price for being ahead the times is that once MS releases a new version of... whatever, really, you have to scrap everything you've had so far and move forward. The fact that VS2005 works only with .net 2.0 allows to assume that new version of VS will work with .net 3.0 only. Is that so much fun? That's a good one. So .NET doesn't reinvent the gui on every platform it's on. Well, how could that be true in that multitude of platforms? And besides, SWT doesn't look or work as bad as you describe it.Sure, so how many branches have you actually counted? And of course ECMA certification will protect MONO from being threated by MS for patent infringement?
I would like to mention that I do think that .NET has serious advantages over Java, such as the above-mentioned native generics support or the assembly concept. It does have its flaws too - ASP.NET is a real WTF IMHO. But either of these cannot be defended in a "Night is better than day because it's darker" way of argumentation. It's technology not religion so let's just be reasonable.
As a final note, there are tools for every task, so fighting without a proper context whether a hammer or screwdriver is better is plain stupid.
Admin
Am I missing something, the control class does not have a Text property, controls inherited from it do... TextBox, HyperLink etc but the base contrl class does not (at least not in .net 1.1...)
** note I just checked this and its right, so this is either not c# or its a later framework
they would need to cast that control to a TextBox before doing what they are trying to do so int.Parse(((TextBox)ctrl).Text))
Admin
What is the fastest way to move a Petabyte of data? - for $500 Alex!
Admin
Incidentally, I just compiled and tested this, and I can't for the life of me work out where exception handling is required. Maybe I've got the wrong library for atof()? (Which is in turn an incredibly retrograde way of using C++. No wonder all the weenies are hooked on C# or Ruby.)
Admin
Next, please.
Admin
Move all the Hard Disk at least 1 milimeter :P
Admin
Hey what's al teh fuzz about Controls, Java, .Net, ASP.Net... The WTF here is... C'mon is the Web 0.1!!! Also with a nice wooden table... Geez!
Admin
The REAL W.T.F. is the C# vs Java bullshit in the forum. They are both the same crappy language.
captcha: fuckwits
Admin
Admin
Admin
Admin
<quote>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? </quote>
Who knows what other methods are part of this class? We are only seeing a code snippet.. not the whole program.
Admin
Or should it be converting "Apples" to 499135 ? (Think leet)
Admin
OTOH, I've seen overlapping widgets in Win32 programs, because they don't have layout managers and simply hardcode the widget positions absolutely. So, when the font size is increased, or when it is translated into another language, the widgets overlaps and look terrible, if still usable.
By hand? That's stupid. If you hard-code widget positions, your GUI cannot adapt to different sizes (of the parent frame, or the buttons -- remember button labels may not fit a fixed, hard-coded size after translation!). If you write code to compute it, you're reinventing a square wheel for which the LayoutManager already provides a round one. Oh! Sorry, when you us MS things, you don't have that round wheel available. Poor man!I've been writing GUIs with layout managers (a.k.a. [automatic] geometry management) for around 15 years. It's nothing new to me. They have been there in Xt, Tcl/Tk or Perl/Tk as well as Java. 20 year old technology. MS still can't catch up with these. Maybe, MS people are too stupid to understand the concept.
And here is a short program that I've just written, which does perfectly what you mentioned: 3 lists side by side. Try resizing it, and the 3 lists always get the same width. No overlapping at all. The key is to use a GridLayout (and use it properly).
Anyone who has gone through Java's tutorial on Layout Managers can come up with code like that.
Admin
There's more to software development than just web programming.
Everyone else seemed to assume that it was a WinForms application.
HTH.
Admin
you miss the point - pictures taken on wooden tables are one of the insider jokes here.
No, I do not care to explain - search the site.
My complaint is that the picture is quite unfocused - that is bad craftmanship.
Admin
The REAL WTF is the picture quality. (most likely a polaroid picture scanned with a device that add random noise on it)
Admin
The REAL WTF is the picture quality. (most likely a polaroid picture scanned with a device that add random noise on it)
Admin
Talk about scraping the barrel. If you can't find any wtfcode to post, how about not posting?
Admin
I think, i've got it now. This guy programmed a little calculator and he created the two methods to read the numbers from the calculator's buttons :-)
Just wondering why he returns Double - has the calculator a "99.9998" button ?!?