Hacker News new | ask | show | jobs
by ascar 2751 days ago
But you have to know if the boundaries are inclusive or exclusive, which leaves you with four different possibilities. You and everyone who reads your code needs to know this.

Ruby is my main language and I would have to look up the boundaries of this function.

Your "explicit" statement is also so much worse than using `x < 5.0` or `x <= 5.0`, depending on what you want. This is terrible advice imho.

1 comments

I am lately enamored of Ruby because it helps me write code that makes me happy. Calling methods on numbers is one of those things that does.

Anyway, ranges are another way of expressing the concepts in Ruby:

  (5.0.next_float..10.0.prev_float).include?(x)
or

  (5.0.next_float...10).include?(x)
if I don't mean

  (5..10).include?(x)
None of which is advice. Just remarks about why I am enamored of Ruby, lately. If I wanted to write C, I'd use Go.