It happened so that I didn’t use Java date- and time-related classes for a long time. I didn’t like them, and I was lucky enough that I didn’t need them, too. Well, sooner or later that should have happened – today I needed to use some date arithmetic. I opened the Javadoc, and spent next half-an-hour trying to understand, how these classes should be used.
I succeeded, and the result was not as ugly as I expected. The question is, why these classes are so counterintuitive and overcomplicated? I had to use 3 different classes to do a relatively simple thing: Date class to store date in milliseconds; Calendar class to perform arithmetic; and SimpleDateFormatter class to print the date and to parse string input.
There are many classes, they are complex – but still some of the most mundane tasks are not that easy to do. How difficult is for us to answer a question: “What date is the next Saturday?” Easy, right (if we have calendar at hand, of course)? Then try doing it using Java classes. Yes, it is possible – and not that difficult – but, still, it is much more complex process than it should be.
The lesson here is simple: create façade for complex classes so that simple common tasks can be easily done – and for more challenging things (what if I need to print a Hebrew calendar in Klingon?) there are always more powerful tools.