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.

Posted Thursday, April 16th, 2009 at 10:36 am
Filed Under Category: Uncategorized
You can leave a response, or trackback from your own site.

6

Responses to “Lisp vs PHP”

Robert Berger

My sympathies go out to you. I hope you can find a way out of being stuck in PHP. I’ve had to do some work with that and it was like going back in time. I think option 3 could cause a lot of unexpected problems and delays. My recommendation would be to find a client that would want you to develop something cool with good tools. Maybe find a client that would fund your SasS project for instance.

We are just now rolling some clojure stuff into production for our own SaaS and so far so good. Huge productivity increase at least at this point…. Much more fun too!

Brennan

Thanks for sharing your experience and your recommendation.

I started to do some work on a Lisp interpreter in PHP (got the lexer and part of the parser done) but then ran into a wall trying to figure out how to implement nested scope for functions. Every implementation idea I came up with got messy real fast, would mean totally abusing PHP, and would be extremely slow.

I think you are right about #3 not being a realistic option. For now I am going to work professionally with PHP and continue learning Clojure on the side and use it for some fun projects of my own. I will position myself so that when the opportunity to use Clojure (in a professional capacity) presents itself, I will be ready for it. Experience has taught me as long as you know what you want and move in that direction circumstances will present themselves.

Valeriy

Hi Brennan, I was thinking maybe I’d be able to generate some PHP from Common LISP and was looking at someone who are interested in the same thing and I found your blog. Basically, this is a clear thing once you understand why you would need this. Being pragmatic programmers, we should understand the drawbacks of one of the technologies and maybe try to compensate with some others. I haven’t worked with PHP for almost 3 years now. But now I have to write a web shop and PHP looks the best option in terms of ease of deployment, hosting options, overall community is huge, most problems known, you name it! But I hate to write it. I think the approach should be to automate as much of PHP writing as possible with code generators in the language you like most. Clojure or any other LISP should be good at that.

I have a couple of ideas how this should be implemented in CL, I don’t know about Clojure, didn’t have time to look at it yet, but will do, all the LISP community is talking about it, and even old LISP hackers have welcomed this language, a good sign!

Brennan

Hi Valeriy. I haven’t thought about using Lisp to generate PHP code. I’d be interested in hearing your ideas. I was giving some thought about the code generators in RoR and implementing them in PHP.

I was also doing some work to make web applications in PHP with a more Flex / XAML type of development style (more declarative). It seems to be moving along nicely and seems like a usable solution. It’s excessively OOP though.

Valeriy

Hi again, sorry I don’t have too much time to dedicate to this. But I’ll try to describe the general idea.

In the past, I used Django for one of the projects and enjoyed it very much. I think that something like Django implemented in LISP would be even more enjoyable. I don’t know Hunchentoot maybe it does the job.

In Django, you define a model and the rest such as creating SQL statements, admin interface, is done automatically by the library. And the library directly serves the model content. It is very easy and fast to write and elegant. If one could develop and debug a site in Django and then compile the model into PHP so that it work exactly like the django model, that would be interesting. But I suspect problems here due to the fact that development with Django involves writing some Python code anyway, and that will not be easy to translate into PHP.

If a similar framework is done with the aim of being compilable into other languages, it would work. And LISP seems the best language to attach this problem with.

The vision:

You run a SLIME session, and start a web server. You create model objects. You also define web forms, and form handling. Immediately, you can access the running web server which works with the views and form handles that you’ve created. After you’ve done your model and view development, you compile it into PHP and publish.

KonstantinMiller

I have been looking looking around for this kind of information. Will you post some more in future? I’ll be grateful if you will.

Leave a Reply

You must be logged in to post a comment.