A rant on php frameworks

Every now and then, someone questions why we have to use a framework when coding php. That very issue came up on HN a couple days ago: http://news.ycombinator.com/item?id=2235507

I have to say the anti-framework camp is on to something.

Frameworks can be a huge help, and learning one is a great way to learn some best practices and keep an eye on what other coders are doing. This is especially important for people like me who pretty much never work with others.

Still, come on. Does every little project really need to be done in Cake or Zend, or whatever? The answer is no. Just as some apps can get by with no database, many don’t really benefit from all the features a framework offers. And if that’s the case, why go to the trouble?

People like to say they’re pragmatic and practical, but that’s rarely the case. Frameworks are shiny and cool. Saying you don’t use one is heresy. So you learn one, which is fine until you get locked in. When you realise what’s going on, you need to justify to yourself why the time investment. So you try to convince others that frameworks are the way to go, regardless of the scope of the work to be done.

Me? I just learn frameworks because it’s a nice way to get to know the work of others, maybe incorporating some practices into my own code. But that’s it.

I think PHP frameworks have a thing or two to learn from the likes of jQuery. There’s a “framework” that really doesn’t lock you into a certain way of doing things, while being ridiculously useful.

End of rant.

This did not go as expected

Saturday

It’s half past noon on a Saturday and I’m about to start work on CarePinger. But first I need to learn my way around CakePHP, the framework I chose for this project.
 
But why use a framework that’s completely new to me, instead of whipping out my own trusty little app engine or simply hacking together a few scripts? After all, my goal is to have CarePinger up and running by tomorrow and the app is indeed very simple. Well, it’s a matter of challenging myself while learning new stuff.
 
I’m very familliar with the MVC pattern of course, having coded my own framework around it. However, Cake is far more complete than my own little app engine. As awesome as my work is, I feel that there’s a lot to learn from exploring the ins and outs of a widely adopted framework. So I’m using CarePinger as an excuse to finally get my hands on some Cake.
 
So yeah. It’s half past noon, I want CarePinger to be at least functional by Sunday evening, and I only just downloaded Cake. Time to get moving. I’m going to start by reading up on IBM’s “Cook up Web sites fast with CakePHP” 5-part series, and proceed from there.
 
Let’s go.

Monday

Sunday has come and gone. It’s now Monday and is CarePinger done? Nope. Have I learned CakePHP? Not really, either.

This is what happens when I’m too stressed out. My decision-making ability suddenly goes south, and since I’m way too stubborn to notice, entire days can be lost to either analysis paralysis or incorrect decisions. Like this past weekend.

Here’s how it played out.

I had this awesome idea last Thursday for a project called CarePinger, which I immediately locked in the “really really simple, lol” category. I figured it could be done in a few hours, tops, so why not take the opportunity to throw in some learning action as well. That’s where Cake came in. I’d finally get around to learning CakePHP, and hack a cool project together at the same time. I had nothing to do that weekend, no trips out of town, no paintball games, nothing. It’d be nothing but me and my laptop for two days straight. With so much time on my hands, and my learning speed being the stuff of legend, what could possibly go wrong?

As it turned out, a lot could. A little trip to the shops for some groceries. Cooking lunch and dinner. Caring for my suddenly-ill girlfriend. A hard drive failure. A huge amount of stress from my current job situation. My mind was really not in the right place for some quality learning and coding time, and because I didn’t actually plan a schedule, there was never a 1-2h block when I could sit down uninterrupted and work.

But the worst thing was that I didn’t even stick to the plan. I meant to learn the basics of Cake and then hack out CarePinger on top of it. Well, I didn’t even make it to the end of the first lesson before deciding Cake was far too bloaty a framework for the simple needs of my project, and that maybe I’d be better off using something simpler. Only, I didn’t really want to go with the proven framework I use in Threddie. Oh no. I have another one, still in early-ish stages of development, which is really cool because it’s a RESTful thing of beauty that’s meant to power single-page AJAX apps. It lazy loads everything, has amazing scaffolding capabilities and the only thing that comes out of it i
s JSON and baby foxes. Obviously, I had to give it a go.

So yeah, by 9pm Saturday evening the plan was already in tatters. Then Roxana had a fever. Work day over.

Sunday was even worse because the clock was ticking and for some reason I hadn’t had a decent night’s sleep. My morning disappeared in a flurry of keyboard strokes as I desperately tried to twist my theoretically perfect RESTful framework into something resembling practical usefulness. The afternoon was even worse. I knew I was melting down when setting up Facebook Connect suddenly seemed impossible. Slowly, I lowered and closed my laptop lid and stepped away from the desk. Five minutes later, I was napping on the couch.

And it was like hitting a reset button. When I woke up, CarePinger no longer sounded like a 4-hour project and I wasn’t in such a hurry to get it done. CakePHP still seemed bloated as hell, but I wasn’t in a hurry to learn it either. The deadlines had been lifted because I realized they never mattered. I realized that learning something new was what was really driving me all along, and the impossibly short timeframe I’d allocated was hurting my determination rather than encouraging my resolve.

So I opened IBM’s excellent tutorial again, redid the first lesson and then the second. I thought it was going slowly as hell, but the funny thing was, when I looked at the clock barely any time had passed. I was back in the Zone, absorbing knowledge like a motherfucker. CarePinger was never going to get off the ground that weekend, but it didn’t matter.

At least I got my mind back.