While having a chat with Keith about the meaning of the term 'syntactic sugar', he pointed out that my examples weren't strictly that. The methods times and each for numbers and arrays aren't technically syntax of Ruby, just things you can do with Ruby.

A more accurate example of 'syntactic sugar' would be something like this:

# this:
blah = Blah.new({:arg1 => 'something', :p => 'something else'})
# could be written like this:
blah = Blah.new :arg1 => 'something', :p => 'something else'



Braces and parenthesis are generally optional for method arguments and are normally only used to resolve which argument belongs to which method when passing methods as arguments to other methods. The syntax is so much cleaner when not having to include operators where their use is unnecessary.

2 Comments

Markyg
1:40pm, 27 July 2008

Hey hoadster.. Good work on making the switch! I'm sure this now means your rewriting your blog?

M

Nathan
8:09pm, 30 July 2008

Yep. It will most likely become a Camping app :-P

Post a comment

Name
Link
Email (not shown, used for avatar)
Type this into the box: