Simply The Best...Why Ruby wins the happy programmer test every time

Disclaimer: There may be better implementations in either language, but I am a relative newbie to both Ruby and Objective-J (similar in many ways to Objective-C), so I believe this to be a fair test.

Ruby makes happy programmers. You can avoid hackish routines like the Obj-J example:

var conversationAsString = "";

for(var i=0; i < [aMessages count]; i++) {
    m = aMessages[i];
    var messageTime = [CPDate dateWithTimeIntervalSinceNow:0];
    var messageBody = [[m firstChildWithName:@"body"] text];

    var messageAsString = "[" + messageTime + "] " + [m from] + ": " + messageBody;

    conversationAsString += messageAsString + "\n";
}

CPLog.info(conversationAsString);

by following the ruby way:

puts messages.map { |m| "[#{Time.now}] #{m.from}: #{m.body.value}" }.join("\n")

Nice, concise and self explanatory. Point proven.

Ben Langfeld 18 August 2010 Manchester, England