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 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.
Don't use the greater-than sign in programming (2016)
11–20 of 96 posts
Re: Don't use the greater-than sign in programming (2016)
#12Counter-point: When checking if a variable is greater than a constant, using the less than is very confusing since we read left to right.
if(x > LIMIT) {
Read "If x exceeds LIMIT, then"
The opposite reads like "If the LIMIT is less than x", which sounds strange and emphasizes the wrong thing, implying LIMIT changed, not x.
Re: Don't use the greater-than sign in programming (2016)
#13Ha, I've been using this trick for a while, though I wouldn't go so far as to say "don't use the greater-than-sign." Honestly I just wish languages had a cleaner way to write "x is within this range," e.g. "if x in [2,4)"
In Python we have if 2 <= x < 4.
Re: Don't use the greater-than sign in programming (2016)
#14Ha, I've been using this trick for a while, though I wouldn't go so far as to say "don't use the greater-than-sign." Honestly I just wish languages had a cleaner way to write "x is within this range," e.g. "if x in [2,4)"
if (2...4).contains(x)Re: Don't use the greater-than sign in programming (2016)
#15Ha, I've been using this trick for a while, though I wouldn't go so far as to say "don't use the greater-than-sign." Honestly I just wish languages had a cleaner way to write "x is within this range," e.g. "if x in [2,4)"
Re: Don't use the greater-than sign in programming (2016)
#16as 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 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.
In python you can just do 5 < x < 10
5 < x && x < 10 is the attempt to replicate this in other languages but falls a bit short
Re: Don't use the greater-than sign in programming (2016)
#17..but the greater than sign is still being used?
Re: Don't use the greater-than sign in programming (2016)
#18This all looks good to me until I'm unwrapping an optional and checking it's length in Swift, which normally looks like: guard let array = obj.someArray, array.count > 0 else { throw SomeError }
Re: Don't use the greater-than sign in programming (2016)
#19Re: Don't use the greater-than sign in programming (2016)
#20Earlier quoted context omitted.
In Python we have if 2 <= x < 4.
That... has nothing to do with nemo1618's wish. The python statement 2 4.
But the point of being able to collapse a I don't think I've ever seen it actually used for anything else, and I would in advocate against it, in code review.