• Helten (unregistered)

    Confusing naming, you say? Isn't it obvious that removeNumeric() is supposed to remove everything except numeric chars? :)

  • Will (unregistered)

    I'm no VB developer, but I doubt very much that the last one will even work. NumStriper != NumStripper.

  • Will Perdikakis (unregistered)

    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.

  • James (unregistered)

    Also 2nd one won't work. outStr != outString

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

    Fail.

  • foxyshadis (cs) in reply to Will
    Will:
    I'm no VB developer, but I doubt very much that the last one will even work. NumStriper != NumStripper.
    James:
    Also 2nd one won't work. outStr != outString
    Presuming they're typos, but if not, oh the fun of ensuring that there's no option explicit in sight!

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

  • Sgt. Preston (unregistered) in reply to foxyshadis
    foxyshadis:
    (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.)
    Classic ASP uses VBScript, which has very loose run time typing and implicit variable declaration. Quick and easy to write and quick and easy to screw up if you're not careful.
  • Pig Hogger (unregistered)

    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????

  • Sgt. Preston (unregistered) in reply to Pig Hogger
    Pig Hogger:
    It’s the "it doesn’t exist, just add it to the language" school of language definition at it’s finest expression!!!
    Rather like the English language, except that in English, we don't care whether a we already have eighteen ways to say something; we'll add a nineteenth and call it cool. And we don't care whether the expression we invent already exists with an unrelated meaning; we'll just give it another one. Sort of spoken language overloading run amok.
  • Blame (unregistered) in reply to RON
    RON:
    Will Perdikakis:
    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.

    Fail.

    Spot on, Ron.

  • jonny lech (unregistered)

    Eat it VB. Java pwnage:

    public String stripNumbersFromString(String s) { return s.replaceAll("\D", ""); }

  • Raptor (unregistered)

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

  • Sgt. Preston (unregistered)

    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.

  • blah (unregistered) in reply to Will

    Thats obvious. its actually NumStriper <> NumStripper

  • Luke Dawson (unregistered) in reply to Will Perdikakis
    Will Perdikakis:
    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.

    Ah, well that's OK then.

  • Will (unregistered) in reply to blah
    blah:
    Thats obvious. its actually NumStriper <> NumStripper

    Hey, at least it wasn't NunStripper...

  • EmmanuelD (unregistered)

    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.

  • akatherder (cs) in reply to jonny lech
    jonny lech:
    Eat it VB. Java pwnage:

    public String stripNumbersFromString(String s) { return s.replaceAll("\D", ""); }

    Wow! VB supports regular expressions too.

  • A Nonny Mouse (unregistered)

    i like that they have such good naming conventions though

    sStr, inString, str

    nice...

  • suutar (unregistered)

    I like the way all three of them will turn, e.g. "a1b2c" into "12"...

  • etr (unregistered) in reply to jonny lech
    jonny lech:
    Eat it VB. Java pwnage:

    public String stripNumbersFromString(String s) { return s.replaceAll("\D", ""); }

    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

  • EmmanuelD (unregistered) in reply to Raptor
    Raptor:
    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" :)

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

  • dhromed (cs) in reply to Will Perdikakis
    Will Perdikakis:
    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.

    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.

  • EmmanuelD (unregistered) in reply to suutar
    suutar:
    I like the way all three of them will turn, e.g. "a1b2c" into "12"...
    Yeah!

    They look like similar functions!

  • Sgt. Preston (unregistered) in reply to etr
    Comment held for moderation.
  • Sgt. Preston (unregistered) in reply to Sgt. Preston

    Pardon my typo. "VN.NET" of course should have been "VB.NET".

  • ParkinT (cs)

    NumStriper()? How do you add 'stripes' to a number?

  • I Hate 1st TN Bank (unregistered) in reply to jonny lech

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

  • MrBester (cs)

    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:

    Dim reg, sOut
    Set reg = New RegExp
    reg.Global = True
    reg.Pattern = "\D"
    sOut = reg.Replace(input, vbNullString)
    Set reg = Nothing

  • etr (unregistered) in reply to MrBester
    MrBester:
    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:
    Dim reg, sOut
    Set reg = New RegExp
    reg.Global = True
    reg.Pattern = "\D"
    sOut = reg.Replace(input, vbNullString)
    Set reg = Nothing
    

    Ouch!

  • RevEng (cs) in reply to ParkinT
    ParkinT:
    NumStriper()? How do you add 'stripes' to a number?

    Turn on every other bit?

  • vt_mruhlin (cs) in reply to Sgt. Preston
    Sgt. Preston:
    Pig Hogger:
    It’s the "it doesn’t exist, just add it to the language" school of language definition at it’s finest expression!!!
    Rather like the English language, except that in English, we don't care whether a we already have eighteen ways to say something; we'll add a nineteenth and call it cool. And we don't care whether the expression we invent already exists with an unrelated meaning; we'll just give it another one. Sort of spoken language overloading run amok.

    It's perfectly cromulent code, which imbiggens the functionality of the language.

  • Reaver (unregistered) in reply to ParkinT
    ParkinT:
    NumStriper()? How do you add 'stripes' to a number?

    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!

  • Manni (cs) in reply to etr
    etr:
    MrBester:
    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:
    Dim reg, sOut
    Set reg = New RegExp
    reg.Global = True
    reg.Pattern = "\D"
    sOut = reg.Replace(input, vbNullString)
    Set reg = Nothing
    

    Ouch!

    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.

  • Leibnitz27 (unregistered)

    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.

  • jgreen (cs)

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

  • cparker (cs) in reply to jonny lech
    jonny lech:
    Eat it VB. Java pwnage:

    public String stripNumbersFromString(String s) { return s.replaceAll("\D", ""); }

    Wow, you're cool.

    Function stripNumbersFromString(ByVal s)
    	Dim re
    	Set re = new RegExp
    	re.Pattern = "\d"
    	re.Global = True
    	
    	stripNumbersFromString = re.Replace(s, "")
    End Function
    \d matches numeric characters.

    \D matches non-numeric characters.

  • Will (unregistered) in reply to cparker
    cparker:
    End Function[/code]\d matches numeric characters. \D matches non-numeric characters.

    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.

  • cparker (cs) in reply to Will
    Will:
    cparker:
    \d matches numeric characters. \D matches non-numeric characters.

    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.

    Yes, but the GGP comment was a new function with a new function name. I fixed the pattern to match what the function name said it was doing.

    Ever hear of the saying "say what you mean and mean what you say"?

  • PC Paul (unregistered) in reply to Will
    Will:
    blah:
    Thats obvious. its actually NumStriper <> NumStripper

    Hey, at least it wasn't NunStripper...

    Why would I want to stripe a Nun?

  • Will Perdikakis (unregistered) in reply to dhromed
    dhromed:
    Will Perdikakis:
    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.

    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.

    The problem is, you can not just go to the library and determine the best function for the job and delete the other two because there may be some remote code that uses this library. You will break that code.

    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.

  • James (unregistered)

    Don't you get it? "RemoveNumeric" removes the numeric characters... and returns them! Get it? Huh? Huh???

    Wow, tough crowd.

  • Jimmy (unregistered) in reply to vt_mruhlin
    vt_mruhlin:
    Sgt. Preston:
    Pig Hogger:
    It’s the "it doesn’t exist, just add it to the language" school of language definition at it’s finest expression!!!
    Rather like the English language, except that in English, we don't care whether a we already have eighteen ways to say something; we'll add a nineteenth and call it cool. And we don't care whether the expression we invent already exists with an unrelated meaning; we'll just give it another one. Sort of spoken language overloading run amok.

    It's perfectly cromulent code, which imbiggens the functionality of the language.

    I concellate. It's a snaff way of bedroggling.

  • Patrick (unregistered)

    NumStriper? does it paint the numbers with stripes?

    Captcha: xevious - You know I dont' speak Spanish!

  • Paul (unregistered) in reply to cparker

    If you want to strip the numbers from the string, you use \D. You fixed it backwards.

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

    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.

    The problem is, you can not just go to the library and determine the best function for the job and delete the other two because there may be some remote code that uses this library. You will break that code.

    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.

    Well, apparently two of the three basically do nothing. In the remote likelihood that they are used anywhere, I suspect that a simple refactoring to no-op would be an improvement.

    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.

  • Phyzz (unregistered) in reply to Sgt. Preston
    Sgt. Preston:
    Pig Hogger:
    It’s the "it doesn’t exist, just add it to the language" school of language definition at it’s finest expression!!!
    Rather like the English language, except that in English, we don't care whether a we already have eighteen ways to say something; we'll add a nineteenth and call it cool. And we don't care whether the expression we invent already exists with an unrelated meaning; we'll just give it another one. Sort of spoken language overloading run amok.

    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

  • Will (unregistered) in reply to cparker
    cparker:
    Yes, but the GGP comment was a new function with a new function name. I fixed the pattern to match what the function name said it was doing.

    Ever hear of the saying "say what you mean and mean what you say"?

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

  • Paul (unregistered) in reply to Will

    "strip" is synonymous with "discard". You don't want back what you discard.

  • Andrew (unregistered) in reply to PC Paul
    PC Paul:
    Will:
    blah:
    Thats obvious. its actually NumStriper <> NumStripper

    Hey, at least it wasn't NunStripper...

    Why would I want to stripe a Nun?

    To send her to prison.

Leave a comment on “Third Time's a Charm”

Log In or post as a guest

Replying to comment #:

« Return to Article