EDIT (5/25/09): Some how my Wikipedia link to Domain Specific Languages got lost in a draft somehwere, thanks Supermike for noticing it was missing. http://en.wikipedia.org/wiki/Domain-specific_programming_language
Disclaimer: I’m going to try my best to keep this post from turning into a rant comparing PHP to other trendy scripting languages. Also, If you came here with a pre-disposed opinion that PHP sucks, I’m not likely to convince you otherwise, so I’ll concede now; that’s not the point anyway.
There’s been more and more activity on the blogosphere about DSL’s lately, and I’m not buying into it (partially because some of them are well-crafted trolls). I believe that there’s not many domain-specific languages out there, at least not “main stream” ones. When I think DSL, I think Lego LOGO and BASH; languages that literally solve one problem. There are many other languages available that happen to be particularly good at doing one thing or the other, however that’s not to say they couldn’t do some other thing, albeit very poorly.
There’s a mile-long spectrum of language functionality to consider here. You have C/C++ that can be made to do damn near anything from programming your refrigerator to serving web pages. On the short end of that spectrum are DSL’s. So where does PHP fit into a scheme like this? I’m going to say it sits squarely in the middle, and that’s why the internet has such a love-hate relationship with it. PHP is good at many things, great at a few things, and terrible at a few as well. People who don’t solve problems with PHP all day every day aren’t fully aware of it’s extensive capabilities, and have been shown most likely to start flame wars about PHP’s inferiority to (Ruby|Python|Java|C#) by an incomprehensive study I just conducted in my head.
PHP, in it’s early stages, could definitely have been considered a DSL. It existed solely to solve one problem: the web problem. (I’ll also argue that the folks over on 4Chan maybe creating the “web problem” as we speak.) What is the web problem? It’s the “D” in DSL. The domain. How do we create web pages programmatically? That’s the web problem, and PHP came around and started solving it. Really damn easily.
With PHP4 and especially PHP5, times have changed. PHP’s runtime, if you include the vast extension library, is full-featured almost to a fault these days. Now PHP solves lots of problems, from raw-socket TCP/IP problems, to XML parsing problems, to Database problems, and more. I’ve even heard of someone writing a software compiler in PHP (purely acadamic, of course). So is PHP great at solving these new and more complicated problems that the Internet has brought upon us? Nah, it’s not great at them. But it’s pretty good, and that’s good enough, especially considering that you can tackle almost any internet-related problem without a context swith to another language (because you’re already building web pages in PHP to start with right?).
So what does PHP suck at? Well, there are some things it just can’t, in fact probably never will, do. PHP can’t do threads. In fact, it’s not happy when other things that touch it are doing threads. If you must have threads, you should probably use (Ruby|Python|Java|C#). PHP also sucks at running for a long time. PHP scripts just aren’t meant to run for 10 days at a time. Somehwere along the line they’re probably going to develop a memory leak and do something nasty. That’s OK though. PHP wasn’t design to run for a long time or to spin up multiple threads. And this my friends, is where the gray area comes in. I spent the last paragraph telling you about how PHP wasn’t a DSL because it could solve all these disparate problems (or at least implying it…spoiler alert), but now we have a problem. I just told you two of PHP’s shortcomings were language design issues. And why were they designed that way? Well, PHP is meant to be created and torn down in the context of a web request, because PHP was meant to solve the web problem.
So no, PHP isn’t a DSL, but it used to be. Ironically though, what makes it so popular, is that it’s really good at that one thing: it’s damn good at creating web pages.