• 2010-05-06 (unregistered)

    frist business comment of month

  • P (unregistered)

    Is the next part of the series going to be IntManager? Because obviously, to get Maximum Performance out of integers you gotta cache the different value instances to prevent runtime allocations of already allocated integers. Every byte counts.

  • Little Bobby Tables (unregistered)

    Am I the only one to read _bldr and interpret it as "bleeder"? Because that's the effect it has on my eyes.

    I am reminded of a programmer who was assigned a task which included "... and put today's date in here, ..." or whatever.

    So he carefully programmed in something like:

    this_string = "3rd September 1995";

    or whatever day it was that day. And yep, you guessed, when the testers came back to him a week later and said, "The date's being output wrong, it should say the tenth," changed it to:

    this_string = "10th September 1995";

    recompiled it and re-released it to test.

  • LCrawford (unregistered)

    The sad part is that some day, someone will be searching for date routines and find the whole source code for Initrode.Utilities and start using it in their app.

  • Code Refactorer (unregistered)

    The spelling of "getLastDayofTheInputtedDatesYear" (correct: capital O and remove "ted". refactored: getLastDayOf(date.Year)) reminds me of a library I had to use that got the grade A in university. It contained over 20 methods with the word "piece" spelled as "peice". I had to use them so often that I started spelling it wrong, too, and got confused when i saw it spelled right later on in my life. But the best was the method "getPopAlter". No, it does not get an alternate pop-up. It also does not change the stack by removing an item. It gets the age of a population. Do you not know that "Alter" is the german word for age?

  • Dave (unregistered) in reply to Little Bobby Tables

    'the testers came back to him a week later and said, "The date's being output wrong, it should say the tenth,"'

    Surely the testers said 'it should say today's date' and he changed it to 10th Sept?

  • Dude (unregistered)

    This is one reason I don't think I could handle consulting or contractor-type work. I'm sure this type of thing is a minority of potential clients out there, but my OCD would compel me to refactor the entire class to be a wrapper around the built-in methods or replace all calls to the class to built-in methods (depending on how widely it's used), and stand my ground when confronted by the local expert beginner. I'm also sure in such a situation I wouldn't last long.

  • DQ (unregistered)

    Will there also be a floatManager? I need one for my next project and this could save me lots of time.

  • Brian (unregistered)
    Fun fact: the Day property returns the day of the month. So this method might “subStract”, but if these two dates fall in different months, we’re going to get unexpected results.

    Funny, I ran into a very similar problem just last month. I was dealing with some scheduler code that would periodically schedule a recurring task, but it would sometimes go crazy and spam the scheduler with tasks just before midnight. Turns out that they were using a homebrew Time class (not a DateTime, but just Time) and weren't accounting for the rollover when, say, 23 + 2 = 1.

  • WTFguy (unregistered)

    Like I said for their StringManager ...

    This looks like somebody's pet library from the days of TurboPascal, repeatedly ported (but never refactored) to the then-current API / language du jour.

    Back then you DID have to roll your own. So as a whole it wasn't a WTF when new; it was DRY as DRY was practiced back when the "structured programming" paradigm was morphing into the early days of OO.

    What's a durn shame is that somehow in the intervening 35 years nobody was able to break the cycle of port-and-re-use. Idjits.

  • (nodebb)

    If only the guys who rewrite "Date" would go on one instead of writing code.....

  • ichbinkeinroboter (unregistered)

    I tend to think of Entity Framework as the real WTF... (database knowledge, stored procs and some battle-tested mini ORM like Dapper is usually all you need)

  • Foo AKA Fooo (unregistered) in reply to Code Refactorer

    "Alter" is also a colloquial term meaning "dude" (lit.: "old guy"), so I'd read the method name as "get me a pop, dude".

    ObXKCD: https://xkcd.com/2108/

  • (nodebb) in reply to Bananafish

    "... go on a date..." Insert standard /. reply about Mom's basement and #nevergonnahappen

  • Foo AKA Fooo (unregistered)

    currentDateIsFirstBusinessDateOfTheMonth is not good code, but (unlike most of the other functions here) does seem to have a purpose and is salvageable:

    • Make the date a parameter. Allows for real unit testing without the danger of leaving a hard-coded test case in the code. If you need to call it with the current date very often, write a trivial wrapper for that.

    • Speaking of which: Do some real testing. 2010-05-06 is not a particularly interesting test case. 2010-05-03 would be more interesting as it the first business day of the month, but not the first day of the month. But obviously, test on more than one case. :)

    • Factor out isBusinessDate. It's needed twice in this function already (and likely elsewhere, too), so it's definitely worthwhile.

    • Get rid of the middle check. This should work as a special case of the later check (of course, test that). If you're afraid of empty loops, get a therapy.

    Sure, doing all that wouldn't leave much of the original code, counting by lines. But the basic approach is correct, and Remy's question "why does it need to cycle through other days" has an easy answer: Because it needs to know if any of those other days are business days.

  • Anon (unregistered) in reply to LCrawford

    That's what StackOverflow is for

  • I can be a robot if you want me to be (unregistered) in reply to Little Bobby Tables

    I've had situations like that where the spec was ambiguous, and no matter how many times you ask for clarification you don't get a straight answer or worse you're told everything is in the documentation.

    Sure, using "today's date" rarely makes sense, but depending on the circumstances valid dates would be when the software was installed, first run, last run, the PC was booted, the current work day, the current day, the next work date, and so on.

    So you work with what you're given, and if the client is someone who doesn't know the difference between IE and EG they get what they say they wanted.

  • Karl Bielefeldt (github)

    I would say they should write some unit tests, but knowing these guys, the tests would take a month to run so you they could cross a new month boundary.

  • I can be a robot if you want me to be (unregistered) in reply to WTFguy

    "What's a durn shame is that somehow in the intervening 35 years nobody was able to break the cycle of port-and-re-use. Idjits."

    I'd like to have a job where I could go through old code and rewrite it. Do these actually exist?

  • sizer99 (google) in reply to I can be a robot if you want me to be

    I get to do it in periods of downtime. I just keep a list, and if I finish something a couple days early I spend that time on cleaning up old code. It is quite satisfying to replace huge swathes of unreliable cruft and replace them with a call to a single built in c# method that actually works.

  • (nodebb)

    For the next episode in this epic (fail, obviously), I expect a peek at the unit tests that test these methods against the built-in routines. I already feel goosebumpily exhilirated...

    What? What do you mean? Not there? Noooooooooooooooooo...

  • Brian (unregistered)

    I could go for a nice dateTime Parm sandwich.

  • AddDays(0) (unregistered)

    It took some time before I realized that the first-calendar-date-check would actually work, because "1 - _currentDate.Day" evaluates to "0" when _currentDate.Day is 1.

    In other words, this code:

    DateTime _firstDayOfTheMonth =
                    _currentDate.AddDays(1 - _currentDate.Day);
    if (_firstDayOfTheMonth == _currentDate)
                    return true;
    

    is equivalent to:

    if (_currentDate.Day == 1)
                    return true;
    
  • Reginald P. Smithington (unregistered) in reply to Code Refactorer

    "reminds me of a library I had to use that got the grade A in university"

    English, please.

  • XenuIzReel (unregistered)

    Does anyone actually bother reading the longer snippets?

    Huh? It's to protect my brain from corruption, of course!

  • (nodebb)

    If these are their managers, imagine what their subordinates (associates) are like.

  • Officer Johnny Holzkopf (unregistered) in reply to Code Refactorer

    Alter Popalter! Of course it is utterly important to also use a aCorRectWayOf.caMelCaseCaPiTaLiZaTion(eVeRyWhere) so it appeals to the reader's eye, because now it looks really professional.

  • R (unregistered)

    I'm pretty sure that those people work for us...

    This is my boss' idea of Clear and Robust code.

  • (nodebb)

    The liberal use of hashes in the code make me think there was liberal use of another type of hash during the writing of the code as well. And I am not talking about a fried potato preparation for breakfast.

  • Nick (unregistered)

    I was at a tech conference recently where a well respected speaker made the comment “Of course, you should wrap all calls to third-party libraries”. This was stated as a matter-of-fact, everyone-knows-this kind of thing. It goes along with the principle of “don’t mock what you don’t own” (referring to the test-double kind of Mock, not the activity of us all here reading The Daily WTF).

    Unfortunately, it seems that the definition of “third-party” is a bit vague. Perhaps no-one told this developer that he could ignore that rule for the system libraries?

  • IPGuru (unregistered)

    This type of problem will still be ongoing in the 24th century as even the feeration of planets apear to have major inconsistencies with their starate system https://en.wikipedia.org/wiki/Stardate :-)

  • Greg (unregistered) in reply to Nick

    When you're doing cross platform development you should treat at least some system libraries as 3rd party libraries.

  • Foo AKA Fooo (unregistered) in reply to IPGuru

    Oh yeah, been there. The article page is nothing. Read the Talk page for some real insight into the weirdness (though most of it is theories by fans refusing to accept that it was all made up on the spot without any real systematic behind it).

  • markm (unregistered) in reply to Bananafish

    "If only the guys who rewrite "Date" would go on one instead of writing code." Oh no, then they might reproduce!

  • Jörgen (unregistered)

    Perfect, I was looking for some date handling code to copy to my projects.

Leave a comment on “Driven to Substraction”

Log In or post as a guest

Replying to comment #508815:

« Return to Article