Ruby Paper Cuts

I love programming in Ruby and (especially) the Ruby on Rails framework. That said, they both have some oddities and conventions that leave me scratching my head, making me wonder what such smart people are thinking, and questioning the very nature of reality…you know, much like an episode of a Disney+ or CW show.

Continue reading “Ruby Paper Cuts”

Understanding unless in Ruby

I don’t know about you, but Ruby’s unless has always been kind of hard for me to grok, but I’m realizing that’s because I’ve never seen a great use of it, esp. one that made me go, “Oh wow – yeah I’d definitely use unless there vs. an if statement or something else.”

However, the deeper I’ve gotten into Ruby the more I’ve noticed one place where unless really shines – guard statements. Consider the following:

def update_book_title(book, title)
  return unless book.present?
 
  book.update(title: title)
end

Now there’s a place I would definitely use unless over other control flow constructs. It’s succinct, easy to understand, and honestly a pleasure to both write and read.

Nice job Ruby! 🔴💎

Legacy Ruby Code

A programmer programmed in PHP. The code she wrote was legacy code as soon as her commits entered the git repo, and they provided gainful employment for many other programmers for years to come.

Another programmer programmed in Ruby. His code was also legacy code from its inception, yet his code prompted several developers to pivot to management careers and a complete application rewrite in Go.

Upon hearing of this, a wise programmer remarked:

How much better it is to work with Java written in PHP than Java written in Ruby!