- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
YES! I did it only took me 27 days
Admin
first.
Admin
Hmmmm.......guess the original programmer thought it was more efficient to type Ys and Ns than to do say.........LOGIC...........
Admin
Obviously done for extensibility. If you tie this kind of thing to tenuous structures like DateTime data types or Calendar functions, you'll be sorry when the calendar changes. Just think about all those programmers working when the Gregorian calendar came online. They were spending weeks recoding. Our friend here can just set a few bits and he's all set. You youngsterd think y2k was bad, you just don't remember y1582. Ugly, man. Ugly. Better to roll your own calendar functions than go through THAT again.
Admin
This still doesn't match the amazing power that Microsoft has to reschedule Thanksgiving to fall on a Wednesday:
http://72.14.203.104/search?q=cache:RzFeU2G46_8J:blogs.msdn.com/jensenh/archive/2005/11/23/496246.aspx+microsoft+bug+thanksgiving+tuesday&hl=en&gl=us&ct=clnk&cd=2
Admin
blnaryHoliday?
booleanary?
Admin
I also like that in a table tblHoliday, and a field named blnaryHoliday, that the days marked with a "Y" are NOT holidays. Just another little bundle of joy.
Admin
This conversation probably happened a couple of years later, after the original developer moved to a new company:
Original Developer: "Yeah, so I didn't want to have to go through each calendar year and figure out weekends, weekdays, and holidays manually. So I populated this table auto-magically by writing a script to iterate over years from 1975, and figure for each day whether it was a weekend or holiday. Saved me loads of time."
Rookie: "Why didn't you just... you know... like, adapt the code from that script, instead of... well, instead of storing it in the database like that?"
Original Developer: "Ah! You are obviously new to enterprise development!"
Admin
Man, I want to work for that company. You only have to work for 2 days and then you get 5 holidays!!
Admin
Because if you used logic instead of Ys and Ns you'd drastically increase the size of your database:
TRUETRUEFALSEFALSEFALSEFALSEFALSEFALSETRUETRUEFALSE
FALSEFALSEFALSEFALSETRUETRUE ...
Admin
I don't think "logic" is the way to go (not sure how you'd logically work out what the holidays would be, anyway -- plus, what happens when that "logic" changes?). However, you could just put the dates in the table as dates, maybe with a nice little description for the holiday in a separate column. Plus other column flags like which country it's a holiday for, or whether it's a trading or settlement holiday for finance, or whatever.
Of course, logic works for weekends. Is it just me who only sees weekends defined on this chart?
Admin
That threw me off, why are the non-holidays marked "Y"?!
Admin
365 bytes, what a waste! Packing it to one bit per day would reduce it to 46 bytes!
And you still have 1 bit available to store other stuff, and 2 bits in non-leap years!
Admin
Should probably be bInaryWORKDAY (Y/N)
Can't believe I am suggesting naming improvements for this nightmare. I guess I need something to do....
Admin
The really funny thing is that it should be called "tblWeekends".
Admin
And it works great overseas. All you have to do is create a new table and determine other countries holidays.
Admin
You see, when you get to work with code like that....each work day is just like a holiday. I'm so super jealous.
Admin
laughable... this fellow clearly has no idea about enterprise systems.
he should have had another table called "days", where each row contains the current date. a daily cron script can then kick off each day to add a row to the days table, which of course has a trigger that calls a stored procedure which automatically appends a "Y" or "N" to the proper row in blnaryHoliday.
Admin
A more "enterprise" way to do this would be with two tables:
one to enumerate holidays...
and one to enumerate non-holidays!
Admin
I agree -- there are NO holidays listed in that table, only the weekdays are marked Y. Apparently there are no holidays, or else every weekday is a holiday.
Admin
Ah yes, then you have truly mastered Zen Programming.
Admin
The ENTERPRISE way to approach this problem is to use a simple CRON routine that;
if it matches this must be a weekend or holiday!
VOILA!
Admin
Surely, this should have been ...
<1975>
<January>
<1>Holiday</1>
<2>Work</2>
<3>Work</3>
...
</January>
...
</1975>
...
or even
\1975
\January
\1
\Status.txt
\2
\Status.txt
...
Where Status.txt contains whether or not the day is a holiday.
(... hoping the forum does not screw the layout ...)
Admin
rofl that is fuckin funny shit.
Admin
This is actually a GOOD approach... caching calculations.
It should have been coupled with some kind of mechanism for generating rows for future years, though.
Admin
Caching calculations MIGHT be a good approach IF it turns out the calcuation is a bottleneck. You can't figgure that out without profiling it. Even then we're assuming that it takes less time to go out to the database and parse that mess instead of doing the calculation in the first place.
Either way, you can't know without profiling, and if it turns out that hitting the database is more efficient, well there's surely a better way of doing it than this bit of WTFery.
Admin
You're close, but not quite there.
It SHOULD be called "tblWeekdays"
Admin
Ok, I see "T" and "F", but what about "File not found?"
In all seriousness, I would love to see the rest of this "database." or maybe not.
Great post Alex. WTF ++ !
Admin
Holidays are *data* and should be stored in tables.
However, as mentioned, it appears that he is simply declaring every weekend a "Holiday" so in that case logic would work, I suppose.
The guy who wrote this must be a fun guy to hang out with ... except for Monday-Friday or on any actual holiday that falls on a weekday, that is.
Admin
If you want a real solution you should use the following table instead:
CREATE TABLE
tblHoliday
(
intYear INT,
bln0101 BIT,
bln0102 BIT,
bln0103 BIT,
...
bln1231 BIT
)
Admin
[:S]
Okay--just so I don't end up the guy who has to make sense out of the WTFs for holidays--
The right way to track holidays is to manually enter them into a table. Most holidays can be mathematically calculated (3rd Monday of January, for example, for Martin Luther King's birthday), but some are rather complex in their formulas (every try to calculate Easter?) Some years a business will observe one holiday, while on others it will observe a different holiday. Safest to always just put the list of observed holidays in a database.
And, for goodness sakes, just have a table with nothing but the actual date of the holiday:
Holiday Table (or whatever you want to call it)
Date (a "Date" datatype, please) | Description (optional column)
12/25/2006 | Christmas
Admin
Because that will be your response. "YYYYYYYYYYYYes! I get to go to work!"
That's how awesome working for this company is.
Admin
1. For blind people being driven to the ATM.
2. Notice there is Braille on all ATMs, including those walk-up ones in the mall and at banks. Does it make sense to manufacture some ATMs with Braille and some without? No, of course not - make one mold, keep filling it.
3. Americans with Disabilities act is probably another reason.
There, three reasons for you. Change your signature.
sincerely,
Richard Nixon
Admin
Man, I bet the leap year code for this mess is hell awesome.
Admin
When did Christmas stop being a holiday?
Admin
Admin
boolean array maybe
Admin
In the financial programming world, we all have 'holiday' tables. That part makes sense. Using a logic based solution would not be practical. Remember when Ronald Reagan died, the markets had a holiday added. Inserting one row into a 'holiday' table was easy, maintaining and releasing code is unfeasable.
Not using a datetime field for the holiday dates is what makes no sense.Using a database in such a way, that you can't possibly 'JOIN' to the required data is the WTF.
Admin
You mean that not everyone celebrates the 4th of July? Weird. [:D]
Admin
During the War On Christmas, obviously. I guess Christmas lost.
Admin
When the Christmas-hating liberal media got hold of the calendar industry.
Admin
scrooge@gold> mysql -uscrooge -pm0n3y
mysql> USE dbHoliday;
mysql> UPDATE tblHoliday SET binaryHoliday = INSERT(binaryHoliday, LENGTH(binaryHoliday)-6, 1, 'Y');
Admin
What do you mean you can't use logic to calculate the holidays? There are rules for figuring out holidays and when they fall each year, they don't generally change.
And yes I think you're right, I also do not see any holidays defined in this, only weekends.
Admin
In the end, it was decided that 'F' would signify both False and Filenotfound, in the interest of saving precious bytes of memory. A random number would be generated, and then the mod(2) taken, to determine which value the current instance of 'F' implied.
Admin
Sorry every holiday has an exact calculation ... in Excel for instance they can represented like:
Memorial Day - Last Monday in May
=DATEVALUE("5/" & IF(WEEKDAY(DATEVALUE("5/31/" & intYear))>3, 35 -WEEKDAY(DATEVALUE("5/31/" & intYear)),28-WEEKDAY(DATEVALUE("5/1/" & intYear))) & "/" & intYear)
How you want to cache the results depends on your needs.
I sure wouldn't want to work for that company. No holidays!
Admin
I should mention that the technical term for this logic is "WTF Overloading".
Admin
This is actually GREAT! Finally a date system that can take leap-seconds into account on the scale of years :D
Admin
easy:
yes == yes, it is not a holiday
no == no, it is not not a holiday
Admin
Cool! Can you show me the formula for Easter next?
Admin
The real WTF here is that the original programmer didn't have the foresight to insert the days as XML entries into the database.