Hacker News new | past | comments | ask | show | jobs | submit login

I have read it, and Dijkstra is a good call to authority, but I don't agree.

His opening sentence is instructive: using the 'pernicious three dots', everything is totally clear: with an ellipsis, it's impossible to understand anything other than a closed interval.

It's primary school mathematics that 2 <= x <= 12, i.e. the interval mathematically written [2,12] (or 2,...,12), contains 11 integers. A programmer who doesn't understand that is in a world of trouble as half-open intervals won't stop the inevitable rain of off-by-one errors.

A programmer who actually calculates the size of a list in the way that Dijkstra suggests (specifically, by calculating b-a) is also perhaps acting questionably. Dijkstra's argument here might make more sense when correctly framed in 1982.

As an aside, if Dijkstra would agree to use a fully-closed interval, his suggested advantage of 0-indexing is eliminated and he would presumably then prefer 1-indexing.




That's not the entirety of the argument. There's the natural number stuff, as well.

Also, b-a is appealing because simplicity is a good indicator you're on the right track, and part of the definition of elegance.




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: