• suzilou (cs)

    I pity the fool who disses the cache.

  • Shriike (unregistered)

    Truly Mr. T can do it all.....I never knew, why don't people attribute more to him?

  • tuntis (unregistered)

    "whenever the fist new user session started."

    Intentional typo?

  • Confused... (unregistered)
    Oh well, just 244 days until the next reboot...

    Okay, I'm too stupid. One year != 245 days... So what joke/reference am I missing?

  • S (unregistered) in reply to Confused...

    Days from now until Jan, 1 2009 maybe?

  • RayMarron (cs) in reply to Confused...
    Confused...:
    Oh well, just 244 days until the next reboot...

    Okay, I'm too stupid. One year != 245 days... So what joke/reference am I missing?

    You said it, not me! :)

    As of today, 2008-05-01, it is 244 days until 2008-12-31.

  • Grovesy (cs) in reply to tuntis

    should be a simple fix?

    public class CommonVars { private final static CommonVars instance = new CommonVars(); public static CommonVars getInstance() { return instance; } private CommonVars() { currentYear = Calendar.getInstance().get(Calendar.YEAR); }

    ...
    public int getCurrentYear() {
        return currentYear;
    }
    ...
    

    }

    to.. I know this is Java, but I'm going to go a bit c# .net here

    public class CommonVars { private final static CommonVars instance = new CommonVars();

    public static CommonVars getInstance() 
    {
        return instance;
    }
    private CommonVars() 
    {
    }
    
    public int getCurrentYear() 
    {
        return DateTime.Now().Year;
    }
    

    }

    Saddly though, having had much experience with similar applications with over zelous caching, I know the fix at first seems simple, yet minor alterations like that have the same effect as removing the corner stone of a delapidated house

  • Outlaw Programmer (cs)

    This is a terrible idea but maybe the poor guy figured the system would be rebooted every night? He's not wrong in thinking that the Java Date/Time API is a horrible nightmare, so I give him points for trying. I often wish it had things like getCurrentYear() and getMidnight() built in, but I guess it's not meant to be.

    Around these parts we typically roll our own Date/Time classes that do some mojo on the value returned by System.currentTimeMillis() without having to go through DateFormats and Calendars. fingers crossed for Java7

  • Someone You Know (cs)
    Jake Vinson:
    According to Wikipedia, caching is a method of storing a collection of data for which the time it takes to compute said data is longer than the time it takes to retrieve from the cache.

    That is a very weirdly-constructed sentence.

  • Codes 4 $ (unregistered)

    Wow! Caching is a really easy problem to fix if you can throw that whole coherency thing out the window! I think I'm gonna start adding some caches to my project, now!

  • suzilou (cs) in reply to Someone You Know
    Someone You Know:
    Jake Vinson:
    According to Wikipedia, caching is a method of storing a collection of data for which the time it takes to compute said data is longer than the time it takes to retrieve from the cache.

    That is a very weirdly-constructed sentence.

    I pity the fool who disses Jake Vinson.

    Mr T

  • Grovesy (cs) in reply to Someone You Know
    Someone You Know:
    Jake Vinson:
    According to Wikipedia, caching is a method of storing a collection of data for which the time it takes to compute said data is longer than the time it takes to retrieve from the cache.

    That is a very weirdly-constructed sentence.

    For some reason, I think while saying that sentance, one should be holding a bottle of rhum, doing a Jack Sparrow impression...

  • Farmie (unregistered)

    The Real WTF is that the class doesn't appear to declare the "currentYear" member.

    also,

    public class CurrentYearHolder { private CurrentYearHolder() {} public static final int currentYear = Calendar.getInstance().get(Calendar.YEAR); }

    System.out.println("current year: " + CurrentYearHolder.currentYear);

    ....on second thought maybe its better not to encourage them

  • Volmarias (cs) in reply to suzilou

    Am I the only one that thought that Alex was serious about Mr. T, in as far as the "Mr. T Ate My Balls" meme is concerned (web pages locally cached, etc)

  • Goplat (cs)

    The real WTF is that the "right" way to get the current year involves an object creation - and since this is Java, there are probably 100 other temporary objects created in the process.

  • anonymous (unregistered) in reply to Grovesy
    Grovesy:
    Someone You Know:
    Jake Vinson:
    According to Wikipedia, caching is a method of storing a collection of data for which the time it takes to compute said data is longer than the time it takes to retrieve from the cache.

    That is a very weirdly-constructed sentence.

    For some reason, I think while saying that sentance, one should be holding a bottle of rhum, doing a Jack Sparrow impression...

    Here in the states, we use the word 'Rum'. Google tells me that 'Rhum' is common in french areas of the world, however.

  • vt_mruhlin (cs)

    This seems more like CodeSOD material than featured.

  • An oppressed mass (unregistered)

    Reasonable solution on a highly loaded system. How often does the year change - rarely and fairly predictably. How often do you need to calculate the year - on every transaction, many times a second.

    Especially since Java probably checks the locale and I8N settings for each data request. Just in case the defn of 'first day of the week' has changed since the last packet arrived.

  • Grovesy (cs) in reply to anonymous
    anonymous:
    Grovesy:
    Someone You Know:
    Jake Vinson:
    According to Wikipedia, caching is a method of storing a collection of data for which the time it takes to compute said data is longer than the time it takes to retrieve from the cache.

    That is a very weirdly-constructed sentence.

    For some reason, I think while saying that sentance, one should be holding a bottle of rhum, doing a Jack Sparrow impression...

    Here in the states, we use the word 'Rum'. Google tells me that 'Rhum' is common in french areas of the world, however.

    Here on the internet, we are not all from the states. It is a common spelling in the UK

  • biziclop (unregistered) in reply to Goplat
    Goplat:
    The real WTF is that the "right" way to get the current year involves an object creation - and since this is Java, there are probably 100 other temporary objects created in the process.

    Which all get promptly and quickly removed from the heap about 10 seconds later by the "small GC".

    I can't see what's all the fuss about object creation. If you have an object creation phobia, don't use Java. It's like being an airliner pilot and complaining about how high these planes fly.

    You're free to use C and then you don't have to deal with all this pesky and mucky object stuff.

  • Digitalbath (cs) in reply to An oppressed mass
    An oppressed mass:
    Reasonable solution on a highly loaded system. How often does the year change - rarely and fairly predictably. How often do you need to calculate the year - on every transaction, many times a second.

    Especially since Java probably checks the locale and I8N settings for each data request. Just in case the defn of 'first day of the week' has changed since the last packet arrived.

    Then put the value in a config file. A "solution" that requires a reboot is not a good one.

  • Farmie (unregistered) in reply to Grovesy
    Grovesy:
    anonymous:
    Grovesy:
    Someone You Know:
    Jake Vinson:
    According to Wikipedia, caching is a method of storing a collection of data for which the time it takes to compute said data is longer than the time it takes to retrieve from the cache.

    That is a very weirdly-constructed sentence.

    For some reason, I think while saying that sentance, one should be holding a bottle of rhum, doing a Jack Sparrow impression...

    Here in the states, we use the word 'Rum'. Google tells me that 'Rhum' is common in french areas of the world, however.

    Here on the internet, we are not all from the states. It is a common spelling in the UK

    Down on the farm, we spell it M O R G A N

  • Jake Vinson (cs) in reply to suzilou
    suzilou:
    Someone You Know:
    Jake Vinson:
    According to Wikipedia, caching is a method of storing a collection of data for which the time it takes to compute said data is longer than the time it takes to retrieve from the cache.

    That is a very weirdly-constructed sentence.

    I pity the fool who disses Jake Vinson.

    Mr T

    I couldn't agree more.

  • Patrick (unregistered) in reply to Outlaw Programmer
    Outlaw Programmer:
    This is a terrible idea but maybe the poor guy figured the system would be rebooted every night? He's not wrong in thinking that the Java Date/Time API is a horrible nightmare, so I give him points for trying. I often wish it had things like getCurrentYear() and getMidnight() built in, but I guess it's not meant to be.

    Around these parts we typically roll our own Date/Time classes that do some mojo on the value returned by System.currentTimeMillis() without having to go through DateFormats and Calendars. fingers crossed for Java7

    This is something that seems like a bit of a premature optimization (OH NOES TEH JAVAS DATE API IS TEH SUQ!). They say that you've gotta code first, profile, then optimize later in that order. A friend of mine, who isn't a programmer, had an interesting take on that sort of thing. He pointed out that focusing on a task that may be secondary to the task at hand (e.g. creating a caching class for seemingly everything in an application) is just a form of procrastination.

  • biziclop (unregistered) in reply to An oppressed mass
    An oppressed mass:
    Reasonable solution on a highly loaded system.

    No, it isn't. Outrageous stupidity is the proper expression.

    No caching is reasonable unless it removes a proven bottleneck. (Or in a generalized form: if it ain't broke, don't fix it.)

    And I've never ever seen a system in which the CPU time spent on getting the current year properly caused any kind of performance problems.

  • Former Jr. Programmer (unregistered)

    Caching in Java? That's what we (ab)use Hibernate for.

    lulz.

  • Farmie (unregistered) in reply to Patrick
    Patrick:
    Outlaw Programmer:
    This is a terrible idea but maybe the poor guy figured the system would be rebooted every night? He's not wrong in thinking that the Java Date/Time API is a horrible nightmare, so I give him points for trying. I often wish it had things like getCurrentYear() and getMidnight() built in, but I guess it's not meant to be.

    Around these parts we typically roll our own Date/Time classes that do some mojo on the value returned by System.currentTimeMillis() without having to go through DateFormats and Calendars. fingers crossed for Java7

    This is something that seems like a bit of a premature optimization (OH NOES TEH JAVAS DATE API IS TEH SUQ!). They say that you've gotta code first, profile, then optimize later in that order. A friend of mine, who isn't a programmer, had an interesting take on that sort of thing. He pointed out that focusing on a task that may be secondary to the task at hand (e.g. creating a caching class for seemingly everything in an application) is just a form of procrastination.

    I don't disagree with your point, but just to make sure we're clear on this, TEH JAVAS DATE API IS TEH SUQ.

  • Anon (unregistered)

    And to think, I thought I had it bad when I worked on a J2EE webapp that on startup cached the entire database into a set of arrays because "database are slow".

    I never was able to communicate just how brain dead it was to think that caching the entire database in a Java application would magically be faster at selecting rows than running queries again a natively optimized database running on the same machine.

  • Datacenter Drone #4 (unregistered)
    Comment held for moderation.
  • Anon (unregistered) in reply to Farmie
    Farmie:
    I don't disagree with your point, but just to make sure we're clear on this, TEH JAVAS DATE API IS TEH SUQ.
    No it isn't. It's just somewhat overly specific.

    Date is just a simple, plain old timestamp in milliseconds since 1970. Sun is even kind enough that Date ignores leapseconds, which they explain in several paragraphs complete with references in the Date documentation. A date is just an offset from a known reference time. Simple. It's not a calendar, it's a date.

    If you want to be able to translate the Date into meaningful terms, you need a Calendar, which translates the timestamp into things a person might understand. After all, there is more than just the Gregorian Calendar out there. You might be dealing with the Jewish Calendar or the Chinese Calendar or some other calendar.

    Just because Java doesn't actually offer any implementation except the Julian and Gregorian Calendars, doesn't mean that it doesn't make some kind of sense, in that liberal "think of the minorities!" sort of way.

    (Yes, you can make a GregorianCalendar act like a Julian calendar. The documentation even explains how.)

    After all, you should never optimize for the most common usecase. Just because almost everyone had need for dates in the Gregorian calendar doesn't mean you should make it easy to get dates in that format. After all, to do so might be considered insulting to minorities that use different calendars.

    (And, yes, this entire thing is sarcastic. Java's date API is moronic. Allowing other calendars makes a sort of sense, but for the love of sanity, don't deprecate and remove easy access to things like the current year!)

  • FredSaw (cs) in reply to Farmie
    Farmie:
    Grovesy:
    anonymous:
    Grovesy:
    For some reason, I think while saying that sentance, one should be holding a bottle of rhum, doing a Jack Sparrow impression...

    Here in the states, we use the word 'Rum'. Google tells me that 'Rhum' is common in french areas of the world, however.

    Here on the internet, we are not all from the states. It is a common spelling in the UK

    Down on the farm, we spell it M O R G A N

    In Trinidad they drink it with coke-ah co-lah.

  • travisowens (cs) in reply to An oppressed mass
    An oppressed mass:
    Reasonable solution on a highly loaded system ... How often do you need to calculate the year - on every transaction, many times a second.

    Oh yes you're so right, calculating the current year is soooo complicated! </sarcasm>

    I would put money down that doing Calendar.YEAR is faster than calling this WTF code!

  • BammBamm (unregistered) in reply to Grovesy

    Pretty sure this wouldn't be caching, you would be retrieving it on every call.

  • BammBamm (unregistered) in reply to Grovesy
    Grovesy:
    should be a simple fix?

    public class CommonVars { private final static CommonVars instance = new CommonVars(); public static CommonVars getInstance() { return instance; } private CommonVars() { currentYear = Calendar.getInstance().get(Calendar.YEAR); }

    ...
    public int getCurrentYear() {
        return currentYear;
    }
    ...
    

    }

    to.. I know this is Java, but I'm going to go a bit c# .net here

    public class CommonVars { private final static CommonVars instance = new CommonVars();

    public static CommonVars getInstance() 
    {
        return instance;
    }
    private CommonVars() 
    {
    }
    
    public int getCurrentYear() 
    {
        return DateTime.Now().Year;
    }
    

    }

    Saddly though, having had much experience with similar applications with over zelous caching, I know the fix at first seems simple, yet minor alterations like that have the same effect as removing the corner stone of a delapidated house

    Pretty sure this wouldn't be caching your calling DateTime.Now() every time.

  • Josh (unregistered) in reply to Farmie

    Amen!

  • Outlaw Programmer (cs) in reply to Patrick
    Patrick:
    This is something that seems like a bit of a premature optimization (OH NOES TEH JAVAS DATE API IS TEH SUQ!). They say that you've gotta code first, profile, then optimize later in that order. A friend of mine, who isn't a programmer, had an interesting take on that sort of thing. He pointed out that focusing on a task that may be secondary to the task at hand (e.g. creating a caching class for seemingly everything in an application) is just a form of procrastination.

    For the record, the systems that I work on are designed to be super high performance because they need to handle something like 2000+ requests a second. It's possible (maybe even likely) that this system has similar requirements, given that this guy was so cache crazy.

    I'm not try to defend this guy, but as far as WTFs are concerned, not only is this a minor bug, it's easily fixable without even changing their API. The easiest solution was already suggested above (don't bother caching).

    No, the real WTF is that the team's solution was to reboot the server every year instead of just applying the simplest refactoring ever needed by a Daily WTF.

  • duplicity (unregistered)
    Comment held for moderation.
  • real_aardvark (cs) in reply to suzilou
    suzilou:
    Someone You Know:
    Jake Vinson:
    According to Wikipedia, caching is a method of storing a collection of data for which the time it takes to compute said data is longer than the time it takes to retrieve from the cache.

    That is a very weirdly-constructed sentence.

    I pity the fool who disses Jake Vinson.

    Mr T

    On the other hand, Chuck Norris doesn't construct sentences. He just stares at them until the words reassemble themselves into the right order.

    Actually, that would be a particularly useful plug-in for an IDE.

    On other matters, this is simply the most astonishingly beautiful use of the Singleton Pattern that I've ever seen. Saves a single call into the kernel (400 cycles or so), guarantees that the returned value will eventually be wrong, and is essentially impervious to testing.

    Brillant!

  • AccessGuru (cs) in reply to Grovesy
    Grovesy:
    Here on the internet, we are not all from the states. It is a common spelling in the UK
    EVERYONE ON THE INTERNET IS FROM USA BITCH
  • Spectre (cs) in reply to BammBamm
    BammBamm:
    Grovesy:
    public int getCurrentYear() { return DateTime.Now().Year; }
    Pretty sure this wouldn't be caching your calling DateTime.Now() every time.

    Yeah.

    public int getCurrentYear() 
    { 
      if (currentYear != DateTime.Now().Year)
        currentYear = DateTime.Now().Year;
      return currentYear;
    } 
    

    Vastly better.

  • Farmie (unregistered) in reply to duplicity
    Comment held for moderation.
  • Andrew (unregistered) in reply to biziclop
    biziclop:
    ... No caching is reasonable unless it removes a proven bottleneck. ...

    I first read that sentence as if it had a comma after "No".

  • cconroy (cs) in reply to duplicity
    duplicity:
    Yes the Java date API is a WTF. Use Joda Time instead.

    http://joda-time.sourceforge.net/

    When 2.84012334 x 10^13 milliseconds old you reach, look as good you will not. Hmm!

  • duh (unregistered) in reply to Spectre
    Spectre:

    Yeah.

    public int getCurrentYear() 
    { 
      if (currentYear != DateTime.Now().Year)
        currentYear = DateTime.Now().Year;
      return currentYear;
    } 
    

    Vastly better.

    You're kidding right?

  • BammBamm (unregistered) in reply to Spectre
    Spectre:
    BammBamm:
    Grovesy:
    public int getCurrentYear() { return DateTime.Now().Year; }
    Pretty sure this wouldn't be caching your calling DateTime.Now() every time.

    Yeah.

    public int getCurrentYear() 
    { 
      if (currentYear != DateTime.Now().Year)
        currentYear = DateTime.Now().Year;
      return currentYear;
    } 
    

    Vastly better.

    No you're still calling it every time, you have to do it in the constructor which leaves you exactly where WTF started.

  • Mike Dimmick (unregistered)
    Comment held for moderation.
  • Farmie (unregistered) in reply to BammBamm
    BammBamm:
    Spectre:
    BammBamm:
    Grovesy:
    public int getCurrentYear() { return DateTime.Now().Year; }
    Pretty sure this wouldn't be caching your calling DateTime.Now() every time.

    Yeah.

    public int getCurrentYear() 
    { 
      if (currentYear != DateTime.Now().Year)
        currentYear = DateTime.Now().Year;
      return currentYear;
    } 
    

    Vastly better.

    No you're still calling it every time, you have to do it in the constructor which leaves you exactly where WTF started.

    take every post on these comments with a grain or spoon of salt. i'm 99% sure he was joking... i laughed at least.

    unless you're joking about not knowing that he was joking... then i'm the fool. unless of course i'm just joking about not knowing that you are joking about not knowing that he was joking. which i'm not, so let me know.

  • Stewie (unregistered) in reply to Confused...
    Confused...:
    Oh well, just 244 days until the next reboot...

    Okay, I'm too stupid. One year != 245 days... So what joke/reference am I missing?

    :|

  • Spectre (cs) in reply to BammBamm
    BammBamm:
    No you're still calling it every time, you have to do it in the constructor which leaves you exactly where WTF started.

    See this.

    8=]

  • Alfred (unregistered) in reply to duh
    duh:
    Spectre:

    Yeah.

    public int getCurrentYear() 
    { 
      if (currentYear != DateTime.Now().Year)
        currentYear = DateTime.Now().Year;
      return currentYear;
    } 
    

    Vastly better.

    You're kidding right?

    I would assume so.

    I half expected somebody to write a snippet like this:

    public int getCurrentYear() 
    { 
      if (currentYear != DateTime.Now().Year)
        return DateTime.Now().Year;
      else
        return currentYear;
    } 
    

    That would get rid of that memory-write-intensive assignment operator.

    I'm sure it's possible to make it even more perverse (and yet still plausible) but I'll be damned as to how.

Leave a comment on “The Annual Reboot”

Log In or post as a guest

Replying to comment #:

« Return to Article