David Golding



Lessons Learned from Anno Domini 2.0

By David Golding

With the latest release of Anno Domini to version 2.0 I’ve had a lot to be excited about. First, in the couple months that Anno Domini 1.0 has been on CakeForge it has consistently ranked as one of the top projects. Somewhere around 3,000 downloads have come from CakeForge and another few thousand elsewhere. But I must confess that 1.0 had a lot of hacks in it. At the time I was fairly familiar with CakePHP but still pulled a lot of PHP hacks to get the dang thing to work. Since then both myself and CakePHP have improved and it became increasingly clear that some important changes would have to happen to Anno Domini before it would tank and deprecate itself against newer versions of both PHP and CakePHP.

So I started from the ground up and rebuilt Anno Domini on Cake 1.2 beta. Here are some important lessons I learned while doing this project.

Working in CakePHP 1.2 is faster

Getting started in CakePHP 1.2 early on had me worried about all the new functions or installation procedures, etc. And, naturally, bringing over projects built in 1.1 would have deprecated functions or helpers which I was not at all excited about hunting down and fixing.

However, I’ve been working all my new projects in 1.2 for months now and the benefits for biting the bullet and moving over certainly outweigh the costs. The overall experience, the gestalt if you will, of working in 1.2 is so superior to working in PHP by hand or from earlier versions of Cake. I found myself assuming that there existed a helper or a component which could cut down on the amount of work I’d have to put into almost every aspect of the application because most of the time I’d be right. If you haven’t begun working in 1.2, and even more importantly, if you’re still just doing things in PHP alone, now is the time to begin working in Cake 1.2 beta.

Fat Models do more than trim the controller

I took Daniel Hofstetter’s advice to look for opportunities to put functions in the model rather than in the controller. Not only did this trim down my controllers by reducing redundancy in the app but the overall structure of the organization of the app was improved. I think when we put everything in the controller, the organization becomes much more one-dimensional. But by beefing up the models my controller was trim and it allowed me to break out into more areas to build chunks of the app. This one intentional realignment of site organization, I think, can lead to a more improved layout to app resources.

Doing things right can dramatically reduce coding time

Following the conventions in Cake really does speed up programming. In the end, Anno Domini 1.0 took about three to four weeks to complete, somewhere around 40 to 60 hours to finish. True, learning from past mistakes cuts down on redesigning the application, but I’m confident the disparity between production time on Anno Domini 1.0 and 2.0 owes more to Cake 1.2 and following Cake conventions than my improved awareness of what worked and what didn’t in 1.0. Version 2.0 took me around 18 hours to complete, about two full work days. That’s around a third to half the time as the first version. By the end of the project, I really had begun to see the benefits of strictly adhering to Cake conventions and not to hacks.

One example was in the component class. I had wanted to access the model directly from the component but had read in many places that such was not the design of the Cake structure. I had to settle for using the $this->requestAction() in the controller to return some basic model finds but later on noticed that those controller functions were useful elsewhere. By sticking to the Cake convention, I was spared some redundancy.

So, there are certainly some more nitty-gritty details I got out of this project, but I hope these facts illustrate some benefits for the rest of you. Adhere to convention, new releases of Cake, and make your models nice and fat and you will be rewarded :)


Comments

No Responses to “Lessons Learned from Anno Domini 2.0”



Submit Comment


Beginning CakePHP: From Novice to Professional by David Golding

David Golding

A blog about CakePHP, web design, and grad studies in religion. © 2008, D. Golding