D on the Web

I took a look at the D programming language today:



I admit that I’m a sucker for new programming languages but this one looks genuinely useful. Nice object oriented programming, compiles to machine code, garbage collection and a lot of of other useful features.

Part of the reason that I like to look at other programming languages is my frustration with PHP, which I spend most of my days writing. I like PHP a lot and can churn out scripts at quite a rate. People often criticise the language because it’s possible to write spaghetti with SQL followed by PHP followed by HTML, all next to each other in the same file. Programmers can be lazy with any language. With care and time (admittedly more time than most deadlines allow) it is possible to write high quality, professional, object oriented code either from scratch or (more likely and perhaps better) by refactoring the script that you cobbled together in an afternoon and have found to be useful.

My problem with PHP is that I’m not sure that refactoring your rough drafts (the SQL/PHP/HTML brain dumps) to PHP goes far enough. Your refactored code might be more maintainable and allow reuse but it probably won’t run quite as quickly. Also, PHP’s very permissive syntax (whilst useful for the hacked code I mentioned earlier) allows for some very hard to find bugs in larger programs spread across lots of files.

One solution might be to use JSP. I used to write Java at work and found that it was a real nuisance (compared to the PHP, Perl and JavaScript that I was also writing at that job) to write at the early exploratory stages of a project but great once the major pieces had fallen into place and everyone knew what was what and where things ought to be.

But I like to consider all the options.

Some folks like to write extensions to PHP in C or C++. This always seemed like quite a sensible thing to do. In my mind, ultimately every program should make its way (albeit slowly) to native code. PHP is olften described as glue linking lots of native libraries. There’s no reason why libraries of PHP shouldn’t evolve to native libraries.

But C and C++ have their problems and are in some ways lacking when compared to Java. Java’s interfaces are useful. D similarity to Java makes it look very interesting. The brief look that I’ve had of it suggest that it has all the safety features of Java (that are missing from PHP), nicer object orientation than C++ and native speed.

Has anyone got any experience of refactoring a large PHP program to D? What about writing CGI programs or native PHP extensions in D? Is it worth the effort?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s