Hacker News new | ask | show | jobs
by patates 3794 days ago
why

    return false unless a.bytesize == b.bytesize
instead of

    if a.bytesize != b.bytesize
        return false
disclaimer: never programmed in ruby
1 comments

It's idiomatic ruby.

First as the conditional only has one statment it's preferred to write it in its shorthand way, so instead of

  if a.bytesize != b.bytesize
    return false
We start by writing

  return false if a.bytesize != b.bytesize
And then unless is the negated conditional, so we rewrite it as

  return false unless a.bytesize == b.bytesize
Which some peolpe (myself included) consider easier to read, the 'unless' is easier to note (more chars) than the '!='.