Skip to content

Python vs Ruby

I know I said I was taking a break from tech stuff and I know that many more people have discussed this topic much more eloquently than I. But someone on IRC posted this link; to an online Ruby tutor. I clicked, mainly out of curiousity, and went through the entire thing. I’ve been reluctant to give Ruby a fair shake because of my Python bias, but I think after my self-imposed tech moratorium, I’ll try it.

This morning I did a test between Python and Ruby. It is, admittedly, contrived.


#!/usr/bin/env python

class Fucker(object):

def __init__(self, string1, string2):

self.string1 = string1

self.string2 = string2

def fuck():

print self.string1 + ” fucked ” + self.string2

# alternately:

# print “%s fucked %s” % (self.string1, self.string2)

>>> f = Fucker(”Sid”, “Nancy”)
>>> f.fuck()
“Sid fucked Nancy”


#!/usr/bin/env ruby

class Fucker

def initialize(string1, string2)

@string1 = string1

@string2 = string2

end

def fuck

puts “#{@string1} fucked #{@string2}”

end

end
>>> f = Fucker.new(”Sid”, “Nancy”)
>>> f.fuck
“Sid fucked Nancy”

The two examples do exactly the same thing in very similar ways, but each language’s approach has certain appeal. I really really dislike Ruby’s use of end statements. Python’s required indentation [it's a feature!!] makes them unnecessary and thus makes the Python code shorter. On the other hand, I’ve always despised Python’s class initialisation method. While it’s better than having explicit getters and setters, the self thing always bothered me. I think the Ruby way is superior in this regard. Overall I prefer Python because it doesn’t use weird looking syntax like #{variable}, but I realise that’s Ruby’s Perl influence shining through. In the end, I honestly hope I do like Ruby. I think there’s room for it alongside Python in my head.

Post a Comment

You must be logged in to post a comment.