Compiling vs Interpreting

I’ve recently started work on a program to catalogue my books and book-like items. After a large amount of thought, I settled on a GUI application even though I knew nothing at all about writing a GUI application. Once I settled on that, I did some research into programming languages and came up with PHP5 using php-gtk2.

Now programmer types might be thinking that a scripting language is a bad choice for a GUI application. I would have said the same thing. After some experimentation, I have come to the conclusion that PHP was the right choice for a couple of reasons. One is that I know the language so I do not have to put a lot of extra effort into learning it. Another major reason is that it is a high level language which will not require that I do a lot of fiddly coding under the hood just to glue everything together with string handling and so on. Having done a lot of that sort of thing with C and C++ in the past, I have no desire to do it for anything this substantial.

Once I looked at the GUI toolkits, I realized that making a GUI is about the same in any language once you get past the various incantations each language requires to instantiate a widget. Likewise between the various toolkits. Since GTK has a binding for PHP called php-gtk, I decided to use that one.

It was a daunting task initially. There is thousands of pages of documentation on programming GTK. So where did I start? Eventually, I found an entry point and got a few simple test programs running and I’m well on my way to actually accomplishing something.

what I have learned in the past few weeks is that it doesn’t really matter that the program is interpreted. It only has to run as fast as I operate which is substantially slower than the work horse on my table. Responsiveness is sufficient in the interpreted state. Also, when you get down to it, the intermediate parsing step happens once during application startup and we’re used to applications taking a few seconds to start so what’s that matter?

Still, it would be cool to have my program not require a lot of external things like the PHP interpreter to run. Or, for that matter, a bunch of bash-fu to make sure things are kosher before launching the PHP code. This is where Roadsend comes in. They produce a free PHP compiler which just now in testing supports PHP5 and they are working on php-gtk2 support. This means I will be able to compile my program into a native application and not have to worry about wonky PHP settings in the future. There will be no dependencies on the Zend PHP implementation.

This does mean, however, that I need to stick to a relatively small subset of PHP extensions. This is not likely going to be much of a restriction anyway since most PHP extensions are somewhat special purpose. As long as I have the core of the language and the standard library, I should be fine.

There is another consideration, though. The way an interpreted project is constructed is often somewhat different to the way a compiled project is constructed. This means that there may be some code structure differences. Still, that’s relatively minor.

Even with the option of a compiled version, I think I’ll stick to the Zend PHP interpreter until I get the project actually working. Then I can monkey with things and see if the Roadsend compiler is the right choice. They do say that premature optimization is the root of all evil. That may be a bit strong but the basic point does hold.

Leave a Reply

Your email address will not be published. Required fields are marked *