Day 12 – When repeating yourself is the preferred method is repeating yourself.
Today’s topic is recursion – iteratively calling a function numerous times with a single minor change. On face value, it sounds like something computer technology should help us avoid. In addition, it seems to directly conflict the Ruby on Rails mantra Don’t Repeat Yourself. Though recursion is inherently resource intensive (repeating yourself over and over is often tiring), the prime benefit seems to be highly concise code without resorting to loops or iterators. Yeah, this is alpha-geek stuff.
All snarkiness aside, Slagell is positioning recursion as a tool to help clearly define the necessary action at the smallest level and using recusion to focus.
I should probably read this chapter again.
This post documents my journey through Sam’s Teach Yourself Ruby in 21 days. I’ll be joining Al Abut in his effort to learn Ruby and blog along the way.
No real comment, but I just wanted to thank you for writing about your ruby learning process. I’m following along and do appreciate the effort you’re making to document it. It motivates me to read the chapters when sometimes I don’t want to.
Thanks!