Hacker News new | ask | show | jobs
by ldubinets 4666 days ago
Ruby is neat! Except for this part:

    return nil unless other.is_a?(self.class)
5 comments

I'm a fan of:

  while true do
    puts 'lol'
  end unless true
but seriously, I like postconditions. they're also handy for encoding intent, if you have a pattern of the left-hand-side being the primary logic flow.
Is it a statement-modifier 'unless' that bothers you? `return ... unless ...` is kind of idiomatic way of returning early in the function. You get used to this shortcut ridiculously fast.
Wait, why? Try to read it aloud and it will make sense. I've seen lot's of hard and confusing syntax but this is not one of them. And I'm not a Ruby developer.
Post conditions are odd if you're not used to them, but once you start to mentally allow for them, they're really quite nice.
Ah, seems everybody misunderstood my comment (not hard to see why). It's not the post conditions that bother me, its the dynamic typing! In my opinion, ruby's duck typing really only works until you actually need it.
this can also be written as

    other.is_a?(self.class) || return
if you prefer that.