Skip navigation

Ruby’s syntax is often called “ugly”. Indeed it has more syntactic sugar than Python. One example is that ruby has a special syntax within strings to expand variables. Yes it’s a syntax “hack” and it’s not strictly necessary, but take a look at this.

Say you want to make a message that prints out 2 numbers. In Ruby, it can be done like this:

puts "The numbers are #{foo} and #{bar}."

In Python, you have to do it like one of these:

print("The numbers are {} and {}.".format(str(foo), str(bar)))
print("The numbers are " + str(foo) + " and " + str(bar) + ".")

Which language is more ugly in the end?

Advertisements

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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: