Dynamic Loading in PHP

August 15th, 2005

I recently started on a small project in PHP, and in working on the project I began to explore how to leverage the OO capabilities of PHP. Much to my delight, I discovered that PHP is a far more capable language than its normally given credit for. I’m sure that there are just as many reasons for that as there are opinions, so I won’t share my opinions (this time). Instead, I would like to share a technique that I have recently developed since I feel that it will not only be interesting to the PHP community, but useful as well.

The technique is a form of dynamic loading, the PHP equivalent of a DLL (more or less). At first, this seems like a rather strange concept for an interpreted language, but it has uses, the most important being that it can reduce code complexity without sacrificing functionality. It is based on the OO capabilities of PHP, and as such is an abstraction layer, which I have blogged about in the past. As with all abstractions, it is always important to understand the internals of the abstraction instead of just blindly using it. With that warning issued, lets get into the actual technique.

In general terms, I needed a “driver” for my project, so I will use the driver model as the basis for this article. Many years ago I stumbled across a driver technique that was used in gnuplot. It was a clever abstraction of the driver layer, even though it was written in C (none of those fancy OO languages existed, and those that did, were not well known and had not gained any real acceptance). This was (and still is) a fine example of how OO-design is a methodology and does not require an OO language to implement.
Read the rest of this entry »

The Knuth of the Matter

April 12th, 2005

“People who are more than casually interested in computers should have at least some idea of what the underlying hardware is like. Otherwise, the programs they write will be pretty weird.”
Donald Knuth, 2004

Donald Knuth is very wise, a god of computing, so I don’t doubt for a second that he understands that this quote applies equally to layers of software abstraction as well. I love this quote though, it has some wonderful subtleties that I am sure are completely lost on fragile programmers.

So lets talk about abstraction. It’s a wonderful thing, but only if there is some comprehension of what is being abstracted. Sure, you can treat the underlying abstraction layer as a black box, but when we are talking about software that can, more often than not, be a fatal thing to do. Of course with software abstractions, the fatality is rarely instant, instead an obscure, difficult or impossible to document set of circumstances must occur. As so many of the current and next generation of high-level languages gain acceptance, there is more and more abstraction and less and less understanding of the the underlying layers.
Read the rest of this entry »

Fragile Developers

September 4th, 2004

Originally posted on QNXZone

In recent years there has been a significant amount of hype and discussion around modern programming languages, most often it is Java or some other OO language. The name of the game is abstraction and things like pointers and allocating and releasing memory are all too often made out to be terrible demons from that evil C language.

Don’t get me wrong, abstraction is great, or at least it can be, but it makes it all too easy to loose track of the underlying arcitecture layers within any system. Yes, layers, more than one… too often we think of archtecture as only a single layer as it pertains to the application we are building at the time. The reality is that there are layers, and each layer has it’s own quirks. The more knowledge we have of those layers the better able we are to leverage them and get the most performance out of every single one.
Read the rest of this entry »