- 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
Can someone plz post Java™ code of equivalency for this?
Admin
Poor Jeff!
Admin
At least they didn't use Val().
Admin
My brain is dribbling out of my ears ....
Admin
public double doubleize(String t) { return Double.parseDouble(t); }
Admin
Double your pleasure Double your fun
Also double your migraines.
Admin
I would imagine conversion of strings to some time integer value, hopefully not floats for currency dealings, is about the most common input gathering activity in programing business apps. Luckily there exist clean, reasonably safe, easy ways to do this. - Or you can do this way.
You'd think in some course somewhere along the line programing instruction could spend a day or so the correct patterns for this activity.
Admin
I would imagine you said something. But - what
Admin
If you're going to Doubleize something, you have to do it twice. Duh.
Admin
Yes, don't use Val. It's much better to use Double.Parse.
Admin
Strictly, since he's also rounding to 4 places, and depending on VB.net's implementation of round:
(Yeah, it's probably off for negatives.)
Admin
Wouldn't that Quadrupleize it?
Admin
Was that VB syntax invented by humans? Esepcially the 'OrElse'; it sounds rather threatening.
Although I believe that VB can be summarised in a single statement: 'Dim'.
Admin
You can lecture people on the right way, but they won't internalize it until they've screwed up and fixed it.
Admin
While the implementation is pretty WTF (especially if not centralized), the intention of the method itself is okay. .NET's Double.Parse throws an exception if the string is invalid, and Double.TryParse just catches that exception. Exception handling is way slower in .NET than just detecting failure like this is trying to do. Our company has something similar (and much better) in our internal code library as an extension method. Basically (in C#):
is much better than Double.TryParse and also doesn't rely on a goofy out parameter.
Admin
Admin
Once upon a time when I was but a nipper I had to write what should have been a trivial educational program to graphically illustrate scaling of decimals. Sadly Pascal didn't have accurate enough floats, or big enough integers so I toiled away and wrote a string based simple math library which was 100% accurate.
Now I realise that I only needed to address the one digit we were working with and simply use the ones to the left and right of it as a identifiers. That's what 30 years of experience does for you.
Admin
FTFY
Admin
I don't believe these manage to replicate the bugs in the VB Doubleize. Perhaps they replicate its intent...
Admin
I can't get any work done with all this WHOOSH!
Admin
Most likely on your part, unless offering the obvious solution in a sarcastic way passes for funny now.
Admin
What do you do if it's not numeric?
Admin
Hey folks, give frits a hand, he's all right!
Admin
If Commenting or AboutToComment AndAlso MightThinkAboutCommenting Then
WriteComment()
Else If HasCommented AndFurthermore HasReceivedComment NotwithstandingAbovementioned MightComment Then
DontWriteComment()
However If WontComment AndNevertheless NeverCommenting Then
OughtToComment()
OrElse
Buster()
Admin
Whatever you normally do when given invalid input- show an error message or something.
Admin
My sentiments exactly.
TRWTF is a language which needs two versions of and/or: one with short-cut logic built-in and one without. Did they really assume that people expect And and Or to execute all paths to ensure that all side effects get triggered - another WTF is people adding side effects to boolean logic.
Admin
Maybe I was confused, the function doesn't look like
But then aren't you parsing the double twice? One pass to validate it for parsing and then another to actually parse it.
Admin
Was showing how we do it- the use case is a little different from the WTF, but taking 2 passes on the string is still faster than catching a FormatException from Double.Parse
Admin
I did not know that, dude.
Admin
No it doesn't, at least it didn't last time I checked. It aborts processing the string as soon as it finds invalid input and returns false; as opposed to Parse() which aborts parsing the string as soon as it finds invalid input and then throws an exception. TryParse() incurs far less overhead in the case of invalid input.
Admin
You know, I've never known a joke that was improved by arguing over whether it was funny or not.
Admin
Admin
TryParse() does not throw and catch exceptions internally. It works completely without exceptions. Your IsNumeric() just wastes time.
Admin
The WTF trifecta is in play here:
This SOD shows a complete lack of understanding on the developers side, or they were a junior, or both... Reminds me of what I saw throughout the codebase I inherited:
string myString = "this is a string"; return (string)myString.ToString() as string;
WTF?! It's a string already!!
Admin
I think that OrElse, AndAlso are VB's way of introducing the short circuit behaviour of C's (and others) || and && operators.
In C,
if (1 || f(x)) { ... }
and
if (0 && g(y)) { ... }
will result in neither f(x) nor g(y) being evaluated.
Admin
Right, sorry about that, the method should start with:
So, obviously the strings '+', '-' and '.' will be passed to CDbl and possibly throw an error.
And, of course, it doesn't handle exponents. The way it's used in the program is almost vindictive: if CStr decides to format a number in exponential form, it will be then be doubleized as its exponent. So 123456789 will be doubleized properly, CStr'd to 1.23456789E8 and doubleized to 1.2346.
Admin
Possibly, there are instances where this comes in useful, but I can't think of any.
Admin
The code clearly had no WTF. It was clearly a management effort to doubleize the productivity of a (clearly) half by half working app. And much like many management efforts, it zeroed the result in most cases.
Admin
I desperately need the source code for Floatate() as well. Please help me, I have an assignment due tomorrow! Please please please...
;-)
Admin
Public Function Quadrupleize(ByVal StrVal As String) As String Return CStr(Doubleize(CStr(Doubleize(StrVal)))) End Function
There ya go. People pay people for this!
Admin
Admin
Bonus:
Most people don't know that, but the numeric separator ("." in the US) is a "," instead in Germany. Oh how much fun this is!
Admin
If you tell a joke and the other person doesn't laugh, and then you explain to them why it's funny, logically, now they should laugh. Retroactively.
Admin
I think my head just exploded.
Admin
Well, how about
If you used && instead of &, the side effects on the second call wouldn't happen if the first call returned false.
This may or may not be desirable, depending on what you're up to.
Admin
"Classic ASP"?
Pff... I'm getting old. What's next? "Canonical Ruby-on-rails"? "Ancient Python"?
Admin
Well obviously you should do the conversion twice. What if the computer made a mistake the first time?
Admin
Or were you joking?
Admin
Logic where you evaluate all tests regardless can be useful to prevent side-channel attacks. Essentially, you're trying to make the machine do the same amount of work no matter which path the code goes through.
For instance, if someone tries to log in with a username and password, you might find right away that the username isn't valid, but then go through equivalent steps as if it had been a real password. That way an attacker can't determine valid usernames by observing patterns of response time.
Admin
Executive summary: "I don't know of any either."