⇥ A new candidate for the Darwin Awards: me.

April 30, 2008
9 comments
 
⇥ Permalink

As far as backups go, until yesterday I liked to think that I had a pretty reasonable setup. As I’ve mentioned more than once before, I have a Mac and, having installed Leopard the day before it came out, I have been using Time Machine ever since.

Given that Apple didn’t “officially” support remote backups when I installed Leopard, and given the fact that my network is entirely wireless (thus making a 100GB backup painfully slow), I simply connected a generously-sized hard drive to my iMac and let Time Machine do its thing.

This approach seemed to work well—it’s saved me a couple of times from losing important data (like, for example, the one time when a mistake in my .Mac configuration caused my entire Keychain to vaporize)—and so it wasn’t until yesterday that I finally discovered the fatal flaw in my plan: you see, the hard drive is physically connected to the computer.

It is necessary for me at this point to step back to a little over a week ago, when my office was being cleaned. I’m not sure exactly how, but it appears that a powerbar managed to lodge itself underneath the side of one of my desk’s legs, thus making it slightly unstable, but not enough so for me to notice. In retrospect, the desk felt a little wobbly (it’s usually very solid), but I guess not wobbly enough for me to worry.

And so, yesterday afternoon, as I stood up from the desk, I bumped against it enough to tip it over front-to-back. As the ninety-degree rotation was taking place—slow enough for me to take notice of every single object tipping over and getting ready to crack itself open on the floor with delightful horror, but not slow enough for me to stop it from happening—I managed to get a hold of the one item on my desk that I couldn’t have cared less about: my $50 cell phone.

Meanwhile, the $3,000 iMac and my ever-so-precious backup hard drive happily slid off the desk and landed next to each other on the wooden floor. I wouldn’t be able to tell you just how they landed on the floor—I was too busy grabbing my freaking cell phone and holding on to it for dear life.

I am, however, able to tell you that both the Mac and the hard drive landed in such a way that the hard disks were physically damaged beyond repair. Even as I realized that my precious cell phone was mercifully safe, and I’d be able to get gouged by my cell provider without interruption, I could hear the dreaded clicking sounds that clearly marked all my data as gone in a puddle of magnetic dust.

The best part of this is that two crystal glasses were right next to the computer and fell to the floor from the same height without so much as a scratch. I had previously managed to break a glass from the same batch with my bare hands (this is why I no longer make or take phone calls with a glass in my hands). If there is a God, he was having a good chuckle yesterday.

And now you know, if I don’t get back to you for a few days—it’s not personal… I am busy collecting my Darwin Award.

PS: Interestingly, the computer was otherwise fine—which made it possible for me to run over to the local computer store, buy a new hard disk, replace it and be off reinstalling everything. While I was at it, I also bought a Time Capsule—I know, it’s not necessary, but what the hell.

⇥ 5 PHP 5 features you can’t afford to ignore

April 27, 2008
20 comments
 
⇥ Permalink

There are dozens of reasons to switch to PHP 5—not least the fact that, if you’re still stuck on PHP 4, the PHP team is about to pull the rug from under your feet. Despite the fact that you may not have a choice in the matter, upgrading comes with a number of bonus new features that can help you write better code and gain access to new functionality that required a fair amount of hacking in previous version. Here’s a quick list of 5 personal favourites (with a little help from my Twitter contacts):

1. SimpleXML
Although its name is the source of much frustration—simple is such a relative concept—SimpleXML is a great extension that makes manipulating XML data a breeze. Thanks to its integration with the PHP 5 object model, SXML allows immediate and intuitive access to the contents of an XML document using normal language constructs: your XML document simply becomes a hierarchy of PHP 5 objects that express elements and their attributes. Combine with XSLT for a kick-ass templating system that (a) is based on well-known standards so your development team doesn’t have to learn some made-up markup language and (b) really forces you to separate your frontend from the rest of your application.

