- 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
Isn't Cache King in a down Economy?
Admin
Admin
You've got to to wonder sometimes how these people end up with a job coding.
I'd love to say our place is better, but based on this - it's much worse.
So I take up this job as sysadmin and sure enough on 1st Jan 2007 complaints start rolling in saying "we can't view our stats for today", sure enough there is no '2007' in the date drop down.
Report it to dev and they produce a release to fix it... problem sorted (or so I thought)
1st Jan 2008 comes, and low and behold the same complaints keep rolling in - I check the bug report I filed and yes it says that the date drop downs are now dynamic. Restart the application and sure enough 2008 appears.
Turns out their idea of 'dynamic' isn't the same as mine. They didn't want to generate the drop down every time the page was rendered because that would be wasting CPU cycles.
...roll on 2009
Admin
Admin
Speaking of attribution, if that statement gets deleted, we can add it back in giving TDWTF as the source now!
I pity da fool.
Admin
The real WTF is that the support staff didn't write a script to automatically reboot the server at the stroke of midnight January 1 of each year. Of course, it would be best if it were a service that polled every 30 seconds or so instead of a cron job.
Admin
Admin
I'd just go with the Monte Carlo approach...
That way we save a precious assignment and ensure we refresh the cache once in a while (if the value changed). I think you all forgot the original idea and lost perspective here: we need to cache so that fetching is faster...
Amateurs.
Admin
I like to cache my whole database on startup, that way I don't have any lookups :)
Admin
The Answer is simple. Because of Chuck Norris!!!
Admin
I pity the fools who continue such jibba-jabba.
Mr T
Admin
Admin
I programmed mostly in Java for over 10 years. 95% of my date-related headaches were caused by morons who wrote their own Date/Time wrapper classes, not by the Java APIs. Just sayin'...
Admin
How long until Clock Girl replaces Irish Girl in our fickle hearts and minds?
Admin
Admin
That, I think, leaves you with 95% of room for headaches caused by the Java API and/or dingbat excursions like J2EE, whatever flavour of RPC is current this month, etc, etc.
Never mind. If you still suffer from date-related problems, I'd suggest choccies and a nice bunch of long-stemmed roses. It won't make your problems go away, but, hey, at least it's not Java.
Admin
Dates are anything BUT simple - you don't even have to go into Jewish or Buddhist calendars: timezones, leap years and daylight savings time introduce enough complexity that rolling your own date/time routines is almost guaranteed to result in bugs.
Admin
Fools. Suckas! You're making Mr T's head explode with that jibba-jabba. And I pity the fool who makes my head explode.
Mr T
Admin
Why? Because an unsuspecting user might not realize that new Date().getYear() gets a Gregorian year, and because Date did not properly handle dates before 1583.
Yes, really. One of the reasons you can't get a year from a Date object is because it would return invalid values on certain dates before 1583.
Admin
Well, it's a bit lame, but we haven't seen one of those for a while. I was going for "Please give me teh bytez," or else "All your byte are belong to us..."
Then I realised that I'm replying to the wrong thread.
Silly me.
Admin
... hmmm.
Excuse me?
If all you've got (which thanks to Unix's brain-dead interpretation of the Multics ideal is all we've got) is "milliseconds since 1970," exactly how do you propose to represent, say, 12:30 PM on January 1st, 1583? Please show us teh Java codez.
Admin
When you're designing something as fundamental as your runtime library's basic "date" object, you've got to think through the use cases. 99+% of the time, people just want to know about seconds/minutes/hours/days/weeks/months/years relative to the current time, on the current computer, using the current locale settings. Java seems to have designed to the <1% fringe cases, and they pay for it in abominations like this one.
There's a reason people keep bringing up DateTime.Now.Year, and it's because you can look at it with 10 minutes of programming experience and know what it's saying. You should not need to add a comment to explain something as simple as retrieving the current year.
Admin
Admin
The reason being, of course, that you can call setTime() on a Calendar instance so that you can use it on some other date values. If all getInstance() does is to return a cached value, your multi-threaded app would start to fail in mysterious ways.
IMHO, getCurrentYear() is likely something that is associated with human-readable values (i.e. display a page or generating a report.) In those cases, the overhead of a single getCurrentYear() is negligible compared with the rest of the task.
Admin
Admin
One of the reasons Sun deprecated all the useful methods from the Date class was because it didn't handle dates before 1583 "properly", which is completely braindead. The number of usecases where anyone cares about dates a century old let along half a fucking millennium old are so few that completely altering the API to accommodate them and not common usecase is a complete WTF.
But Sun, in their wisdom, just had to make sure that Java can properly form dates before 1583. (But you're still not allowed to use Java in nuclear reactors.)
Since you asked, that date would be represented in Java using their GregorianCalendar as:
new GregorianCalendar(1583, Calendar.JANUARY, 1, 12, 30);
Note that despite "Calendar" being an abstract class that doesn't represent any specific culture's calendar, you still have hard-coded month constants. (WTF?!)
'Course, there's no reason why Sun couldn't include that class and STILL allow you to do new Date().getYear(), but whatever.
Admin
"That would be the French. Inventors of mayonaise..."
Admin
Admin
Admin
Admin
Admin
Oh well the wrong year is maybe the only thing that is apparent and noticeable. I wouldn't want to know how consistent their data is after using this for ... well ... a few years...
Admin
Admin
Java typically runs ten times slower, and takes up ten times as much memory as C. But you can write programs a lot faster in Java, and they are more likely to be correct, because you are considerably less likely to get memory leaks.
The day dawns when your Java application, vital to the company's business, just cannot keep up, and so the programmer goes in and starts optimizing, whereupon disaster ensues.
If you are really not much worried about hardware performance, but programmer importance is important, write it in Python. When the system starts to grind to a horrible halt, rewrite in C++
Python will get you better programmer performance than Java, C++ better hardware performance. Why should one ever use Java? Certainly one should never use Java in a situation where one needs to worry about Java creating a hundred temporary objects to perform some entirely trivial operation. If you are worried about Java's propensity to create innumerable objects, it is C++ time.
Admin
Damn it! Someone beat me to it!
I wonder what would happen if you got them into a room together? Is that how the world is going to end?
Admin
The first rule of caching...
Know how and WHEN to invalidate cache...
Stale cache can be worse to an app than no cache...
Admin
Admin
This issue has nothing to do with languages, or calenders/date objects, it is a simple matter of not understanding caching.
I'll let you in on a secret - time always changes. If you store a 'current' time now (as a long, or in years, or in days, or using java, or using assembler... doesn't matter how), it cannot be guarranteed to be accurate the next time it is read.
Now, as Mr T. once told me "Never cache information which changes constantly (fool)".
On the other hand, if you are storing a 'past' time, then that will not change. Then again, it would not need to be recalculated, and having it in any specialised cache rather than just a public/global object/variable/file/etc would make more sense.
Admin
It's a stupid solution. It reminds me of offshore code where you have folks that don't understand java or any programming, just enough to get by.
Admin
Rhum is not a common spelling in the UK.
What nonsense...
Admin
Its a rhum do, thats for sure.
Admin
"That would be the French. Inventors of mayonaise..."
Mayonaise was invented by the Smashing Pumpkins. Mayonnaise, however, was invented by the Spanish in Port Mahon (mahonese). No sign of the French in either of those.
I pity the fool.
Admin
Admin
Agreed, and the only way to know whether the cached year value is stale is to check it against the real year. In other words, the cache has gotta go.
Admin
Okay, so what's with the picture of the blow-up sex doll (in clothes and a wig) pointing at a clock? Wouldn't a calender have made more sense? And, er, a real person?
Admin
In Spanish we call it "ron", and it's pronounced somewhat like "run", but with the strong latin "rrrrrr" sound (which may go well with the whole "Arrrrgh matey" motif).
Admin
(Accompany, maybe)
Admin
Alfred, your code has a potential bug. What if you check currentYear and it is equal to DateTime.Now().Year, but it's a millisecond before midnight. Now, before you can return, the clock ticks. Oops! Wrong date returned.
Better to double check:
That should ensure you don't get bitten by that bug.
Admin
Oh, come on! Everybody knows that there wasn't enough government in place back in 1583 to require an operating license for a mere nuclear plant. Anybody could build and run one. My great-great-great-great-great-great-great-great-great-great (somewhere in there) grandfather had a whole chain of nuclear reactors that he started building in 1582; the first one came on line on January 1, 1583.
Admin
Time to put on my over engineering gloves...