- 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
Confusing naming, you say? Isn't it obvious that removeNumeric() is supposed to remove everything except numeric chars? :)
Admin
I'm no VB developer, but I doubt very much that the last one will even work. NumStriper != NumStripper.
Admin
This is not a WTF. When you have a shared function library, you will always have repeated functions, or functions that are really similar but take in account a different range or type of input.
This will always happen.
Admin
Also 2nd one won't work. outStr != outString
Admin
Fail.
Admin
(OTOH I forget whether classic asp is vb6 or vbscript; the latter has no declarations at all in a classic invitation to shoot yourself in the foot. Repeatedly.)
Admin
Admin
This is great!
In fact, this is just the way the PHP functions were developped!
It’s the "it doesn’t exist, just add it to the language" school of language definition at it’s finest expression!!!
Captcha: "poindexter". WTF????
Admin
Admin
Admin
Eat it VB. Java pwnage:
public String stripNumbersFromString(String s) { return s.replaceAll("\D", ""); }
Admin
Sorry, but I don't see how this is a WTF at all. Something to read, shrug and move on, certainly wouldn't make me think "WTF" :)
Admin
It wouldn't be a WTF discussion without someone coming to the defense of the WTF. So, I'll offer the following.
At least the first function, "OnlyNumber", has a tolerably meaningful name and actually does what it appears to claim. It uses the bizarrely named variable "sNonNum" for the string of numeric characters, but that's inside the 'black box'.
As for including a whole library of community developed functions in every script on the Web site, well... WTF indeed!
Peer review, weeding, and thorough documentation could still make it a handy resource.
Admin
Thats obvious. its actually NumStriper <> NumStripper
Admin
Ah, well that's OK then.
Admin
Hey, at least it wasn't NunStripper...
Admin
I actually love the name of the second one: removeNumeric().
So that's supposed to remove all numbers in the string. And of course, the code do the exact contrary (well, the code doesn't work, unless this is a typo from our master poster).
I guess there is a meta-function somewhere which is called removeNameSecmantics() (or addNameSemantics(), depending on the programmers way of thinking).
The captcha says it all: muhahaha.
Admin
Wow! VB supports regular expressions too.
Admin
i like that they have such good naming conventions though
sStr, inString, str
nice...
Admin
I like the way all three of them will turn, e.g. "a1b2c" into "12"...
Admin
Yeah, and you can do the same thing (roughly) in PHP, or Javascript, or any language with regex capability...
Is there no regex in VB? Why would anyone use that language?.... That's a real WTF... :P
Admin
If it's not a WTF, then it's because there's only 3 of them. You must have many more code repetitions to make this kind of "quite normal behavior" a WTF. For my part, I can't consider this kind of issue to be a WTF unless there are at least 31 of them (and that's because I'm 31. In 4 years, this maximum repetition number should increase).
Admin
While a library often contains similar/related functionality (different but similar ways of pouring database results into a language-native format, for example), a library with exact copies of functionality is in dire need of cleanup.
This WTF is a WTF indeed, because it displays the utter mental blindness with which their library is treated.
Admin
They look like similar functions!
Admin
Isn't it interesting how quick people are to slam Visual Basic, VBScript, and VN.NET without (a) knowing the differences among them or (b) knowing the features and capabilities of the languages.
What we saw in this WTF was VBScript. All three of the VB-related languages support regular expressions. http://msdn2.microsoft.com/en-us/library/ms974570.aspx
Admin
Pardon my typo. "VN.NET" of course should have been "VB.NET".
Admin
NumStriper()? How do you add 'stripes' to a number?
Admin
Aren't regular expressions available in just about every language under the sun? This is not a problem with VB (although I would never use it over C# or JavaScript), it is a problem with the one(s) behind the keyboard. Unfortunately, we can't put monkeys in space, that's why there's still so many in front of computers...
Admin
OnlyNumber only returned numbers. Perhaps that is what was wanted, but some numbers have a decimal component that wouldn't be honoured. As for the glorious WTFy way Microsoft decided to implement RegExp in VBScript:
Admin
Ouch!
Admin
Turn on every other bit?
Admin
It's perfectly cromulent code, which imbiggens the functionality of the language.
Admin
Maybe it has something to do with the Webserver's RAID configuration?
Nah, probably the same thing that makes "developpers" play "Rouges" in fantasy games.
Or the disappointment felt when one discovers that there are only "stripers" at the nightclub.
Cheers!
Admin
VB does have its share of WTFs, like finishing out the function with functionName = value rather than using the return statement like everyone else. Small typos like we see in the sample above will result in a returned value of a zero-length string. Yippee.
And although it is possible to create a RegEx object in VB, I wouldn't recommend it if you have to do it more than a couple times. It's incredibly slow to instantiate. Not that VB is known for its speed, but don't slow it down any more than you have to.
If you're dealing with fairly short strings, just loop through it with Mid(), save the RegEx stuff for when it would be worthwhile.
Admin
I moved onto a 750kloc project once, and found 7 functions which operated on the same container type, all called "remove_duplicates" (with minor changes / namespace hiding).
Catchpa : Bling - Programming's glamorous you know.
Admin
Having been forced to use ASP in the past, I defied convention and used Javascript as the language instead of VBScript because of the nightmarish state of VBScript. Also making sure to always explicitly declare and explicit type conversion was extremely helpful as well.
Even so, I also had to resort to (albeit much shorter) a custom defined "library" for dealing with the bizarre XML RPC I was forced to use for communication with our CRM system (that drives the website).
Admin
\D matches non-numeric characters.
Admin
According to the article, the submitter was looking for a function to return the numeric characters out of a string. So, what is wanted is to replace non-numeric characters with "". \D would be correct.
Admin
Ever hear of the saying "say what you mean and mean what you say"?
Admin
Admin
This problem is inherent in user editable function libraries. Just like the possibility of errant code getting in there. Just like possibility of bad information getting on Wikipedia.
And to all those one-word replies to the original post, please explain what you disagree with.
Admin
Don't you get it? "RemoveNumeric" removes the numeric characters... and returns them! Get it? Huh? Huh???
Wow, tough crowd.
Admin
I concellate. It's a snaff way of bedroggling.
Admin
NumStriper? does it paint the numbers with stripes?
Captcha: xevious - You know I dont' speak Spanish!
Admin
If you want to strip the numbers from the string, you use \D. You fixed it backwards.
Admin
In the more general case, a refactoring of all but one function such that they are implemented in terms of the remaining (useful?) one is obviously the way to go. This makes the lives of future developers significantly less likely to end in That Postal Moment.
As to the one-word replies, I think the authors are implying that they would not wish to work alongside someone with your refreshingly cavalier attitude to sensible codebase maintenance. This is most unfair of them. If they look around their place of work, I have no doubt they'll find plenty of other ninnies who are equally adept at making their lives miserable.
Admin
Helped out by the fact that English is a ridiculously loosely typed language. What were they thinking. Theres even the word "verbed" for implicit conversion of noun type objects to a verb object. Which is itself verbed noun. What a WTF. :D
Admin
The name "stripNumbersFromString" is a little ambiguous. It could mean "strip the numbers from the string and give the string back to me" or "strip the numbers from the string and give the numbers back to me."
Admin
"strip" is synonymous with "discard". You don't want back what you discard.
Admin
To send her to prison.