Skip navigation

Monthly Archives: November 2011

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?