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.
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?