On Thursday, we started a deep dive into Ruby. There’s so much about this language to love.
- It encourages a functional style of programming. It’s a lot more about telling Ruby what to do rather than how to do it.
An example of this is the heavy use of methods like
inject. In a language like Java, you tell the computer how to do something. For example, you might say, “given an array, create another array. For every element in the first array, if it is less than four, copy it into the new array”. This might be 4 to 7 lines of code, most of which is describing how to do something. With detailed instructions like this, it’s easy to lose sight the big picture.
But in Ruby, we’d simply say:
This reads almost like English. If I were to read this aloud, I’d say, “To get a list of NYC teams, from the list of all teams, select each team where the team starts with NY”. It’s not so clever to be hard read, and it’s not so verbose to get bogged down in the details.
Overheard at @bitmakerlabs: If Ruby were a woman, I’d probably divorce my wife.
- Punctuation is optional. This is probably the most surprising aspect of Ruby to me, and I’m not quite sure how I feel about it.
- Everything is object oriented. In Ruby, even the mathematical operators are methods on an object:
I’m looking forward to reading more about blocks and lambdas in Ruby, and more about object oriented design. This weekend, we’ll be reading Sandi Metz’s book Practical Object-Oriented Design in Ruby.