Before you can use Ruby on Rails you have to learn Ruby so I've spent part of the night trying to learn Ruby. What a fascinating language, and it's amazing how cool it is from just a syntactical perspective alone. Here's a simple example with an object in Ruby and a comparison with the equivalent in Python:
class PointKeeper
def initialize(name, count)
@name = name
@points = count
end
def Name
@name
end
def Points
@points
end
def Points=(points)
@points = points
end
end
pk = PointKeeper.new("MikeT", 4000)
print pk.Name + "t" + pk.Points.to_s + "n"
pk.Points = 5000
print pk.Name + "t" + pk.Points.to_s + "n"
Python version:
class PointKeeper:
def __init__(self, name, points):
self.name = name
self.points = points
pk = PointKeeper("MikeT", 4000)
print pk.name + "t" + str(pk.points) + "n"
pk.points = 5000
print pk.name + "t" + str(pk.points) + "n"
Now what's the big deal about the difference? Seems like the Python version is simpler and thus more elegant, right? Wrong. I have a soft spot for Python given that it was one of the first languages I studied, and I have even used it at work to get stuff done, but it is a bit lacking in some respects compared to Ruby and this happens to be one of them. Python doesn't allow you to restrict object member variables and that is a problem because it makes it harder to achieve proper encapsulation. Who knows what variables should be accessed and which shouldn't be accessed? That of course requires more documentation, which requires more reading, which ultimately means less time spent working on the actual code.
For a while I was resistant to learning Ruby, but now that Rails has come along, I have to learn it in order to feel like a proper geek. It's amazing how cool this language really is. I really do wish that I had been forced to get familiar with it a while ago.


Leave a comment