Using a framework? Why you should still learn OO and SQL
It was just one short year ago that I began a new job working as a “programmer;” prior to that, I’d styled myself a “Web developer” or something similar, but the new job meant that I’d be doing something much different than before. During the interview, terms like “object-oriented programming” and “SQL” were tossed about, and I truthfully acknowledged that I understood and used such things in my working life, although not terribly frequently. (My previous job was a Filemaker and procedural programming shop.)
When I arrived and began programming Web applications, I took a look at CakePHP, and suggested we use it. Soon, it was implemented for basically all new development projects. I quickly realized, though, that I had a huge knowledge gap. Sure, I know what object-oriented programming is, and even done a bit of stuff previously, but when my boss suggested we might use things like an observer pattern on some legacy code, or when he talked of extending CakePHP’s controllers in various ways, I knew I’d need to expand my skills.
And even with the database side of things, where I felt a bit more comfortable, I found that my knowledge of SQL was a bit rusty in spots—such that I couldn’t decide if what CakePHP was doing (say, with joins) was correct or whether I’d need to do things differently.
Frameworks like CakePHP, Zend Framework, and Symfony allow you to quickly and easily write a “real” application, but in doing so they tend to shield you from things like raw SQL and obviate the need to manually load or extend classes, for example. I contend that this is a good thing, but only if you understand the “guts” of the system—that is, OO and SQL, for example.
Why? Consider what happens if your framework loads data into a variable in a completely unexpected way. If you don’t understand the SQL that’s going on under the hood, what chance do you have of determining whether the framework is wrong—or perhaps you’re not calling the data in the right way?
In a similar vein, knowing how to program in an object-oriented way is also vital. I’ve looked at the Lithium framework recently, and confess to not understanding a lot of what’s going on. Sure, there’s some documentation, but I’m certain my learning process would be helped if I understood things like singletons, or lazy loading, or even anonymous functions.
This goes beyond mere debugging or learning new technologies. As in the example I gave earlier, it’s quite possible that you’re going to hit a point at which you want to do something the framework doesn’t do natively; in this case, your OO skills come into play, letting you get the job done. Or what if the framework can’t handle the poorly designed legacy database you inherited? Suddenly your SQL-fu doesn’t look so useless, since you’ll be able to write occasional custom queries when the framework falls flat.
But even beyond that, there will be times during which you can’t (or don’t want to) use a framework. I recently took a look at CouchDB and PHPillow, and I confess that I still can’t get PHPillow to work. My OO chops are simply not up to par. That experience taught me that I really need to start taking my favorite PHP book to bed with me a little more frequently.
So, even if you use a framework, take the time to get to know object-oriented programming and SQL (useful even if you’re using a document-oriented database, I think). They truly form the building blocks of programming.
Image of building blocks from Flickr user Artful Magpie. Published under a Creative Commons Attribution-Noncommercial-No Derivative Works 2.0 Generic license. http://www.flickr.com/photos/kmtucker/3355551036/
Leave a comment
Use the form below to leave a comment:
Responses and Pingbacks
April 28th, 2010 at 8:00 am
I assume that a PHP analyst/programmer already has OO and SQL *great* skills.
I think you can’t define somebody a good programmer without these kind of knowledge: these are the basics.
April 28th, 2010 at 9:49 am
@Odino: I disagree. I think you can define someone as a “good” programmer even if that person lacks top-notch SQL or OO skills. Note that I didn’t say “great” programmer. I readily acknowledge that I’m not a spectacular programmer; I pale in comparison to others we see on this blog, I’m sure. But at the same time, I did some stellar work with procedural PHP (with a bit of OO thrown in) and a Filemaker database at my previous job. Does that make me a crummy programmer? I don’t think so; our legacy data was in Filemaker, and so was our code, and with too few people in the department we simply used the tools at our disposal. (I hear things have changed, though, thankfully!)
In any event, my post was aimed more at the entry-level programmer who might be seduced by the simplicity that a framework seems to offer. We hired a student programmer in my work group recently. Although we use CakePHP for new development, I insisted our student first use the mysqli portions of PHP to work on a project. It’s important to learn to crawl before you enter a marathon.
July 27th, 2010 at 2:23 pm
Hey,wonderful article. I began building websites in 98, I used view source, and learned html then css, some php, etc, in time. All of the sudden at some point all of this crazy OO programnming began to surface more, and I feel like I missed the train. Although I have been a freelance web developer (loosely termed I guess), I am lost in the true php programming. I am so hungry to learn it, but really don’t know where to find a structured learning environment, well without spending thousands, I just went through a divorce, and have 2 children to feed. Any ideas where someone who is a quick study, and has some understanding of the MVC could get structured learning? I have downloaded Cake, Zend, well, most of them, and tried to learn through tutorials, but I feel it will take me forever without some good guidance. Thanks for your great article again! jerryLee
July 29th, 2010 at 1:10 pm
There are plenty of free resources out there for learning OOP. Check out Nettuts (http://net.tutsplus.com/tutorials/php/oop-in-php/) as a primer. Also, if you don’t want to invest a lot of money, use Safari Books online. You have access to many books, for a flat rate per month about 30 – 40 dollars. PHP, Objects, Patterns and Practices from Apress has proved an invaluable resource for me as a developer.
December 28th, 2010 at 2:23 pm
Also busy with the oop thing and i still can`t find the advantages. Every where i ask, the say: learn oop. If i want to learn it and get stuck, they advise me to not reinvent the weel and use a framework. So now i need to know php + php-oop + framework + eventualy ORM. Ok, so i use Cakephp to find that i don`n need to realy learn oop, just the basics to extend the model/view/controler. Then i find myself using pure php inside the class. How am i ever gonna learn php oop? I thing people using frameworks are realy not using the oop thinking mechanism, but writing php inside pre-defined classes, designed by Cake?
March 29th, 2011 at 10:48 pm
Great article carl. As an entry level programmer in php I had a hard time deciding whether to choose a framework or go OO. I picked up a book on cakephp and even though I could build an application(mostly from code samples from the bakery and cakephp books) I had no idea what was happening especially when something went wrong.
This year I took on learning OO and I have to say I am much more confident in my programming though the road is long and i’m slowly getting there. In my opinion the trick is to find a book that does not stick too much to basics but uses OO to build a sample application that you can use as a base to build your own.
I can suggest PHP Solutions: Dynamic Web Design Made Easy Second Edition By David Powers. If anyone has come across any other good books please post their titles.