Apples, Oranges, and Culture

Apples and Oranges

A number of people wrote irate comments after my article about Ruby’s eBay API beating PHP hands down. They complained that I was comparing apples to oranges, because the Ruby library I was using was nicely crafted, whereas the PHP one was some crufty crud that just happened to be one of the first things you find when you go to developer.ebay.com.

First things first, let’s look at some better PHP code:

require_once 'EbatNs/EbatNs_ServiceProxy.php';
require_once 'EbatNs/EbatNs_Logger.php';
require_once 'EbatNs/GetItemRequestType.php';
require_once 'EbatNs/ItemType.php';

$session = new EbatNs_Session('config/amd.ebay.config.php');

$cs = new EbatNs_ServiceProxy($session);
$cs->setHandler('ItemType', 'handleItem');

$req = new GetItemRequestType();
$req->setItemID(5652664344);
$req->setDetailLevel($Facet_DetailLevelCodeType->ReturnAll);

$res = $cs->GetItem($req);
echo "<pre>";
if ($res->getAck() != $Facet_AckCodeType->Success) {
echo "we got a failure<br>";
foreach ($res->getErrors() as $error)
{
    echo "#" . $error->getErrorCode() . " " .
    htmlentities($error->getShortMessage()) . "/" .
    htmlentities($error->getLongMessage()) . "<br>";
}
} else {
//#type $item ItemType
$item = $res->getItem();
echo "ShippingTerms : " . $item->getShippingTerms() . "<br>";

print_r($item);
}

versus our Ruby code:

require 'rubygems'
require 'ebay'

include Ebay
include Ebay::Types

require 'localconfig'

ebay = Ebay::Api.new

begin
  response = ebay.get_item(:item_id => '110011765264')
  puts "ShippingTerms : #{response.items.shipping_terms}"
rescue Ebay::RequestError => e
  e.errors.each do |error|
    puts error.long_message
  end
end

So, they get closer with that, but the Ruby code is still clearer and more concise. If you look around at some PHP5 based examples, they start to be decent as well. As one tutorial writes:

These components combine to create a kick-ass tool that PHP 4 can’t replicate without lots of work, if at all.

Leaving aside the fact that a lot of people are still more or less stuck on 4, I think there is something more important to be learned.

Culture

There are a lot of really smart people who work with, and on PHP. As much as anyone grumbles about any language, it’s not easy to create one, let alone create one and make it as popular as PHP. However, as I’ve said elsewhere, one of the things that made PHP so successful was its ability to “scale down”. Part of its value is that it made it much easier for more people with less advanced skills to create things. That is, without doubt, a very fine accomplishment, but it does bring some baggage with it. Namely, that there are a great deal of PHP programmers who do not write very nice looking code. Going back to the eBay example, the code featured on their site is not very tasteful, if you ask me. My bet is that in Ruby-land, that sort of code would not be displayed very prominently. Why? It’s not the computer, it’s the culture that has grown up around the different languages.

Computers do not care one bit about programming languages. They interpret bits and bytes, whatever language is used, so it’s really all the same to them. Programming languages matter only to people, because they are the tool we use to comunicate our instructions to machines. This means that they are a very human thing in some ways, and that human aspects of them matter a great deal.

What this means is that it’s important not only to design a cool language, but to create a good culture around it. To take aim at something nearer and dearer to me than PHP, one of the major failings of the Tk toolkit was that there was little to no attempt to create a good design culture around it. Anyone who was using Linux 10 years ago will surely remember some of the truly horrible things that were created with Tk. Why? Tcl and Tk made creating a GUI an order of magnitude easier than with C and Motif (or whatever windows used at the time), and turned them loose with no instructions or idea whatsoever of how to go about creating a good, intuitive user friendly one – the Tk docs themselves make little to no mention of usability, and even the best Tcl/Tk books pay almost no attention, even in the form of recommended reading, to what to make with this beautiful tool whose hows are explained very well. The unixy community also wasn’t exactly a wellspring of creativity and critique in terms of good guis, either.

So, yes, I know that it’s possible to write good, clever, readable PHP (or Perl, or FORTRAN) code, and bad Ruby (or Tcl, or Python, or whatever) code. However, I’m also convinced that culture counts. People who value clean, beautiful code gravitate to cultures, and, where possible, workplaces where they find other like-minded people. Others, not having as many options, find themselves staring at 13000-line PHP files that grow malignantly by dint of cut and paste, wondering how to tame that which others have wrought!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s