PHP development vs Java vs C# vs ASP...

My experiments with Mediawiki have been extended into an examination of PHP itself. I wanted to interrogate the Mediawiki db.

I started with ASP and found (unsurprisingly) that ADO's blobs are not capable of dealing with MySQL. The variant object returned from a binaryblob is "unknown" to Javascript. Much swearing. So I decided to bite the bullet and write what I wanted in PHP directly - a language I have never used.

I expected a huge struggle. Java gave me one - lots of fooling around with xml and classpaths. C# gave me one - similar problems. Hell even ASP gave me one for this task.

PHP just worked - database opened as the examples suggested. Reading out of the wiki database achieved in about 5 mins. OK so surprise over, now down to using its slightly weird syntax. I knew it was a Perl clone, and since I needed to chop up strings, I thought it would be a good idea to try regular expressions. This was the slowest bit of the development - creating a regular expression to slice and dice out the tags I wanted. After a few false starts and head scratching I started to notice the PHP libraries were really very complete.

Regular expression matching over arrays is rather smart - change every " " to an "_" and the like, and it then proved to be able to do a few more tricks I haven't seen other languages do well, like showing the missing elements missing between two arrays. I was impressed.

The syntax is very old fashioned. Arrays do not have methods, but are passed to functions. The $ infront of variable names gives it a Perlly uglyness. Its very loose. Variables appear on demand, and have no obvious way to declare them. Excitingly you can put a variable directly into a string so:

$out = " My name is $NAME. How do you do?"

works. Having been a javascript user for a while it seemed to have much of the power, but with a far better library of functions. I am turning off purist approaches of rigidly typed languages. I didn't once wonder what my variable type was today, much the same as with Java. When you are obviously squibbling a type, yes its handy to know what it is, but usually you see them coming. In 5 years of JavaScript and C++, the only typing problems I have had are with C++, and the COM layers that dwell in MSoft's browsers (methods returning DATEs yay!).

PHP appears very rich. In fact it probably has too many functions. I found it took a while to work out which you wanted.

Looking thru the Mediawiki code it's obvious PHP can do much more than I am using it for, but for the time being it has served my purpose well.

I suspect its performance sucks - certainly my config of a P4 3.0 seems to take .7s per MediaWiki page - I load tested for the hell of it, but I am not using any of the numerous accelerators out there. Besides, there are often better ways to reduce code on a website if performance is really necessary. I suspect that's partly why PHP has such a full library of functions - you don't need to write as many iterators, so most of the processing happens in the core.

All in all I am pleasantly surprised. .Net has funky controls on the page and lots of claim to support this that and the next thing, Java has cross platform support (and now serious speed). But I feel to write what I have today in either - assuming no prior knowledge of the language or platform - would have been hard to impossible. I know there would have been a brick wall - like the one I hit in ASP, or getting the program manifests right, or the Interdev integration would have unexpectedly broken itself.

So will I use PHP for my next project? No. The performance issues disturb me, and non-mysql support is weak. But its nice to know that its a simple effective database programs can be written in PHP. I'll certainly be keeping an eye on it...

Comments

Popular Posts