Counter-intuitive Productivity

If you want to get something done, do it. When writing PHP, if I need to output something to the screen or save a record in the database, I write code that performs that function. But something happened in recent weeks that changed my approach to this situation.

Instead of writing code to perform the operation, I began writing functions that perform the operation. I would then insert calls to those functions. Long-in-the-tooth programmers that read this are probably thinking “Duh!” but there’s something subtle about this.

Even though I’ve been writing code since the mid 80′s, I’ve always had a ‘use whatever approach best fits the current need’ way of doing it. If it makes sense to write a function, that’s what I do. If it makes sense to build a class, that’s what I do. If it makes sense to write the functionality I need in-line with the main body of code, that’s what I do. I don’t have a default way of doing things like many developers do (OOP, anyone?)

The way my mind works is to ask, “Will this functionality be needed elsewhere? If so, write a function. Does this functionality need to encapsulate both code and data? If so, write a class.” This time, however, I began writing functions right away and didn’t specifically ask myself those questions (I already created the necessary classes for the project). Then something remarkable happened.

As I began coding the different versions of functionality that would be available to different levels of users (easy and advanced, create and edit, etc.) I found I had created a library of handy drop-in functions that dramatically increased my programming productivity. It seemed counter-intuitive at the time, but creating functions took slightly more time up front but dramatically reduced the amount of coding required soon after.

Instead of building results, I wrote functions that produced those results. Whenever I needed that result, I’d call the function instead. Again, this probably seems old-hat to many developers, but what’s different is that I took this approach by default right from the start rather than making that choice as I went along.

It was subtle but profound.

Leave a comment

You must be logged in to post a comment.