Bonus features: SXML integrates with Xpath, making complex XML data extraction practically trivial. If you SimpleXML won’t do something you need it to, its underpinnings are based on the same library as DOMXML, making swapping between the two a breeze.

2. JSON and SOAP
Web services are all the rage, and blah blah blah. Forget the hype—the reality is that no serious web application can afford to have a single frontend anymore. Your users expect to be able to interface to your code in a multitude of ways and, if you allow them, will come up with new ways you haven’t even thought of.

That’s why the support for web service functionality built into PHP 5 through the JSON and SOAP interfaces is a boon for developers both because it lets them consume external services—making rich functionality easier to achieve and less expensive—and because it allows them to create interfaces accessible to anyone. Even more importantly, these interfaces make PHP a viable choice for complex backend applications that can be accessed directly from all sorts of Rich Internet development environments like Ajax and Flex.

Bonus functionality: some PHP IDEs (like Zend Studio) are capable of generating WSDL files directly from your PHP source code (thankfully, because writing WSDL files is about as fun as getting a root canal done with a rusty drill). Large vendors, like Adobe and Microsoft, are taking notice of PHP 5′s new interoperation capabilities and actually investing in making their products compatible with it and promoting its usage.

3. PDO
I am not entirely sure why, but PDO seems to be one of the great mysteries of PHP 5 (although not as much as SPL—mentioned later in this entry). The idea of accessing multiple databases using a single library is nothing new, of course, but PDO takes an interesting approach to the problem of database abstraction—it only abstracts access to the database, as opposed to the entire interface to it. This means that it doesn’t force you to adopt a “lowest-common-denominator” approach in an attempt to make your application function with every possible database, or implement costly abstraction layers. Rather, it allows you to access your database of choice using a simple, consistent interface that promotes good coding practices and provides important functionality like prepared statement and built-in escaping without bogging down your code.

If you are used to DBMS-specific libraries, PDO may seem a little hard to justify until you start using it consistently and find yourself wondering how you managed to live without prepared statements and language-level iterable result sets—to name a couple of the multitude of new features introduced by it.

Bonus features: drivers for all the “popular” DBMS, including MySQL, MSSQL, Oracle and more. Proper, exception-based error reporting.

4. SPL
If I had to pick a favourite-of-favourites in the new features provided by PHP 5, I’d go for the Standard PHP Library. The SPL allows userland code to present itself as one of a number of built-in PHP language elements like arrays. This sounds like little more than a triviality, but the overloading functionality that it provides can be incredibly powerful. The ability to make any object behave like an array—including iteration using foreach()—is perfect for result sets, filtering functionality, and so much more.

SPL is still suffering from a lack of solid documentation, but its functionality is relatively easy to understand, and some articles on its use do exist.

Bonus features: SPL comes with a number of useful built-in classes, such as DirectoryIterator, which makes examining the contents of a directory tolerable, and SimpleXMLIterator, which ties beautifully into SimpleXML. It also implements an enhanced autoloading feature that simplifies dynamic file inclusion considerably. Recursive iterators make for wonderful geek jokes.

5. SQLite
How many times have you wished you could have a cross-platform, portable, powerful, easy-to-use, file-based database system? Perhaps never—but only because you couldn’t use SQLite. This simple but full-featured DBMS packs all the punch of MySQL in a format that doesn’t require a database server and runs on every platform on which PHP 5 can be compiled. Creating databases is as simple as creating a file, and everything else follows an almost-standard SQL syntax that provides practically everything that you would expect of a modern DBMS—including support for transactions!

SQLite is a perfect choice for data storage where a MySQL database is overkill and a simple text-based file format doesn’t provide the performance you need.

Bonus features: SQLite columns are weakly-typed, making it possible to store just about anything. You can also register your PHP functions within the extension and access them from within your SQL statements. SQLite 3 is widely supported by a number of developer technologies, like Flex, making interoperability a breeze. A nice, multiplatform, GUI-based SQLite database editor built using Adobe AIR is readily available.

And much, much more
So, there you have it: five very good reasons to embrace the move to PHP 5. Any one of these five technologies has the potential to revolutionize the way you write code and open up new opportunities for your development efforts.

This is by no means a comprehensive list. Do you have other favourites? Share them below.

⇥ The challenge has been met!

April 24, 2008
9 comments
 
⇥ Permalink

Topbit, from “not too far from London” has written in with the correct solution to yesterday’s challenge.

The solution was not difficult to get at—which means that I need to come up with a more creative problem for the next time. Each group of four numbers indicated, respectively, an ISBN number (for either php|architect’s Guide to Programming Zend Framework or php|architect’s Zend PHP 5 Certification Study Guide), followed by a page number, line number and word number.
The six groups of numbers spell “Tell me that PHP Architect rules.” Lame, I know, but it’s difficult to come up with creative sentences out of technical books!

⇥ Riddle me this, and win $50 in php|architect coupons

April 23, 2008
4 comments
 
⇥ Permalink

I’ve wanted to do this for a while, but haven’t quite gotten around to it due to impossible work constraints, so, here it goes:

The Tabini Challenge, v. 1.0
Here’s a challenge that requires a combination of skill, patience and knowledge about me and what I do for a living. The winner (see Rules, below) gets a $50 gift certificate for our online store at php|architect:

973862157 61 14 3
973862149 94 30 3
973862157 5 2 5
973862149 247 15 1
973862157 32 21 9
973862149 84 5 7

Rules:

  • The winner is the first person from whom I receive an e-mail with the correct answer. I am not responsible for e-mail messages that get lost in any way, and the timestamp on my end is the final judge of who gets here “first”.
  • The riddle does have a solution—but it is, of course, possible that I have made a mistake in calculating it. In that case, I will void the contest and post a correct one.
  • The winner will receive a $50 gift certificate that can be spent at the php|architect online store on any product, without any limitation, so long as the entire $50 is spent on a single order (sorry, that’s the way our store works). The coupon will be worth for one year from the date of issue.
  • The contest closes on May 31, 2008, at which point I will post the solution.

Good luck!

⇥ Of eggs and baskets

All companies—big and small—make mistakes (big and small). It’s just the nature of business that one is forever trying to divine the tastes and needs of customers who never seem to quite know what they themselves want or are looking for, and so it’s inevitable that business decisions are a hit and miss, regardless of how much thought and work goes behind them.

When making a business decision, the payoff is inversely proportional to the risk—a decision that is counterintuitive is, by definition, an unlikely choice for your competition, which means that, if successful, it will bring a significant benefit. Success alone, however, is not enough to bring the payoff, because a simple idea is easily copied by the competition, thus mitigating the potential return.

A business decision that brings in a significant benefit, therefore, must be both counterintuitive and costly in order to bring a significant benefit. This means that the downside of an idea that has a lot of potential is… the potential for a lot of downside.

I am, by nature, a very cautious person, which, I would assume, has to be a common characteristic among people who run their business the way I do: MTA has no debts, does not use its credit facilities and has adopted a simple rule for every one of its activities—there has to be a clear path to measurable profitability within a well-defined period of time.

As you can see, I don’t really like big gambles, and I prefer the Japanese principle of Kaizen to the cowboy approach of big leaps and bounds. While none of our products is ever perfect, we continue to alter them by means of small, simple changes aimed at improvement. When a change doesn’t work out, we simply step back to the “last good iteration” and move forward again in a different direction.

There are two corollaries to doing business this way. First, big spikes are unlikely both ways—I would be surprised if our business came crashing down around our ears all of a sudden and, at the same time, I am not expecting our revenues to triple overnight, either. Therefore, this approach to business management is for those who are in it for the long haul.

Second, it’s important to have a plan and not to fall into the trap of feeling like you have to catch up to your competition every time they come up with an idea that you think is cool. It’s best to keep plugging away at those things that you decided are important, and integrating other ideas where they fit your plans.