Same shit, different language?

I like PHP. I also like Ruby on Rails. So, it naturally follows that I would also like Rails ported to PHP, right? Well, maybe — but I’m not sure I’ve seen a good example of this.1

Here’s a totally made-up example (in Ruby):

class RockStar < ActiveRecord::Base
has_many :roadies
has_many :groupies
end

Sure, it doesn’t do much, but most of the interesting model behavior comes automatically (that being the whole point of Rails). So, here’s a fairly literal translation into PHP:

class RockStar extends ActiveRecord::Base {
has_many('roadies');
has_many('groupies');
}

Literal as in, I didn’t bother making it valid PHP; I just replaced the basic syntax elements with the PHP equivalents.2 Ignoring the rather basic issue of namespaces, the interesting problem is that I called an inherited function in the middle of declaring the child class — PHP doesn’t allow this.

Here’s the thing; different languages are different. That doesn’t mean one has to be better than the other, it just means they’re different. The problem is most of the ports I’ve come across are losing something in translation.

The elegance of Rails3 is in the code you don’t write. There’s not a single line of CRUD up there; the base class sorts all that out for me. Sure, you could create some valid PHP out of that, but quite often that leads to Rails crammed into PHP syntax, instead of a real PHP equivalent to Rails.

Don’t get me wrong — has_many works well in Rails, but the next time I find a new `ActiveRecord` in PHP, I’d rather see some elegant PHP instead of the closest PHP someone could think of to some elegant Ruby.

  1. I’m intentionally not naming names here; but some examples I’ve seen are much closer than others. []
  2. I also didn’t write a more complex has_many relation with a less obvious PHP equivalent, but that’s beside the point. []
  3. …or in any system, depending on who you ask []

Rants | Permalink | No Comments

On second thought…

Feed URLs are (hopefully) getting redirected, but entry URLs are not; I just modified the permalink fragment of all the old posts en masse, so the old and new should be the same URL.

Site Info | Permalink | No Comments

If you can read this…

…I’ve switched (server-side) blog software. Old URLs should be redirected to new ones, where appropriate.1

Why the switch? Ultimately it comes down to language preferences. There were parts of this site that I never bothered to get working, and converting my ideas into Movable Type templates just didn’t appeal to me.2 One such example is the archives — MT just listed posts there with little structure. Sure, WP doesn’t even generate anything there by default, so I’m building it from scratch instead of fixing a template I don’t like, but I just find WordPress easier.

My natural distaste for object-based Perl meant that in Movable Type I tended to avoid mucking around “under the hood”, so I was largely stuck with the tags and features it ships with or that plug-in authors had made. WordPress is PHP, so if something doesn’t work how I want, there’s a much lower barrier to patch it via a plug-in. This isn’t a political statement of some sort, where I turn to WordPress because it’s free software; for that matter, I’m not even saying that WordPress is better software.3

So, at last count, I have two site-specific plug-ins, two others I’ve downloaded and installed, and obviously a site-specific theme. Oh, and I went through all my old posts and converted between text-markup schemes.4 As usual, be sure to use the non-functional feedback link above to let me know what stuff is more broken now than it was before.

  1. At least, they will be, once I throw the switch that shows this post, and the new blog, to the world []
  2. that being why they were left un-working []
  3. Better for me, perhaps… []
  4. I’d started off using Textile, but now I’m using Markdown, and it just seemed silly to be running with two different ones and a plug-in to make that possible. []

Site Info | Permalink | No Comments