⇥ Dates, Times and Derick

As you may know, php|a just published Derick Rethans’ new book, php|architect’s Guide to Date and Time Programming. If you allow me a small amount of self-promotion, this is a great book—and not just because my company happens to be the publisher.

Date and time programming is one of those topics that almost everybody tends to think they’re doing well and almost nobody does correctly. Thus, the most challenging aspect of selling this book is the fact that almost all those who could benefit from it—and that’s just about everybody—will tend to think that they don’t need it.

As an aside on why this book is so important, let me tell you this little story. Like most, we paid relatively little attention to our date programming—for the most part, it just worked, but only because all our servers are set to the same timezone, so that date and time values are all automatically synchronized.

When we installed PHP 5.2, however, our machines kept crashing. I have had occasion in the past to mention that out software is written with Nixon-level paranoia in mind, so all warnings and strict notices turned on and anything amiss is cause enough for our software to throw a 500 error and let us deal with the consequences by hand.

It turns out that, starting with 5.2, PHP was much more anal about the way it handles dates, so that it now spits out warnings like these:

Strict Standards: strtotime(): It is not safe to rely on the system’s timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘America/New_York’ for ‘EDT/-4.0/DST’ instead.

As you can see, Derick and the rest of the PHP team have gone to great lengths to make sure that date and time manipulation are as accurate as they can be—and, as anyone who has ever tried writing date-management code knows, that’s not a simple task.

That’s why I think Derick’s book should be on every PHP developer’s reading list—because you, too, could end up with a line like this in your code:

// Here, Derick--happy?
date_default_timezone_set('America/Toronto');

⇥ Use your own brain, please

There has been a surprising—and, at times, outright hilarious—debate under the form of a number of reactions to my last post on self-commenting code (itself a follow-up to a blog post by Brandon Savage). For my part, I will limit myself to wonder, with a slightly curled lip, how, with so many people openly disdaining the mere idea of reducing the number of comments in code, there can be so much horribly commented code lying around, and leave things at that…

…well, not quite—I will say one more thing while I’m at it: please, please stop blindly quoting Martin Fowler and his books. He is not Jesus Christ, and his books are not the Bible. Like every other source of information, Mr. Fowler’s books should be assimilated into your own personal base of knowledge and used to formulate your own ideas, not parroted as if they were the word of the Almighty. I bet he would be the first to say so himself.

Let me give you a quick reason why quoting out of context is dangerous:

Never forget that the most sacred of all rights in this world is man’s right to the earth which he wishes to cultivate for himself and that the holiest of all sacrifices is that of the blood poured out for it.

What a heartfelt, patriotic and inspiring quote, eh? Too bad you may have a bit of trouble liking it once you find out who the author is.