Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Let's say you want to find accommodation from day x to y, would you rather have [x, y + 1) as the interval in the code?

In other words, I think the blog post lists problems the author has had and in those cases an open-closed interval would have worked better. But one could come up with an opposite case, would that be equally true?



Of course if datetimes are involved, you need to go up midnight. So you’re back to +1 and a half-open range


IIRC (bit rusty now) python makes you do exactly [x, y + 1) in code and it pisses me off which is why I did my own trivial end-is-included range for loops.


Otherwise would result in surprises like range(10) giving 11 values, violating convention. I admit I usually have to pause to remember whether it's inclusive of the upper bound or not.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: