Three Cheers for CakePHP Backwards Compatibility

27 Jan

cake-logoI would make a horrible framework developer.  Why?  Because I don’t have the patience to put the effort into making my code backwards compatible (unless I really, really have to).  Thankfully, the developers of CakePHP are not like me.

I just had cause to take an old client site that was built on CakePHP 1.0.x and move it over to a new platform with some upgrades in functionality.  Since we are most likely going to be developing a bunch of new features on the site I felt it was important to go ahead and upgrade the cake core libraries to the recently-released 1.2 — a task I was dreading from the moment I thought it.

But, surprise surprise, the whole ordeal wasn’t an ordeal at all.  In fact was incredibly easy because the Cake devs made it a point to include backwards compatibility. As a result a lot of my legacy code could remain in place to be upgraded gradually.

Take for instance the following gem.  I was a rough and tumble Cake developer back when I first wrote this and this format was actually never really acceptable in the first place, but it worked in 1.0.x:

$this->Order_frame->findAll();
// correct way to access the order_frames table: $this->OrderFrame->findAll();

// in view
echo $orderFrames['Order_frame']['type'];
// correct way to access the data: $orderFrames['OrderFrame']['type'];

Now, having used Cake for a couple of years I know the error of my ways. But, to my surprise, when I ran this legacy code locally on a fresh 1.2 core it worked. Huh? There was no way they would still support this ancient syntax! Heck, I dont think they ever supported it, really.

Anyways, this is a long way of showing my appreciation to the CakePHP devs for building the framework with all the legacy code out there in mind.

  • mattmillr
    Neat. Looks like they *just don't care* whether you use underscore_separation or CamelCase to access properties. I've been mulling something like this over in the back of my mind for our own ORM layer, where we have database tables with underscores but would like to automagically expose them in ActionScript objects where the underscores would just be ugly.

    IIRC, Flex styles do something similar depending on whether you access them as class properties or through CSS. The difference is that it matters that you use the right format in the right place.
  • Yeah, I agree about ActionScript camel casing. Some languages just _feel_ like they should be camelcased and other _feel_ like they are underscored -- usually correlated to whether they are OO or not.
blog comments powered by Disqus