Yes, PHP sucks, but it works

Jeff Atwood had a really great blog entry on PHP the other day. I think the title pretty much sums up the way I feel about it: PHP Sucks, But It Doesn't Matter.

I've been working with PHP for about 3 or 4 years now. For the last 9 months, writing PHP code has been my day job. And I've got to tell you, PHP really is kind of a crappy language. It's so bad you can't even complain that PHP was poorly designed, because it quite clearly wasn't designed. In fact, I'm not even so sure it "evolved." Sometimes it seems like it just sort of mutated.

So, as Jeff said, nobody with an ounce of programming talent could thing that PHP is a "good" language in any objective sense. It's just too hacked-up and thrown together. It's the Visual Basic 6 of the web. God knows much of the PHP code you find on the net is every bit as terrible as the VB6 code you find. In fact, when you consider ill-conceived "features" like safe mode and magic quotes, it even starts to make VB6 look good.

But all that is really beside the point. At the end of the day, PHP does the job. It might not have the orgasm-inspiring elegance of Ruby, but does it really need that? These days, PHP has all the big features - decent object-orietation, a rich standard library including decent XML handling and database access layers, and a number of good MVC frameworks. In short, it has what it needs to allow decent developers to write good, solid, maintainable code. PHP doesn't lend itself to elegance, but in the right hands, it can be elegant enough. And really, that's all that matters.

F# on Mono

I learned something cool yesterday - F# runs on Mono! That means I can mess with it without having to use VMware!

I got interested in F# from hearing about it on Hanselmintes and .NET Rocks. For those who haven't heard of it, F# is a functional programming language, similar to OCaml, built on .NET. It's actually not an "official Microsoft product," but rather a project out of Microsoft Research, which is pretty cool.

Incidentally, working Microsoft Research is on my list dream jobs. I mean, how many organizations can boast of having had two Turing Award winners on staff? How could you not want to work someplace like that?

Anyway, the thing that excites me about F# is the combination of functional programming and its status as a first-class .NET language. I've been meaning to get up to speed on functional programming for a few years now, but I've just never gotten around to it. Learning LISP or ML always seemed on par with refreshing my Prolog and Ada skills - an interesting exercise, but not profitable in terms of marketability. I mean, how many Standard ML listing have you ever seen on Monster?

However, it looks like functional programming may start pushing more into the main stream. The current trend in hardware is that CPU speeds are flattening out and performance gains are being made by adding more processors or cores. However, most code today is not written to use more than one core/proc at a time. So we're going to have to start parallelizing our code to fully take advantage of the hardware. That's where functional programming comes in. Pure functions, by definition, have no side effects. So if you're writing pure functional programs, parallelism becomes much easier, as you have no worries about thread safety and whatnot.

So with F# I can now learn functional programming while using .NET. This means that I can leverage some of my existing knowledge while learning the new language, which always makes things go faster and smoother. It also means that this learning experience has some vague marketability, i.e. I can at least count it as .NET experience. In other words, it's not one of those "off in left-field" learning ventures like if I took up Intercal or APL. I'm not going to feel (as much) like I could be making better use of my time.

Anyway, it turns out that installing F# on Ubuntu 8.04 wasn't quite as painless as I had hoped. On the up side, the F# site does supply a ZIP archive with generic Mono-compatibile binaries and full source (under the MS shared-source license). However, it seems the binaries don't quite work right with Mono 1.2.6. That's fixable, though, thanks to Laurent Le Brun's article on using F$ 1.9.4.17 on Mono. Basically, the important thing is to remember to pass mono the --runtime=v2.0.50727 option when running the F# compiler or F# binaries.

I haven't been blogging much lately, but hopefully I'll be posting back in the coming months with tid-bits on F#. It's been a while since I tried to learn a new language, especially a non-procedural one, so I'm looking forward to it.

I wish Ming had documentation

Documentation is a good thing. Especially for programmers. When you're working with a new API, you like to know exactly what all those functions, objects, and methods do. Otherwise, you're just kind of guessing - and that makes the programming process quite painful.

I spent much of today messing around with the Ming bindings for PHP. Ming is an open-source library for creating Flash movies. It's a nice library and pretty much perfect for what I'm trying to do - dynamically create SWF files from user-uploaded data.

The only problem with Ming is that the documentation is practically non-existent. Oh, sure, PHP has a documentation section for it, but it's largely just shell docs - auto-generated function declarations with parameters. Little to no information on what the functions actually do. Fortunately, gazb has a nice Ming example site which makes up for that. It includes basic samples of all sorts of common scenarios, so I was able to figure out the stuff I needed pretty quickly.

The problem I'm having now, however, is not with the basic usage of the library, but rather with some of the deeper details, i.e. the ones that go beyond the basic syntax and usage. In particular, I'm working with SWFSound objects, trying to bind an arbirtary, user-uploaded audio file to a button. The problem is, the Ming documentation cointains zero informtation on exactly what formats SWFSound can handle. I've tried several variations on WAV files - some work, others just produce static. Apparently SWFSound also supports some compressed formats, apparently including MP3, but I've yet to get any results with those.

So now it looks like I'm stuck with the scenario of converting all the user-uploaded audio into a known-good format before passing it off the Ming. Now I've just got to figure out how to do that. Ming seemed to like the WAV files produced by MPlayer, but we don't have that on our servers. Rather, we have FFMPEG, and Ming barfed all over itself when I tried creating the WAV files with that (meaning it segfaulted trying to write the SWF). Apparently I just don't know the magic flags to make it work.

In any event, it would be really nice to have some hard information here. But I guess that's what happens when you use extensions that are listed as experimental. Maybe I should just get an ActionScript compiler installed on the servers and write a script to populate a template source file.... Of course, that would mean I'd have to learn ActionScript.