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

    I agree with you, but myself I would fix it in a fashion that would force the rest of the code to be changed. Refactor the soon to be dropped functions so that they call the one to keep, then add an alert box stating that the refactor needs to happen so as to use functionX instead.

    All code still works and anything not caught by developers will be caught by QA (which in some companies means the users) but the word will get passed and it will eventually get fixed. Hopefully not by removing the alert() though, that's why you let them know what function to call.

    Once all those issues are cleared up you can remove the function. Of course you could bypass all this by simply grepping the source but you always miss something that you didn't know you had to include in the search.

  • None (unregistered) in reply to RON

    If I had been drinking a diet coke when I read that, I would likely have spewed it through my nose.

    You rarely run into a situation where so much meaning can be derived from one, perfectly-chosen, single-syllable word.

    I salute you, sir!

  • None (unregistered) in reply to None
    If I had been drinking a diet coke when I read that, I would likely have spewed it through my nose.

    You rarely run into a situation where so much meaning can be derived from one, perfectly-chosen, single-syllable word.

    I salute you, sir!

    Sorry, was directed to Ron.

  • egw (unregistered) in reply to jonny lech

    $mystring=~s/\d//g

  • Will (unregistered) in reply to Paul
    Paul:
    "strip" is synonymous with "discard". You don't want back what you discard.

    Not where I come from, but I do see your point.

  • Michael (unregistered) in reply to cparker
    cparker:
    Ever hear of the saying "say what you mean and mean what you say"?
    cparker:
    Dim re
    You're not very nice to re.
  • (cs)

    If isNumeric(theDigit) then ... if isnumeric(mid(str,i,1)) then

    I take it ASP is not case sensitive, or else we're left to ponder how many versions of isNumeric are in the library.

    --RA

  • (cs) in reply to Paul
    Paul:
    "strip" is synonymous with "discard". You don't want back what you discard.
    Ever heard of stripping something for parts?
  • Will (unregistered) in reply to Zylon
    Zylon:
    Paul:
    "strip" is synonymous with "discard". You don't want back what you discard.
    Ever heard of stripping something for parts?

    And I doubt strippers would make much of a profit if they didn't get their clothes back.

  • stinky (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.

    And, you always wind up with a bunch of crappy code snippets like this C++ gem (from some outsourced overseas counterparts):

    bool Boolean::getTrueOrFalse(const bool& BooleanResult) {
      bool TrueOrFalseResult;
      if(BooleanResult == true) {
        TrueOrFalseResult = true;
      }
      else if(BooleanResult == false) {
        TrueOrFalseResult = false;
      }
      else {
        throw(Boolean::MAYBE);
      }
      return(TrueOrFalseResult);
    }
    
  • escape_shall_we (unregistered) in reply to jonny lech
    jonny lech:
    public String stripNumbersFromString(String s) { return s.replaceAll("\D", ""); }

    That won't compile in Java. You need "\D".

  • Paul (unregistered) in reply to Zylon
    Ever heard of stripping something for parts?
    Good counter-example. I think the difference is between "strip out" and "strip for". Strip usually means "strip out", but "strip for" would return what was removed.
    And I doubt strippers would make much of a profit if they didn't get their clothes back.
    The customers pay to see nekkid people, not a pile of clothes.
  • Mario (unregistered) in reply to Rank Amateur
    Rank Amateur:
    I take it ASP is not case sensitive,
    No, Basic (est. 1963) is not case sensitive.

    Of note: in ASP, "Option Explicit" and "Option Strict" are available. It is possible to write proper code in those languages, if one wants. Also, let's not confuse VBScript, VBA, VB and VB.Net. They share the same origin, but are seriously different languages.

    How do you do regular expressions in VB.Net?

    Imports System.Text.Regularexpressions
      Public Function stripNumbersFromString(ByVal s As String) As String
        Return Regex.Replace(s, "\D", "")
      End Function
  • Mario (unregistered) in reply to Rank Amateur
    Rank Amateur:
    I take it ASP is not case sensitive,
    No, Basic (est. 1963) is not case sensitive.

    Of note: in ASP, "Option Explicit" and "Option Strict" are available. It is possible to write proper code in those languages, if one wants. Also, let's not confuse VBScript, VBA, VB and VB.Net. They share the same origin, but are seriously different languages.

    How do you do regular expressions in VB.Net?

    Imports System.Text.Regularexpressions
    
      Public Function stripNumbersFromString(ByVal s As String) As String
        Return Regex.Replace(s, "\D", "")
      End Function
  • anonny (unregistered) in reply to suutar
    suutar:
    I like the way all three of them will turn, e.g. "a1b2c" into "12"...
    Could be useful for processing things like credit card numbers. Whenever a site tells me to never, ever, ever add any dashes between the number groups, I always wonder, why? Are they too stupid to strip out non-numbers?
  • (cs)

    Every place I've ever worked as a programmer has had some massive "dumping ground" library, a place where everything anyone has ever deemed "might be useful" has been thrown in. It grows out of control with furious speed, until it's so unwieldy that it's virtually unusable. It's not long before the only use it gets is in the form of people using the parts they themselves contributed.

    This is the result of programmer ego ("this snippet was hard to write, so I feel proud of it and therefore it should be in the hall of fame"), and a cargo-cult belief that code reuse is always a good thing. In fact it is NOT always a good thing, especially for simple code snippets. (You wouldn't approve of a library function that adds two basic integers, would you?) Self-contained code is quicker to maintain and understand than code that references a massive monolithic library for trivial functions.

    Particularly common is the entire "dumping ground" being in one package or file. This happens because it was made by people who don't know anything about API usability or don't care. Everyone just keeps throwing little monuments to their egos into it, Ball of Mud style.

    Had the relevant functions been in NumericParsing.asp, I suspect the redundancy would have been more evident, and Sam's task would have been quicker.

  • (cs) in reply to Sgt. Preston
    Sgt. Preston:
    Pardon my typo. "VN.NET" of course should have been "VB.NET".

    No, VB.Net should not have been.

  • (cs)
    'TODO: Swap name with NumStriper
    Function NumStripper(str)
    	ret = ""
    	for i = 1 to len(str)
    		ret = ret & Mid(str, i, 1) & CStr(Int(10 * Rnd))
    	next
    	NumStripper = ret
    End Function
  • Anon (unregistered)
    if ret = "" then ret = 0 end if

    the dreaded Variant.

  • (cs) in reply to VGR
    VGR:
    Every place I've ever worked as a programmer has had some massive "dumping ground" library, a place where everything anyone has ever deemed "might be useful" has been thrown in. It grows out of control with furious speed, until it's so unwieldy that it's virtually unusable. It's not long before the only use it gets is in the form of people using the parts they themselves contributed.

    This is the result of programmer ego ("this snippet was hard to write, so I feel proud of it and therefore it should be in the hall of fame"), and a cargo-cult belief that code reuse is always a good thing. In fact it is NOT always a good thing, especially for simple code snippets. (You wouldn't approve of a library function that adds two basic integers, would you?) Self-contained code is quicker to maintain and understand than code that references a massive monolithic library for trivial functions.

    Particularly common is the entire "dumping ground" being in one package or file. This happens because it was made by people who don't know anything about API usability or don't care. Everyone just keeps throwing little monuments to their egos into it, Ball of Mud style.

    Had the relevant functions been in NumericParsing.asp, I suspect the redundancy would have been more evident, and Sam's task would have been quicker.

    I used to work in a retirement home, and we'd use the resident's communal bathrooms because they were nicer. We called them the "Secret Dumping Grounds".

    Oddly enough, we'd leave behind our own Balls of Mud, if you catch my drift.

  • brendan (unregistered)

    first, it obvious that all three a done by three different developers.

    the middle one's the best performance wise, but not named properly.

  • Jens (unregistered) in reply to Blame
    Blame:
    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.

    WAUW... Ron and Blame.. You two are the best programmers ever.. Imagine that.. You really ROCK !!! I mean, having a complete, I mean COMPLETE overview of EVERY SINGLE function available in you code library.. Waaauuuww..

    I have made What the F.. I mean Worse than failures many many times, simply because I didnt know every single function by heart.. I must admit, I quite often still, even after reading this, make functions myself, rather than browsing through code trying to find what I need, if the algorithm is as simple as this.. But you two.. Remembering every single function available, and be cool enough to never write an already existing function.. This is soooo, good.

    (To all Americans.. Think "sarkasm" while reading this..)

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

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

    Hey! Ive been w... Uhm. Seen some hot nuns. ;)

  • Jor naim (unregistered) in reply to stinky
    stinky:
    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.

    And, you always wind up with a bunch of crappy code snippets like this C++ gem (from some outsourced overseas counterparts):

    bool Boolean::getTrueOrFalse(const bool& BooleanResult) {
      bool TrueOrFalseResult;
      if(BooleanResult == true) {
        TrueOrFalseResult = true;
      }
      else if(BooleanResult == false) {
        TrueOrFalseResult = false;
      }
      else {
        throw(Boolean::MAYBE);
      }
      return(TrueOrFalseResult);
    }
    

    What the hell? Do you pay them by LOC per any chance?

  • Joost (unregistered)

    The real WTF is that the NumStriper() method doesn't have a Color parameter... (for the stripe's color)

  • London Geezer (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.

    Wow. You're obviously not a very good developer!

    CAPTCH = sanitarium - maybe you should be there?

  • Corporate Cog (unregistered)

    Demonstrating one of the benefits of a framework.
    In my last job, I asked if there were any standard libraries or anything similar. The response from the uber coder was, we don't need anything outside the (Delphi) VCL/RTL. At my current job I suggesting using the JCL (again for Delphi). The suggestion was rejected. Thus, developers don't even want to ask and routines are duplicated everywhere bloating the code base to 750K lines. Such is the life of a code wannabe.

  • the_real_tel (unregistered)

    Am I the only one who noticed that the 3rd function is significantly different to the 1st and 2nd functions, in that it returns a number, not a string of [zero or more] digits ? (unless cdbl() doesn't do what i think)

    As has been pointed out, "strip" is ambiguous - does it mean "remove these things from the input and return what remains" or "extract these things from input and return extracted items"? So, by my logic, these should be called something like extractDigits(aString).

    Of course, there's no reason not to reimplement the 2nd function as a wrapper of the 1st (or vice versa). Equally, the 3rd function could just cdbl() around call to 1st or 2nd.

    So overall, the WTF/CSOD as presented is quite minor. In reality it could be much worse, but we don't know what else was in this file that's included everywhere.

  • drd (unregistered) in reply to jonny lech

    you mean s.replaceAll("\D","");

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

    Those are exactly my sentimonies.

  • Phil (unregistered)

    I've known worse in website coding. One near 10k lines include that's in almost every file, with overlapping functions and occasional functions that are also in individual code files, plus multiple 5k plus include files with overlapping but subtly different content. They didn't even have consistent usage, naming or a central storage directory, and were scattered all over the place.

    Needless to say I wasn't a fan of the system.

    (Captcha - quake. About what I did when I first realised the true nature of this beast.)

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

    Only if you already work in a WTF-cubed environment. I can't think of a sane devleopment environment where one wouldn't have version control, production-development-test isolation and code cross-referencing (handled by the IDE and/or off-line tools like doxygen, LXR, you name it).

    If you have no control over where the code is used, that means that you cannot test anything, ergo WTF.

    So, er, no quack for ya.

  • (cs)

    Commented Code + Doc Generator = Your friend.

    Seriously, that file should be automatically documented each time it is updated.

  • arhhook (unregistered)

    Maybe...some documentation or comments on what a code snippet does if it's just...chillin' in a library? Just an idea...

    captcha: gygax //...wtf?

  • Bobby Brady (unregistered)

    "Starting a new job is usually exciting but also frightening. Adjusting to a new code base --- styles, idioms, and all --- can be daunting."

    <sarcasm>You should go into consulting... You would love it!</sarcasm>

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

    WTF.....

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

Log In or post as a guest

Replying to comment #:

« Return to Article