Lisp vs PHP

Thursday, April 16th, 2009

I’ve been studying Clojure quite a bit this last month.  I really love the language and want to use it but I think I am going to be stuck with PHP because of deployment issues and there being too much of a learning curve.

PHP is probably the worst programming language I have come across.  But, I find myself asking the question, then why am I programming in it almost exclusively for my “real work”?  My day job requires me to program in PHP and then any clients that I do freelance work for require me to write in PHP as well.

I noticed this pattern has happened to me when I was learning Ruby on Rails.  I spent months learning it but then when I tried to use it in “the real world” I found that I couldn’t.  My clients were using shared hosting.  If I developed any products I could only use it on my own servers and couldn’t sell it to others.  There would be no way for them to get it up and running without being sysadmins.

Clojure had the idea of using the JVM so that it has access to the entire Java API.  This is a brilliant idea but unfortunately I don’t live in a Java world.  Everyone I know and all my work opportunities are in the LAMP world.

I could use Clojure and just offer SaaS solutions but for selling actual products people can download and install on their server, PHP is the only option.

The other problem is if I did develop some stuff in Clojure and then needed the same functionality in PHP I would have to write it twice.

So I have a few choices as I see it.

  • First, I can continue learning Clojure and in another month or 2 I should be proficient enough to be developing web applications in it. I can concentrate on SaaS only and ignore the market for people being able to buy software they can install on their own servers.
  • Second, I could just stick to PHP and deal with it. There is no learning curve, I already know the language and can crank out work immediately (although probably not at the same pace as I could once I learned Clojure). This is probably the most pragmatic solution but I’m not so sure it would make me happy and there is no leverage involved in it. I could create something good but not great.
  • Third, What about programming Lisp but targeting the LAMP stack? I see 2 ways of going about this. I could start with Lisp code and then either have a Lisp interpreter in PHP or compile the Lisp into PHP. I did some searching on google and I have not found anyone doing something similar unfortunately. That means I would have to do it myself.

I am leaning towards option three. I have done some work with language parsing in PHP before for a Forth based language in PHP. I should be able to do a Lisp version as well.

Interpreted would be the easiest but would also be really slow. PHP is the slowest language out there and running an interpreter on top of that would be even slower. Still, it should be enough and with prices coming down and hardware improving it really does make business sense. Most of the time is going to be spent in the database doing queries and there is always caching.

Later on I might be able to figure out a way to compile the Lisp into PHP code.

Something is rotten with the current state of programming

Thursday, April 2nd, 2009

When you’ve been programming for so long sometimes it is hard to take a step back and rethink the way you are doing things.  As developers of technologies, languages and platforms we tend to build things incrementally as there is a need. This usually works to some extent but in some regards we end up with a horribly inefficient development experience.

Let’s take the current web development experience on the LAMP stack. One of the first things that strikes me as wrong is the sheer number of languages we have to deal with for any moderately complex project. We have PHP, MySQL, Javascript, HTML and CSS. Are you fucking kidding me? That’s 5 radically different languages while working on the same thing. Worst yet, I’ve seen code that uses all 5 of those languages within a few lines of code. Let’s not forget all the extra work we need to do for cross browser compatibility (always having to write to the least common denominator, or worst yet doing things multiple times for each different browser).

Other times we use one language to output the code to another language for the same data. <?php echo “var myVar=’$myVar’; ?> just so Javascript can use something from PHP. How retarded is that?

What do any of those languages do that would make it impossible or undesirable to do all of that in 1 language? Absolutely nothing! Now, I’m not saying they should all be written in the same style; quite the opposite in fact; but with domain specific languages (DSLs) it is possible to express radically different domains and concepts within a single language. LISP and Ruby both have good implementations for large portions of this but I think it can be taken much further.

Having one language for everything allows us to reduce huge amounts of complexity. Ever have to escape escaped characters? You end up having to type “\\\\” just to get “\”. Having 1 language also makes for better integration between all the parts of the web application. Why do we have to write a validator in Javascript and then do the exact same thing, in an entirely different language (PHP), for the server side when it does exactly the same thing? If we throw Actionscript / Flex into the mix we have even more overhead and complexity.

Then of course we have languages that are pushed to do things they really weren’t designed to do. Ever try to center an element vertically on a page with CSS?

Why is it that 70% of the code we write is plumbing to move data from one place to another instead of logic or algorithms? We have an HTML form that submits the data to PHP, which then needs to read those data and store them into variables, which then need to have PHP dynamically generate SQL that contain those data to be submitted to a database. We have the exact same problem going the other direction.

Does this seem a bit out of whack to anyone?

Let’s use some zero based thinking and transport ourselves 50 years into the past. Let’s say someone tasked us with creating something akin to the current Internet. How would we do it? I highly doubt it would look anything like what we currently have. If we had to build everything from scratch we most likely would end up with something dramatically better.

An analogy we can use is a giant snowball that is rolling downhill. It keeps getting bigger and bigger. Nobody wants to stand in front of it and try to slow it down for fear of getting squashed. It seems hopeless like there is nothing we can do. I don’t think this is the case. In fact, look at the cost if we don’t. I have no doubt if the entire system were redesigned the mid-level programmer could see a 10x increase in productivity. Do we really want to be working at 1/10th of what we could be doing for the rest of our lives?

I have some thoughts on how things can be done different which I hope to expand upon in future essays.

In the meanwhile I hope my words have sparked a curiosity in your mind as to how things can be done differently. I welcome your thoughts and opinions.


Saturday, February 28th, 2009

In my search of various langauges I have stumbled upon Clojure.  It meets a lot of the criteria established in the last post.

I am ashamed to say I have not learned a Lisp dialect up until this point.  I have known enough about Lisp to get the concept but never actually used it for anything.  The fact that it isn’t commonly available on servers nor common to set up caused me to shy away from it. The thought process going on in my mind was probably: Why bother learning something that I’m not really going to be able to use? It’s just an intellectual curiosity. Well, now I have good reason to learn it.

I bought the Pragmatic book Programming Clojure and like what I have learned so far. This language / environment has a lot of what I have been looking for.

It runs in the JVM so you have full access to any library that is available in Java. Moreover, it is often more convenient to access these libraries in Clojure than they are in Java. It can be embedded into any server architecture that runs the JVM. I haven’t looked into this step but I imagine it is pretty easy to get up and running on a server.

It has all the benefits of Lisp like homoiconicity and macros.

It takes great steps towards Intentional Programming. Since code is data you are not restricted to working with source code in some kind of lexical form. You can use tools that will output the code for you and compile it into JVM bytecodes on the fly and behind the scenes.

There’s much more that can be elaborated on but I think you get the picture. I definitely recommend checking the language out. You can find out more at the web site