iPerSec
internet Performance & Security

Switching to a new scripting language ?

septembre 1st, 2008 by jfbus

Why I don’t like PHP

After having spent quite a few years programming PHP (from functional to OO programming), I just realized I don’t really like this language. The main problems I think are with PHP being :

  • The lack of consistency : functions not always follow the same naming conventions (underscore, no undescore), and, more important, parameters are not always in the same order ($haystack, $needle or $needle, $haystack ?)
  • The lack of universality : PHP only really works in web-only environments (ie : using mod_php or FastCGI). But sometimes you would like to write daemons, servers (ie to asynchronously process data), and this is nearly impossible to do in PHP. The main reason : the memory footprint of any typical PHP program is too high (due to the lack of garbage collection or to memory leaks). I’m still amazed that PHP 5.2.6 just fixed a “huge memory usage” bug in string concatenations (!!!).

You can also add many less generic problems (ie : the fact that certain errors cannot be catched), but the list would be too long for this post.

Looking for an alternative

I spent a few days looking for an alternative that would :

  • be as productive as PHP (or better) - forget Java, or any other compiled languages like D
  • have a nice classical OO syntax - forget erlang & other
  • have a large user base and a nice framework
  • and of course cool

The two main languages that looked interesting were Ruby and Python (no tcl, sorry, anyone remember struggling with Vignette ?).

  • productivity: Python and Ruby look both good. Ruby might have a slight edge if you’re in the pure OO camp
  • OO syntax : Ruby IMHO is a clear winner : a nice, elegant pure OO syntax. Python is lacking real OO functions (it reminds me of PHP4), and I really don’t like the indentation-based syntax (I always have problems finding when a function finishes)
  • user base and framework : both languages have a large user base, and nice frameworks (ie Django for Python or Rails for Ruby)
  • coolness : Ruby wins easily this one (I really love the OO model, and really dislike the indentation-based syntax of Python)

The decision would have been pretty easy without Ruby’s little problem : performance. Where Python is pretty fast for a scripting language, Ruby 1.8 (aka MRI) really sucks (Ruby 1.8 is 2 to 3 times slower than PHP). Any twitter user has noticed that scaling a ruby website is not an easy task.
Yet there is a huge amount of work done by the community to address this problem : the recently-released Ruby 1.9 is nearly as fast as PHP, and a handful of alternative VM (JRuby, Rubinius, …) are getting better and faster every day. I bet that, in 2009, Ruby will be on par with Python.

You can expect to see some Ruby or Rails articles in the coming month…

Posted in PHP, Ruby

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.