• Aaron (unregistered)

    What about IsDate? And he even did leap year checking wrong.

  • Ben Hutchings (unregistered)

    The "Stop" in the middle of this makes me a little dubious that this is actually production code. Isn't that like a breakpoint in VB?

  • Frans Bouma (unregistered)

    w00t! :D Amazing stuff these highly payed super specialists can poop out :)

    What's that 'Stop' statement doing btw... ? :)

  • Bruce (unregistered)

    Yeah, the STOP statement halts execution dead in its tracks. That's priceless!

  • Thomas Eyde (unregistered)

    I realize I am hopelessly underpaid.

    BTW, stop acts like a breakpoint in the debugger and like an exception beyond repair in production.

  • Matt K (unregistered)

    Just goes to show that it doesn't take skill and knowledge to command $250/hr... just huge cajones.

  • skicow (unregistered)

    Holy S.

    Why is a function that is defined as an integer returning a boolean? Guess this $250/hr. programmer hasn't heard of Option Strict On.

  • Dan (unregistered)

    What happens if you do validDate("xx/xx/xxxx")...

    If i'm correct about this code, wouldn't it do Cint(theDay) where theDay would be equals to "xx" ?
    And what does CInt return ? A zero or an error ?

    I especially like the "For i = 3 To 6" since just under it he does a Mid anyway.

  • Phil (unregistered)

    Maybe that means they estimate it would take $50M to /fix/ the code.

  • Bart (unregistered)

    Ill do that for 100 a day ;p

  • Theologian (unregistered)

    Are they hiring?

  • Tony (unregistered)

    Wow,

    All that and he didn't even use the "Step" keyword in the "For" loop. I think I need a raise.

  • Gavin (unregistered)

    My Big Blue Hypothesis: SLOC is proportional to $'s earned.

  • TheF0o1 (unregistered)

    Let's see...

    - currentYear is assigned but never used

    - Numerous exit paths (14 to be exact) really scare me. Fortunately there's no state other than the return value. But still that's a lot more assignments than necessary.

    - Is that really the way to do a "for" loop with a step of 2 in this language?

    - They're assume a very specific date format "mm/dd/yyyy" or "mm-dd-yyyy" or "mm.dd.yyyy" or "" (blank).

    - Could "Mid" really return an empty string? Particularly when you already know the length is 10? I think there's some unreachable code here.

    - On a month with 30 days, the year is never validated. Come to think of it, the year is never really validated at all!

    - Oops... leap year logic is not that simple.

    - If the month is 2, 4, 6, 9, or 11 then it is valid. If it's something else then it's valid too, as long as the day is between 1 and 31 inclusive.

    My new favorite date is: "01/Uh-WTF!"

  • Ron (unregistered)

    My "take-away" from this code is the most awesomest operator I've seen yet today: "><"

  • A. Consultant (unregistered)

    I think some of you may be confused about what IBM charges and what the moron who flung this code poo gets paid.

    Consultants at big shops, we get paid about average. You can actually do better outside of consulting, but the experience and exposure to enterprise projects balances that out a bit.

    Some of us know what we're doing, some of us don't have a clue. There is a riculous amount of fat in between the consultant and the client. I could do the math for you, but it's galling.

    I've seen code nearly this bad from peers. I've also seen some amazingly good stuff. I can't definitively say which one you're guaranteed to get if you hire a big shop like this one.

    In any event, mileage will totally vary re: quality, just don't go around thinking the consulting shop's bodies are the one's getting rich. Maybe it happens, I can also attest to the opposite.

  • Jason Hasner (unregistered)

    I pulled as much as 160 an hour the semester that I was graduating. I got $30 an hour of that and a nice bonus every now and then. The trade off was I got $30 an hour even when I wasn't billing the client. I was happy, the boss was happy, and I made damn sure the client was always happy. As the above post says, there is a lot of fat in there. My impression was that the most important skill you could have as a consultant was not programming, but effective communication.

    Just my two cents.

  • Cakkie (unregistered)

    OMFG, someone please help me back on my chair because I just fell off. However, I have my doubts with the credibility of this. This is non-functional code, containing things the VB IDE does not allow (maybe he used notepad to write it)

    Nevertheless, I reward this guy an award for following achievements:

    - best custom implementation of the Step in a For Loop

    - keeping nostalgia alive (stop instead of Debug.Assert)

    - his l33t notation of not equal >< instead of the usual <> (actually VB automatically changes >< in <>, is this code for real?)

    - double checking that a Mid from chars 3 to 5 of a string you are 100% sure of is 10 characters, does not return an empty string.

    - the remarkable learning curve he went through, in the beginning he checked for an empty string using Len(string), but he must have realized that that would imply an extra function call which is less efficient as checking for ""

    - making every year a leap year (he never assigns yearNumber, making is 0, and 0 Mod 4 is 0). Additionally, some other logic involving leap years is missing

  • WanFactory (unregistered)

    This just in, IBM has realized that they have been exploiting their employees by charging them out at $250 an hour and paying their employees only 10% - 15% that ammount. To atone for their misdemeanors, they have agreed to provide $50M worth of compensation to their employees on the following valid dates:

    13/13/2004 (a very lucky day indeed!)
    29/02/2100 (the day IBM declares Pope Gregory to be an anti-Pope)

  • AndyL (unregistered)

    The RSS feed for TheDailyWtf seems to claim it's time-stamps are in GMT... but they appear to be good old Eastern Standard Time.

    This causes sorting problems for the feed reader that I use. Am I the only one with this problem?

  • Tim Cartwright (unregistered)

    Cakkie - you were joking when you said this?:

    "
    - the remarkable learning curve he went through, in the beginning he checked for an empty string using Len(string), but he must have realized that that would imply an extra function call which is less efficient as checking for ""
    "

    http://www.aivosto.com/vbtips/stringopt.html

  • Dr.Funk (unregistered)

    The correct way to check for an empty string in VB is by calling Len.

  • Cakkie (unregistered)

    @Tim C: My guess is that he decided to sacrefice the performance gain of Len for the time he saved out typing "" instead of Len :p

    @Funk: since Len$ uses string rather than variant as it's argument, it will run faster than Len. Since LenB looks at the string in a binary fashion, it will be faster than Len$.

  • Bart (unregistered)

    Aggrevating to think that i cant get a job doing this :(

  • Andrew Tetlaw (unregistered)

    I see everyone is scratching their heads, but I think that this is not VB, it's actually LotusScript from a Lotus Notes database. LotusScript is almost identical to VB.

    The clues:

    - The reason why it returns an integer and not a boolean is that the boolean datatype didn't exist in LotusScript until Notes Domino 6 and this is probably an earlier version where you needed to use an integer.

    - The Lotus Notes IDE will not change a >< into a ><> automatically.

    - stop's left in production code. Everything's RAD in the world of Notes :P

    - "'a blank date is considered valid as it is not a mandatory field" : only a notes consultant would attempt to write a generic function to check a date and then incomprehensibly screw it up by making applicable to only one field on a form

    - only a notes consultant would write a validation function that only works if the input is correct. This is really only checking if the numbers in the date are within certain bounds because cint() will raise an error if it can't turn a string into an integer. And because there's no error handling in here the function will just bomb out and not actually return anything.

    - only notes consultants constantly use strings for dates (even though LotusScript has native date handling, a DateTime class and notes forms have a DateTime field type) and are required to write crap like this to constantly check strings, convert strings etc...



    (caveat: I am a Lotus Notes developer :P )


  • Centaur (unregistered)

    When testing my code, I like to set up crazy date and time formats like "yyyy#MM+dd" and "HH$mm" and see what blows up, what just breaks, what looks different and what continues to work. This piece of code will not pass that check…

  • RPG Fallout (unregistered)

    I suspect that the IBM programmer in question is more used to RPG. (RPG is an old language for IBM mainframes- it's known as an accountant's language because everything goes into neat little columns and boxes, with plenty of special cases and rules)

    In RPG (especially earlier versions with fixed format only) you have to create millions of fields (variables) at the top of the program since the declerations have to be seperate from code and each line of code does exactly one operation. Notice how each line does one operation (except for boolean expressions, which are supported in RPG IV or with multiple indicators before that)

    There is no step clause in for statements in RPG.

    The select case equivalent is similar, and special case handling for special values is very common.

    The naming convention like theDay and dayNumber is common.

    'Manditory field' is an IBM term.

    Fixed-length date fields are always used in RPG since almost all data on IBM systems are fixed-length partitioned strings; I think that's why only dates in the form dd/mm/yyyy, even when one part could be 1 digit (it would need a leading zero) Dates are usually stored as 8 character fixed length strings in the form DDMMYYYY.

  • RJ (unregistered)

    Ugh, no wonder all our jobs have left for India.

  • Ray S (unregistered)

    Jason Hasner:
    "My impression was that the most important skill you could have as a consultant was not programming, but effective communication."

    Unfortunately someone told that to this guy, and he took it to the Nth degree... (Only he probably forgot the communication part)

  • Ted Kubaska (unregistered)

    Well, I guess being a knockout programmer means you don't have time to learn out to spell seperate (sic).

  • Brad C (unregistered)

    The only thing I'll defend here is the Leap Year logic. (I won't defend the fact he never actually assigns a value to YearNumber, though. That's just stupid.)

    YES, it is true that the CORRECT implementation of leap year logic would include the following obscure exceptions:
    #1 - Leap year every 4th year except for years divisible by 100.
    #2 - Years divisible by 400 are leap years despite exception #1.

    If you failed to implement either of these exceptions, the nearest years that would actually cause you any problems would be 1900 and 2100. (2000 is a leap year by either correctly applying exceptions 1 and 2, or by ignoring them both)

    And if all dates of the application were well within this range, as they would be in most examples I can think of, he'd be fine. (Date of loan closing, date of account opening, date of product sale, etc.).

    How many programmers think their application will really be around till the year 2100 ? (Of course, that's what everyone thought about 2000, too.)

  • M (unregistered)

    What Andrew said about this being LotusScript is probably accurate. I thought that too when I saw the boolean being returned as an Integer. Also makes sense if this was an IBM consultant, since they'd be writing either LotusScript or Java these days :)

  • Anon (unregistered)

    >> What about IsDate?

    IsDate in VB 6 is often unusable. For example, if local date format is dd/mm/yyyy (which presumably it is in the above code) then IsDate will return True for 12/13/2001.

    >> since Len$ uses string rather than variant as it's argument, it will run faster than Len.

    There is no Len$ function. The $ would indicate the return type, not the parameter type - and obviously the return type of Len would not be a string.

  • CRConrad (unregistered)

    Yup, simplifying the leap year logic from three rules to one still leaves plenty of valid years, from 1901 to 2099...

    And actually, some commercial applications seem to have taken advantage of this: Could there be any other sensible reason why MS Excel, for example (at least in older versions) has a valid date range from March 1st, 1900 to (IIRC) February 28th, 2100?

    Those dates are far too leap-year-specific -- just after the non-existent "February 29th" of 1900, and just before the non-existent "February 29th" of 2100 -- for it to be anything else, IMO, than definitive proof that Excel uses a one-rule leap year logic.

  • Thomas Eyde (unregistered)

    I am so sick and tired of reading arguments like Left$() is faster than Left() because the latter uses a variant, which not only is slower, but also takes up more memory.

    On what system what-so-ever will this difference be detectable by other than a hi-res timer?

    Anyhow, your problem is never where you think they are. Use a profiler and find the real bottleneck.

    One should think we were rid of such statements by now, but some people seems to be stuck in old thinking. Take a class in premature optimization.

  • Brian Duffy (unregistered)

    I've seen alot worse out of IGS guys. One of the best was particularly clueless Tivoli consultant who was supposedly a Prolog expert. (Prolog is used in the IBM/Tivoli Enterprise Console rule engine)

    This genius had a habit of writing prolog code that would spawn a shell process which would then spawn a perl, python or awk script (who needs consistency) to process the event.

    I wish I still had some sample code around.

  • Matthew Morris (unregistered)

    To be fair to MS Excel, they deliberately made the 1900 leap year wrong for backward compatibility with Lotus 1-2-3, which had exactly the same problem.

    So it's all Lotus's fault again :o)

  • Techfiend (unregistered)

    Um, well at least he has comments... shrug

    :)

    TF

  • Arka Nada (unregistered)

    Trouble is, he/she (do we know it's a man?) has left out the most important comment: what the function is trying to do.

    If this kind of comment had appeared at the top of the function, it would be much easier to discern the, ahem, quality of the following code.

  • nigerianscammer1338 (unregistered)

    might as well rename the site to
    www.thedailyhoax.com

  • OMG_WTFWT (unregistered)

    I'd like to imagine that the author of this rubbish is a visitor to this place. He's probably laughing himself/herself sick knowing that he's robbing people blind by churning out this kind of crap and being paid a fortune for it.

    Re-writing core functionality (wrongly) is always good for a laugh

  • LMAO (unregistered)

    Besides the reserved VB keywords, not one word of that code is worth the server/database space this thread is occupying...

  • (cs)

    Hi, I just found this site.  Great stuff.

    Contrary to some speculation, this code:

           For i = 3 To 6
                separator = Mid ( dateString, i, 1 )
               
                If Not ( separator = "/" Or separator = "-" Or separator = "." ) Then
                  validDate = False
                  Exit Function
                End If
                i = i + 2
           Next

    is not trying to do a step 2.  It's a step 3.  The loop var gets incremented by 1 anyway, and he adds two more.  He's just checking positions 3 and 6 for the separators.  "For i = 3 to 6 step 3" would have worked just as well.

    But there's so much wrong with this, that this one step doesn't really matter! 

  • (cs) in reply to Dan
    :
    And what does CInt return ? A zero or an error?


    If the parameter is not convertable to an integer, CInt generates an error, which would, in effect stop the execution, since there's no error handling of any sort.

    And, since he's only checking for empty strings in the If above the CInt, something of a form "5/dec/2004" would surely crash this monstrosity.
  • (cs)

    How old is this code?

    It actually looks like VB3 where integers were used for booleans and nice functions such as IsDate didn't exist.

  • MylesB (unregistered)

    here, i fixed this part.

    Stop 'hammer time

  • C (unregistered) in reply to TheF0o1
    TheF0o1:
    My new favorite date is: "01/Uh-WTF!"
    Actually, there's still "Cint ( theMonth )", so that wouldn't be valid. Some actual examples would be: "20/-6-=WTF" and "01-99/>:-)"... ;-)

Leave a comment on “Your $2000 Function”

Log In or post as a guest

Replying to comment #:

« Return to Article