Cross-language polination

If you learn habits and patterns in one language, it’s bound to cross over and infect the way you do things in another language. Any given programming language will let you skin the proverbial cat 9 different ways (or more). I’ve been writing PHP more or less full-time since 2002, with a scattering of Cold Fusion and Javascript thrown in. I started writing my PHP code using a procedural approach with some dabbling in OOP. PHP lets me do either, both, or a mix (which is most often the case). It’s a very flexible language and there is power in that flexibility. But, like a permissive parent, it doesn’t force a lot of discipline in its followers.

Along comes Objective-C in my life. As I’ve mentioned, I’m working to learn the lingua franca of iPhone and Mac apps. Objective-C pretty much demands a 100% OOP approach (yes, it’s possible to write procedural code but that would be like owning a Porsche and never taking it out of first gear). As a result, my exposure to the Objective-C way of doing things is affecting how I write PHP code.

I have a series of classes in PHP used for database access. They inherit some basic functionality from a generic database class, but for the most part whenever I add a new table to my database I have to create a new class to access it. It’s reasonably efficient and works well once it’s in place, but there is still a great deal of functionality that’s identical between each table class.

Now that I’m seeing how things are done in Objective-C, I’ve already got some great ideas of how to abstract my database table access classes so that the creation of a new table is reduced to passing a list of field names, rather than the creation of a whole new class.

See, you can teach an old dog new tricks!

Leave a comment

You must be logged in to post a comment.