Hacker News new | ask | show | jobs
by nimbius 2751 days ago
as a CS major im sure this has academic value. as someone who is just learning python outside of a trade job as an engine mechanic, this idea makes me want to glass someone and im not sure why.

(5 < x && x < 10)

if we're talking about X, whats wrong with defining the parameters of its constraints in terms of X instead of dancing around the numbers? 5 < X makes it sound like im setting constraints on the number 5.

2 comments

In python you can just do 5 < x < 10
which is also the proper way you would read in any scientific paper, and very easy to read imho.

5 < x && x < 10 is the attempt to replicate this in other languages but falls a bit short

> 5 < x && x < 10 is the attempt to replicate this in other languages but falls a bit short

On the contrary, it's Python that added the shorthand, mathematical-looking notation because the longer "desugared" form wasn't great.

That's not the contrary, it is exactly what the other comment said ;). "To fall short" == "to not be great"
Actually this has zero academic value. The entire point is as a working programmer to compensate for ambiguous pitfalls in a language.

You don't need this specific trick in python (as others have pointed out, `5 < x < 10` works), but in general python holds to a similar philosophy of using standardized idioms to make reading code easier. It's called "being pythonic".