Hacker News new | ask | show | jobs
by thaumasiotes 2751 days ago
> I don't think I've ever seen it actually used for anything else, and I would in advocate against it, in code review.

Yes, this would be a terrible practice. But that's what Python offers. The desire to express that a variable's value lies within a range is very common, and is presumably the reason for Python's bad choice. But that doesn't make Python's syntax a good response to the desire. The syntax expresses a conceptual mess; you're relying on people only using a tiny subset of what's there.

Contrast lisp, where you actually can express the concept of a range, as (< lowBound variable highBound). Unfortunately, that won't allow you to mix soft bounds with strict bounds. But it's vastly better than Python's approach.

Contrast Ruby, which offers almost every convenience in ranges, including literal notations, that you could ask for.