• Random guy (unregistered) in reply to RandomUser423689
    RandomUser423689:
    db2:
    java.lang.Chris;:
    The RWTF is that the code this snippet is embedded into presumably gets passed a string, when it should be passed an integer. Must have been written by one of those dynamically typed language loving cretins.
    That's cute. I'll bet you store zip codes as integers, too.
    I do feel like I'm forgetting something, but right now I can't remember why this wouldn't work. Sure, you have to have input and presentation logic to convert 00401-0203 to 4010203 and 79301-0000 to 793010000, and vice-versa; but as long as you consistently store +4 (even when zero), prepending zeros shouldn't be a problem. Or maybe that was the issue, that +0000 is "valid" and therefore not good to mean "no +4". If that's it, how about negative for 5-digit. Right back to input and presentation logic.

    Someone please remind me what I'm forgetting.

    Other countries, for one thing. Off the top of my head Canada uses letters, and I'm sure it's not alone. Of course if other countries are remembered then the field is more apt to be called 'PostalZone' or the like.

    Regardless, ISNUMERIC isn't useful since it allows non-numbers (commas, periods, and more) and would need a second check anyway. Since LIKE or TRANSLATE simply move the loops internally that aren't that much faster. While other ideas may work, the presented one is perfectly valid and there is nothing to indicate 'Andy' could think of everything discussed during its initial development. And I have a feeling if he wrote the test cases for it in the new Oracle system he wouldn't have thought of periods or an initial minus sign but just verified on 'XYZ' or other obvious cases.

  • Tony Janusky (unregistered) in reply to BrainSlugs83
    BrainSlugs83:
    Unless you're doing math on a value you shouldn't store or process it as a number. Numbers are for math, and counting, and statistics and such... Not zip codes. Just the fact that you have to add the extra zeros in at display time is wrong, and also, fully qualified zip codes contain non-numeric characters such as the hyphen.

    I once wrote a geographic distance approximation server that determines mileage based on zip code deltas. This is how I worked out the formula:

    Beverly Hills - Boston: 90210 - 02043 = 88167

    Zip distance = 88167 (That's 90210 - 02043) Actual distance = 2605 miles. Ratio = 33.84

    That's a pretty good sample to base all other possibilities on, so the function goes:

    int distanceBetweenZipcodes( int zip1, int zip2 ) { int zipDist = abs(zip1 - zip2); return (int)((float)zipDist / 33.84F); }

    You'd be amazed how accurate it is.

  • (cs) in reply to wtf
    wtf:
    frits:
    Just remember, Rickles rhymes with tickles and Gore rhymes with bore.
    Lifestyles of the easily amused.
    wtf:
    Insults = pointless and unenlightening rudeness

    As long as posters like you take themselves too seriously, I'll be amused. Thanks for the entertainment. ;)

  • Procedural (unregistered)

    TRWTF* is the fact that the developer is proposing non-idempotent code to "optimize" something that absolutely doesn't require optimization (the bar code generation can't usefully go faster than either image generation of label printing), in a way which breaks predictability and comparability in an heterogeneous environment, does not properly validate in a bit of validation code, and wastes more man-hours exchanging idiotic e-mails with a manager who obviously has better things to do (and he looks like a good one, given the quality of the call made) than the total man-hours this optimization is ever likely to save over the entire life-cycle of the project.

    I think the dev just needs something new to work on. He`s converting idle cycles into NOPs.

    • 3 years without using this stupid acronym; I sort of feel dirty. But I like it. Confusion confusion.
  • Procedural (unregistered) in reply to Procedural

    (should edit: "image generation of label printing" should read "image generation or label printing"; othger typos are offered as a bonus to the original content)

  • Mike D. (unregistered) in reply to Random guy
    Random guy:
    RandomUser423689:
    db2:
    java.lang.Chris;:
    The RWTF is that the code this snippet is embedded into presumably gets passed a string, when it should be passed an integer. Must have been written by one of those dynamically typed language loving cretins.
    That's cute. I'll bet you store zip codes as integers, too.
    I do feel like I'm forgetting something, but right now I can't remember why this wouldn't work. Sure, you have to have input and presentation logic to convert 00401-0203 to 4010203 and 79301-0000 to 793010000, and vice-versa; but as long as you consistently store +4 (even when zero), prepending zeros shouldn't be a problem. Or maybe that was the issue, that +0000 is "valid" and therefore not good to mean "no +4". If that's it, how about negative for 5-digit. Right back to input and presentation logic.

    Someone please remind me what I'm forgetting.

    Other countries, for one thing. Off the top of my head Canada uses letters, and I'm sure it's not alone. Of course if other countries are remembered then the field is more apt to be called 'PostalZone' or the like.
    Aha! Don't be so easily fooled. Canada and Britain have letters in their codes? Nay, they are integers as well! You just have to handle them as base 36.

  • (cs) in reply to Mike D.

    AKA hexatridecimal.

  • (cs) in reply to Tony Janusky
    Tony Janusky:
    BrainSlugs83:
    Unless you're doing math on a value you shouldn't store or process it as a number. Numbers are for math, and counting, and statistics and such... Not zip codes. Just the fact that you have to add the extra zeros in at display time is wrong, and also, fully qualified zip codes contain non-numeric characters such as the hyphen.

    I once wrote a geographic distance approximation server that determines mileage based on zip code deltas. This is how I worked out the formula:

    Beverly Hills - Boston: 90210 - 02043 = 88167

    Zip distance = 88167 (That's 90210 - 02043) Actual distance = 2605 miles. Ratio = 33.84

    That's a pretty good sample to base all other possibilities on, so the function goes:

    int distanceBetweenZipcodes( int zip1, int zip2 ) { int zipDist = abs(zip1 - zip2); return (int)((float)zipDist / 33.84F); }

    You'd be amazed how accurate it is.

    Buffalo, NY (14201) to NYC, NY (10101) -- Calculates to 121 miles. Actual distance is about 350 miles.

    Beverly Hills to Ft. Lauderdale (33301) calculates to 1681 miles. Actual distance: 2700 miles.

  • Joe (unregistered) in reply to jrh
    jrh:
    Some Wonk:
    Santa is sick, and Christmas has been cancelled. What do you do, now?

    Start putting, commas where they, don't belong?

    No, that's for apo'strophe's, lo'ser!

  • Single User (unregistered) in reply to Procedural
    Procedural:
    code to "optimize" something that absolutely doesn't require optimization (the bar code generation can't usefully go faster than either image generation of label printing)
    Remind me not to hire you for optimizing code. Or for anything to do with real computers, for that matter!

    (A real computer is any computer that does real work, instead of sitting on a desktop entertaining a bored, overpaid moron who can't remember if he's on the job, or home watching TV.)

  • re:me (unregistered) in reply to RandomUser423689
    RandomUser423689:
    db2:
    java.lang.Chris;:
    The RWTF is that the code this snippet is embedded into presumably gets passed a string, when it should be passed an integer. Must have been written by one of those dynamically typed language loving cretins.
    That's cute. I'll bet you store zip codes as integers, too.
    I do feel like I'm forgetting something, but right now I can't remember why this wouldn't work. Sure, you have to have input and presentation logic to convert 00401-0203 to 4010203 and 79301-0000 to 793010000, and vice-versa; but as long as you consistently store +4 (even when zero), prepending zeros shouldn't be a problem. Or maybe that was the issue, that +0000 is "valid" and therefore not good to mean "no +4". If that's it, how about negative for 5-digit. Right back to input and presentation logic.

    Someone please remind me what I'm forgetting.

    because Canada has letters in their postal codes.

  • (cs) in reply to frits
    frits:
    Eve:
    Adam:
    IsNumeric() would allow currency symbols, negative signs, decimal points, etc - all of which can NOT be rendered as a bar code. The manager is right that the implementation would be different. The "Andy" in the story needs to STFU and not assume he is the smartest person in IT.
    Does it make you feel like a big man to hurl imaginary insults at people you've never met, for reasons you aren't even sure about? Please try to remember that this is a site for IT professionals, not angsty kids.

    Please try to remember this is a comments section for a comedy website specializing in IT. Insults = entertainment, lectures = tedium.

    Not to mention TheDailyWTF would be without mandate if they didn't daily hurl (or at least rethrow) insults at people they've never met, for reasons they aren't even sure about. After all, that's how stories like today's get posted--a lack of perspectives, a lack of context, and a lack of domain knowledge.

    Not that I care since when the WTF is on the poster it makes for just as good a story.

  • (cs) in reply to Jaime

    I agree. If there is any correlation between zip code and actual distances, it's a coincidence specific to a particular subset of US zipcodes.

    You should NEVER being doing math based on zipcodes. Especially when there are free web services that can do the actual distance look ups for you. Not to mention as someone already pointed out canada has letters in their zip codes (I always thought it was the UK, but apparently canada does also).

    There is a difference between a number, and a string containing only numeric digits. Each is a unique tool and has a unique scenario when it is appropriate.

  • (cs) in reply to Tony Janusky
    Tony Janusky:
    BrainSlugs83:
    Unless you're doing math on a value you shouldn't store or process it as a number. Numbers are for math, and counting, and statistics and such... Not zip codes. Just the fact that you have to add the extra zeros in at display time is wrong, and also, fully qualified zip codes contain non-numeric characters such as the hyphen.

    I once wrote a geographic distance approximation server that determines mileage based on zip code deltas. This is how I worked out the formula:

    Beverly Hills - Boston: 90210 - 02043 = 88167

    Zip distance = 88167 (That's 90210 - 02043) Actual distance = 2605 miles. Ratio = 33.84

    That's a pretty good sample to base all other possibilities on, so the function goes:

    int distanceBetweenZipcodes( int zip1, int zip2 ) { int zipDist = abs(zip1 - zip2); return (int)((float)zipDist / 33.84F); }

    You'd be amazed how accurate it is.

    A quick look at the zip code map and you'll see that, although it might look OK for some, there's many many holes.

    Extreme example. Gulfport Mississippi to Slidell Louisiana.

    Zip code difference: 30951 Projected distance: 915miles Actual distance: 45ish miles

  • Someone like Kevin (unregistered) in reply to Jaime
    Jaime:
    ammoQ:
    tiller:
    Why the hell is data converted to/from barcodes by the database?

    This is a task that the normal language (Php/Java/.net I guess) can do much faster, and without an insane implementation.

    Why should PHP be faster than, say, T-SQL or PL/SQL? Just because an interpreter is running in the database doesn't necessarily mean that it's slower.

    I believe "faster" refers to the developer accomplishing the task faster rather than the code executing faster. T-SQL is a horrible language and PL/SQL is only marginally better. Any modern language can do this as a one or two liner. The more important issue raised by the poster you responded to is that checking to see if something can be printed on a barcode seems to be UI validation code, not data layer validation code. For example, if the UI changes the barcode format to PDF417, the validation rules change. UI code in the database is not a good idea.
    select case when patindex('%[^1234567890]%', @barcodeValueSequence) > 0 then 'Non-Numeric Sequence Provided' else @barcodeValueSequence end

  • RandomUser423689 (unregistered) in reply to Random guy
    Random guy:
    RandomUser423689:
    db2:
    java.lang.Chris;:
    The RWTF is that the code this snippet is embedded into presumably gets passed a string, when it should be passed an integer. Must have been written by one of those dynamically typed language loving cretins.
    That's cute. I'll bet you store zip codes as integers, too.
    I do feel like I'm forgetting something, but right now I can't remember why this wouldn't work. Sure, you have to have input and presentation logic to convert 00401-0203 to 4010203 and 79301-0000 to 793010000, and vice-versa; but as long as you consistently store +4 (even when zero), prepending zeros shouldn't be a problem. Or maybe that was the issue, that +0000 is "valid" and therefore not good to mean "no +4". If that's it, how about negative for 5-digit. Right back to input and presentation logic.

    Someone please remind me what I'm forgetting.

    Other countries, for one thing. ... Of course if other countries are remembered then the field is more apt to be called 'PostalZone' or the like.
    Indeed, I was referring specifically to ZIP codes. Accommodating other countries would bring a different set of specifications to the table.

    Random guy:
    Regardless, ISNUMERIC isn't useful ...
    I'll assume this is in reference to the main article; I did not intend to imply that ISNUMERIC would help with ZIP codes.
    BrainSlugs83:
    Unless you're doing math on a value you shouldn't store or process it as a number. Numbers are for math, and counting, and statistics and such... Not zip codes.
    I will agree in some cases and disagree in others. It all depends on the requirements. If time is of the essence, and mapping ZIP codes into into another (valid) representation saves 10s of hours of batch processing time, versus barely-noticeable slowdowns running presentation logic, in user time, then we have a winner.
    BrainSlugs83:
    Just the fact that you have to add the extra zeros in at display time is wrong, and also, fully qualified zip codes contain non-numeric characters such as the hyphen.
    By that logic, I presume it is "wrong" to need input and presentation code for anything else that can be validly represented by another datatype.

    The fact that proper ZIP codes have simple, ridgedly defined layout makes determining the non-numeric characters and their positions trivial. Just because an array of generic-characters is the closest thing to an array of class-of-characters, neither means it is the only valid way to store the information, nor means it is (in some cases) the most efficient for processing.

  • Procedural (unregistered) in reply to Single User
    Single User:
    Procedural:
    code to "optimize" something that absolutely doesn't require optimization (the bar code generation can't usefully go faster than either image generation of label printing)
    Remind me not to hire you for optimizing code. Or for anything to do with real computers, for that matter!

    (A real computer is any computer that does real work, instead of sitting on a desktop entertaining a bored, overpaid moron who can't remember if he's on the job, or home watching TV.)

    Instead of just throwing insults around, could you point out the flaw in my argument, or do you just get that extra zest for life that keeps you from shooting your sorry low-self-esteem brains by coming on the board and showing what a better man you are ?

    (Hint 1: You do not hire people anyway, so you wouldn't be in a position to hire me; you are a sad loner. You probably dont even have a girlfriend who loves you. Hint 2: I certainly wouldn't hire you. And I hire a lot of people. We dont accept sad loners on the team. Happy loners yes. Sad ones bring everybody down.)

  • commenter88 (unregistered)

    In defense of the manager, this is obviously a 2 phase project.

    Phase 1:

    step 1) translate the code identically

    step 2) validate the new code

    Phase 2: upgrade/revise the new code base

  • Procedural (unregistered) in reply to Procedural
    Procedural:
    Single User:
    Procedural:
    code to "optimize" something that absolutely doesn't require optimization (the bar code generation can't usefully go faster than either image generation of label printing)
    Remind me not to hire you for optimizing code. Or for anything to do with real computers, for that matter!

    (A real computer is any computer that does real work, instead of sitting on a desktop entertaining a bored, overpaid moron who can't remember if he's on the job, or home watching TV.)

    Instead of just throwing insults around, could you point out the flaw in my argument, or do you just get that extra zest for life that keeps you from shooting your sorry low-self-esteem brains by coming on the board and showing what a better man you are ?

    (Hint 1: You do not hire people anyway, so you wouldn't be in a position to hire me; you are a sad loner. You probably dont even have a girlfriend who loves you. Hint 2: I certainly wouldn't hire you. And I hire a lot of people. We dont accept sad loners on the team. Happy loners yes. Sad ones bring everybody down.)

    I mean, you are not one of those geniuses who would spend even a single man-hour optimizing away what would amount to a few seconds of machine time over the lifespan of a non-real-time app are you ?

  • NutDriverLefty (unregistered) in reply to jrh
    jrh:
    Start putting, commas where they, don't belong?

    Is that you, Captain Kirk?

  • Gary (unregistered) in reply to NutDriverLefty

    Here's the problem with is numeric.

    Select ISNUMERIC('$12355.23').

    Technically, that's a string, however ISNUMERIC() is "smart" enough to figure out you mean money.

  • ke (unregistered)

    Where's the WTF?

  • Single User (unregistered) in reply to Procedural
    Procedural:
    Procedural:
    Single User:
    Procedural:
    code to "optimize" something that absolutely doesn't require optimization (the bar code generation can't usefully go faster than either image generation of label printing)
    Remind me not to hire you for optimizing code. Or for anything to do with real computers, for that matter!

    (A real computer is any computer that does real work, instead of sitting on a desktop entertaining a bored, overpaid moron who can't remember if he's on the job, or home watching TV.)

    Instead of just throwing insults around, could you point out the flaw in my argument, or do you just get that extra zest for life that keeps you from shooting your sorry low-self-esteem brains by coming on the board and showing what a better man you are ?

    (Hint 1: You do not hire people anyway, so you wouldn't be in a position to hire me; you are a sad loner. You probably dont even have a girlfriend who loves you. Hint 2: I certainly wouldn't hire you. And I hire a lot of people. We dont accept sad loners on the team. Happy loners yes. Sad ones bring everybody down.)

    I mean, you are not one of those geniuses who would spend even a single man-hour optimizing away what would amount to a few seconds of machine time over the lifespan of a non-real-time app are you ?

    Oh my god you nailed me! How did you know? I lost my job as a manager and my girlfriend left me. I haven't had sex in four years!

    But at least I don't reply to my own posts.

    (Hint 0: My nickname "Single User" refers to the only computers you've ever seen, not to my relationship status. But nice try...)

  • Monkey (unregistered)

    Where's the WTF? Are you too retarded too understand that it does NOT exactly replicate ISNUMERIC(). Your boss is right and you should be fired.

  • Dude (unregistered) in reply to re:me

    You are forgetting that there is other country in the world than your stupid empire.

  • Homer (unregistered) in reply to Anonymous
    Anonymous:
    Everyone is a little bit wrong here:

    Andy shouldn't be using IsNumeric without any further processing because, as others have commented, it will return true for numeric symbols such as a decimal point. However, I'm going to give Andy the benefit of the doubt and assume that his revised function handled these cases. After all, the article specifically says that he researched the IsNumeric function and it's behaviour in this regard is perfectly well documented.

    The manager is wrong for thinking that a piece of code has to be written in the same way to function the same way. In any programming language there are a myriad of ways to code exactly the same function. Only a clueless manager would assume that two pieces of code have to perform exactly the same steps in order to perform the same function.

    Personally speaking, the manager scores highest on my WTF meter.

    I've found that the fastest way to work a whole lot of unscheduled overtime is to start improving code during a port.

  • Homer (unregistered) in reply to savar
    savar:
    What is the WTF?

    Unless the system is under test, their best bet is to transliterate the semantics of one system to the other. Other parts of the system may rely on that idiosyncratic behavior.

    +1

  • Homer (unregistered) in reply to DOA
    DOA:
    TRWTF is that Andy went to his boss to talk about implementation details. Only newbies do this. Experienced developers get the gist of what has to be done and keep the implementation to themselves. They do not discuss low-level code issues with management, because there is a very real risk that some clueless manager might start coming up with brillant ideas of the type "we should use XML because I keep hearing about it" and "we need to write this application in AJAX"
    An experienced dev would have quickly converted the function per spec, and moved on. Nothing to discuss.

    Junior did what juniors do, but was wise enough to discuss.

    Manager praised junior for being pro-active, but realized this was not the time. End of discussion.

  • RandomUser423689 (unregistered) in reply to Dude
    Dude:
    You are forgetting that there is other country in the world than your stupid empire.
    No, clearly what I forgot is that most commenters on TDWTF don't bother to read all the comments and their context.

    I was replying to a comment about ZIP codes. I assumed (perhaps incorrectly) that they were referring to USPS ZIP codes. I realize other countries have postal codes similar in purpose to USPS ZIP codes, that have different properties than USPS ZIP codes. If there are other countries that call their postal codes "ZIP codes", I am unaware of them, but I would interested to learn about these non-USPS postal ZIP codes.

  • Magus (unregistered) in reply to RandomUser423689
    RandomUser423689:
    Dude:
    You are forgetting that there is other country in the world than your stupid empire.
    No, clearly what I forgot is that most commenters on TDWTF don't bother to read all the comments and their context.

    I was replying to a comment about ZIP codes. I assumed (perhaps incorrectly) that they were referring to USPS ZIP codes. I realize other countries have postal codes similar in purpose to USPS ZIP codes, that have different properties than USPS ZIP codes. If there are other countries that call their postal codes "ZIP codes", I am unaware of them, but I would interested to learn about these non-USPS postal ZIP codes.

    Most English-speaking countries call them postcodes, but the Philippines (as a former US colony) refer to them as ZIP codes as well, apparently. http://www.nscb.gov.ph/activestats/zipcode/ for more information.

    In any event, due to the pervasiveness of American television programmes throughout the world, it is highly likely that the term 'zip code' is interchangeable with 'postcode' - or at least understood as such.

  • Xris (unregistered)

    Sigh... a simple googling provides (http://www.techonthenet.com/oracle/questions/isnumeric.php) that using

    ISNULL(LENGTH(TRIM(TRANSLATE(string1, '0123456789', ' '))))
    would be a valid test in this case, and
    LENGTH(string1) = X
    will test for the correct length (depending on the barcode standard used).

    The manager was right in that case... if testing for barcodes, ISNUMERIC alone would not be equivalent to the provided code.

    Captcha: saepius - S.A. Pius, a ship named after a pope?

  • sparky (unregistered) in reply to hatterson

    How about Antelope, OR (97001) to Agana, Guam (96910)?

    Zip code difference: 91 Projected distance: 2.6 miles Actual distance: 5787.7 miles

    I hope you were joking about that algorithm...

  • Channel6 (unregistered) in reply to Jon
    Jon:
    The real WTF is the manager used the phrase, "think outside the box."

    Sounds pretty manager-ish to me

  • (cs)

    This is actually a valid approach by the manager.

    It is quite easy to look at two pieces of PL/SQL and T-SQL code and verify that they perform the same. It's not so easy to look at a piece of PL/SQL code and know that it functions the same as a named T-SQL function without source code for that function.

    In order to verify that they both perform the same, we would need to know that they both returned the same value for a null input; we would need to know that they returned the same value for an input which included padding spaces; we would need to know if they returned the same output for arbitrarily-long strings (the ISNUMERIC may convert to a 32- or 64-bit integer and fail for longer inputs); we would need to know what it does for inputs with leading zeros; we would need to know if works on integers or floats.

    In short, there are too many edge cases where the behavior might vary, that it's safer to copy it as-is than replace it with something that may or may not behave exactly the same.

    Since the stated goal of the project is to have the two systems "work exactly the same", the manager is taking the safest approach for ensuring that his project is completed correctly and on time.

    I would likely do the same.

    TRWTF is not the manager requesting identical code, but the original version's developer writing such strange code instead of using a library function.

  • Procedural (unregistered) in reply to Single User
    Single User:
    Procedural:
    Procedural:
    Single User:
    Procedural:
    code to "optimize" something that absolutely doesn't require optimization (the bar code generation can't usefully go faster than either image generation of label printing)
    Remind me not to hire you for optimizing code. Or for anything to do with real computers, for that matter!

    (A real computer is any computer that does real work, instead of sitting on a desktop entertaining a bored, overpaid moron who can't remember if he's on the job, or home watching TV.)

    Instead of just throwing insults around, could you point out the flaw in my argument, or do you just get that extra zest for life that keeps you from shooting your sorry low-self-esteem brains by coming on the board and showing what a better man you are ?

    (Hint 1: You do not hire people anyway, so you wouldn't be in a position to hire me; you are a sad loner. You probably dont even have a girlfriend who loves you. Hint 2: I certainly wouldn't hire you. And I hire a lot of people. We dont accept sad loners on the team. Happy loners yes. Sad ones bring everybody down.)

    I mean, you are not one of those geniuses who would spend even a single man-hour optimizing away what would amount to a few seconds of machine time over the lifespan of a non-real-time app are you ?

    Oh my god you nailed me! How did you know? I lost my job as a manager and my girlfriend left me. I haven't had sex in four years!

    But at least I don't reply to my own posts.

    (Hint 0: My nickname "Single User" refers to the only computers you've ever seen, not to my relationship status. But nice try...)

    Yadi yadi yada. All insults, not one single cogent or useful argument. You are a troll. Buzz off.

  • Paster (unregistered) in reply to Anonymous
    Anonymous:
    Everyone is a little bit wrong here:

    The manager is wrong for thinking that a piece of code has to be written in the same way to function the same way. In any programming language there are a myriad of ways to code exactly the same function. Only a clueless manager would assume that two pieces of code have to perform exactly the same steps in order to perform the same function.

    Personally speaking, the manager scores highest on my WTF meter.

    Eh. Anyone who has done a bit of this even remotely this type of work knows that when you change things, they break. Then you have to debug the system to get it working, at least if you're lucky enough to notice that it no longer works correctly...

    Actually the case is often exact opposite of what's presented as the WTF. Original code uses a built-in/library function. The new system doesn't have a function that behaves exactly the same, there's a slight difference. So in the new environment, the original function is re-implemented instead of using the new environment's subtly different default function.

  • csrster (unregistered) in reply to JB
    JB:
    I dunno...it seems perfectly reasonable to ask that a piece of production code, which probably interacts with a great many equally warty codes, do the exact same thing, at least at first. I could see implementing Andy's fix down the road (or rolling into the SQL Server code, if it weren't being transitioned to Oracle), but starting out by changing things just seems like a bad idea.

    Now, before I get pilloried, let me explain. There're inevitably going to be bugs in the transition from SQL Server to Oracle, and being able to say "we implemented it the exact same way as before" provides a basis on which to debug. You can compare the two codes line by line, and figure out what didn't get translated correctly (or what function has different side effects, &c). While that code snippet probably doesn't have any funny side effects, it's possible that another one might, and "improving" the code as you translate could introduce/get rid of side effects that could change the behavior of the system. There's a time and place for improvement, but that just seems like it's premature--I agree with Andy's boss on this one.

    The real WTF is you expecting to get pilloried for saying somthing correct.

  • (cs) in reply to Magus
    Magus:
    RandomUser423689:
    Dude:
    You are forgetting that there is other country in the world than your stupid empire.
    No, clearly what I forgot is that most commenters on TDWTF don't bother to read all the comments and their context.

    I was replying to a comment about ZIP codes. I assumed (perhaps incorrectly) that they were referring to USPS ZIP codes. I realize other countries have postal codes similar in purpose to USPS ZIP codes, that have different properties than USPS ZIP codes. If there are other countries that call their postal codes "ZIP codes", I am unaware of them, but I would interested to learn about these non-USPS postal ZIP codes.

    Most English-speaking countries call them postcodes, but the Philippines (as a former US colony) refer to them as ZIP codes as well, apparently. http://www.nscb.gov.ph/activestats/zipcode/ for more information.

    In any event, due to the pervasiveness of American television programmes throughout the world, it is highly likely that the term 'zip code' is interchangeable with 'postcode' - or at least understood as such.

    True. Here in Australia we use four digit postcodes, but we know that 'zip code' means the same thing. And at my workplace they're stored in a ZIPCODE column since our software platform is American. Fortunately, it's a string column so that we can accommodate the occasional customer with an address in the UK or wherever.

    Of course, other than Australian postcodes, our members mainly use it for things like 'DO NOT CONTACT', but we have the occasional 'GU7 2PR' or whatever in there as well.

    One thing about the original submission still puzzles me (the other good points have already been made). Why was the developer recommending IsNumeric in the language he was porting from, when it doesn't exist in the language he was porting to? Even if only integer-compatible strings were used and the currency and other "numeric" symbols were somehow not a problem, what was he hoping to achieve?

  • Anonymous (unregistered) in reply to csrster
    csrster:
    JB:
    I dunno...it seems perfectly reasonable to ask that a piece of production code, which probably interacts with a great many equally warty codes, do the exact same thing, at least at first...

    Now, before I get pilloried, let me explain...

    The real WTF is you expecting to get pilloried for saying somthing correct.

    Don't be ridiculous, that's not the real WTF - it's perfectly normal around here. Consider yourself both pilloried you pair of simpering morons.

  • Sir Robin the Not-Quite-So-Brave-As-Sir-Lancelot (unregistered) in reply to RandomUser423689
    RandomUser423689:
    db2:
    java.lang.Chris;:
    The RWTF is that the code this snippet is embedded into presumably gets passed a string, when it should be passed an integer. Must have been written by one of those dynamically typed language loving cretins.
    That's cute. I'll bet you store zip codes as integers, too.
    I do feel like I'm forgetting something, but right now I can't remember why this wouldn't work. Sure, you have to have input and presentation logic to convert 00401-0203 to 4010203 and 79301-0000 to 793010000, and vice-versa; but as long as you consistently store +4 (even when zero), prepending zeros shouldn't be a problem. Or maybe that was the issue, that +0000 is "valid" and therefore not good to mean "no +4". If that's it, how about negative for 5-digit. Right back to input and presentation logic.

    Someone please remind me what I'm forgetting.

    Zip codes in other countries than the USA may not be numeric. For example in the Netherlands they are 4 digits + 2 letters.

  • (cs) in reply to Anonymous
    Anonymous:
    ammoQ:

    On the other hand, it's trivially easy to formaly prove that program B is an 1:1 translation of program A (exactly the same steps in order to perform the same function), while it is generally speaking difficult to impossible to prove that a differently written program B gives the same result like program A. To be on the safe side, requiring an 1:1 translation doesn't seem unreasonable to me.

    I see exactly where you're coming from and I agree with your sentiment. But testing a function/program/system should be a complete task in and of itself and it should be possible to do this without ever seeing the code (ie. as a black box). If you're porting a legacy system, for example, you should not be forced to write logically identical code to the old system just because it makes it easier to prove that the new functions the same as the old. You should write the code in the most effective manner provided by your language and then identify any differences through a thorough test schedule.
    This assumes that a test for each function/program/system already exists for the old system. Let's say it doesn't. So, while you translate the system from the old language to the new language, you are also writing unit tests along the way. But obviously to write those unit tests, you need a good understanding what exactly the old function did. Chances are, you misunderstand the old program every now and then, and write the new functions and their tests accordingly. Your unit tests perfectly work with the new program, which unfortunately behaves slightly different like the old one. It's up to the integration tests or acceptence tests to find out something is wrong. It could be in any of those 1000s of pesky functions, all of which satisfy their unit tests.

  • (cs) in reply to Aussie Contractor
    Aussie Contractor:
    ISNUMERIC("First") = TRUE; // what ??

    Nowhere on the name it says it will only accept cardinal numbers.

  • (cs) in reply to ammoQ
    ammoQ:
    Why should PHP be faster than, say, T-SQL or PL/SQL? Just because an interpreter is running in the database doesn't necessarily mean that it's slower.

    Making an extra trip to the network layer, a connection handshake, argumment passing, context switching if on the same machine, or waitting for a slow network connection if on different machines, and to top all, offloading work fom cheap and easily replicated resources (web servers) to expensive servers that won't replicate at all (as both Oracle and MSSQL won't), but even if the software were less of an WTF, would face several basic problems for replication, not being able to achieve proportional speedup.

    No, no reason for calling the database everytime being a problem at all.

  • Nido Media (unregistered) in reply to toth

    Are you sure you want to match END_OF_STRING, followed by some number characters, followed by BEGIN_OF_STRING?

  • Adam (unregistered) in reply to Markp
    Markp:
    frits:
    Eve:
    Adam:
    IsNumeric() would allow currency symbols, negative signs, decimal points, etc - all of which can NOT be rendered as a bar code. The manager is right that the implementation would be different. The "Andy" in the story needs to STFU and not assume he is the smartest person in IT.
    Does it make you feel like a big man to hurl imaginary insults at people you've never met, for reasons you aren't even sure about? Please try to remember that this is a site for IT professionals, not angsty kids.

    Please try to remember this is a comments section for a comedy website specializing in IT. Insults = entertainment, lectures = tedium.

    Not to mention TheDailyWTF would be without mandate if they didn't daily hurl (or at least rethrow) insults at people they've never met, for reasons they aren't even sure about. After all, that's how stories like today's get posted--a lack of perspectives, a lack of context, and a lack of domain knowledge.

    Not that I care since when the WTF is on the poster it makes for just as good a story.

    Funny how easily offended (supposed) smart people are on a technology website dedicated to comedy. As a fellow programmer for 10+ years I have seen "Andys" try to prove their worth by tearing apart older systems. Competence begets maturity, both of which the "Andy" in the story sadly does not posses. Quickly seeing the "Andy" for the self-serving attention whore that he is should evoke a smile, not a discussion on Al Gore's politics.

  • Emtucifor (unregistered)

    The person who wrote the SQL Server function in the first place was a bit inexperienced, to be kind:

    IF @Input LIKE '%[^0-9]%' BEGIN --non-numeric character in string END

  • RandomUser423689 (unregistered) in reply to Sir Robin the Not-Quite-So-Brave-As-Sir-Lancelot
    Sir Robin the Not-Quite-So-Brave-As-Sir-Lancelot:
    Zip codes in other countries than the USA may not be numeric. For example in the Netherlands they are 4 digits + 2 letters.
    Just curious, does the postal system for the Netherlands actually call it a "ZIP code"? Or, have the residents of the Netherlands just picked it up as slang?
  • (cs) in reply to NutDriverLefty
    NutDriverLefty:
    jrh:
    Start putting, commas where they, don't belong?

    Is that you, Captain Kirk?

    Well done.

  • (cs) in reply to Jaime
    Jaime:
    Tony Janusky:
    BrainSlugs83:
    Unless you're doing math on a value you shouldn't store or process it as a number. Numbers are for math, and counting, and statistics and such... Not zip codes. Just the fact that you have to add the extra zeros in at display time is wrong, and also, fully qualified zip codes contain non-numeric characters such as the hyphen.

    I once wrote a geographic distance approximation server that determines mileage based on zip code deltas. This is how I worked out the formula:

    Beverly Hills - Boston: 90210 - 02043 = 88167

    Zip distance = 88167 (That's 90210 - 02043) Actual distance = 2605 miles. Ratio = 33.84

    That's a pretty good sample to base all other possibilities on, so the function goes:

    int distanceBetweenZipcodes( int zip1, int zip2 ) { int zipDist = abs(zip1 - zip2); return (int)((float)zipDist / 33.84F); }

    You'd be amazed how accurate it is.

    Buffalo, NY (14201) to NYC, NY (10101) -- Calculates to 121 miles. Actual distance is about 350 miles.

    Beverly Hills to Ft. Lauderdale (33301) calculates to 1681 miles. Actual distance: 2700 miles.

    I'm amazed.

  • Kirby L. Wallace (unregistered) in reply to Aussie Contractor

    If "First" is the name of a numeric column in a table, and it contains a number...

    What you are wanting to see, I think, is

    IsNumeric('FIRST')

    Double Quotes are identifiers... like column names.

Leave a comment on “Warts and All”

Log In or post as a guest

Replying to comment #:

« Return to Article