'if x==4' was written as 'x[4]'
'if x>2 && x'if x>=2 && xEtc.
It was very easy to read and write... at least for me.
31–40 of 96 posts
'if x==4' was written as 'x[4]'
'if x>2 && x'if x>=2 && xEtc.
It was very easy to read and write... at least for me.
Ha, 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)"
Swift has it. I'm sure a few languages must have it. if (2...4).contains(x)
> (x What? no it doesn't!
> (5 It's already very obvious that one can take 5 < x < 10 and split it into 5 < x && x < 10 right off the bat. Loads of examples of that out there.
I use this. I can read lines reading left to right with only very quickly now, because of the visualization of a numberline in my head. Any other arrangement, and I have to slow down to my old, normal processing, and reason very carefully about the code, lest a subtle bug slip by. For similar reasons, I find this notation helps me prevent errors, because they become visually detectable.
5
you can use the number line visualization very quickly, but it breaks down if the code is in fact x
It means the same thing. But it's not obvious.So the number line analogy is incomplete and even when there is only </<= you still need careful reasoning.
Earlier quoted context omitted.
is there really a naming distinction between ‘>’ and ‘ the ‘greater’ than sign? Interesting if so! I always assumed it was context dependent (i.e x < 10 could be said 10 is greater than x, so it’s still acting as a greater than sign - but I see why I’m probably wrong here). I was interested in seeing an arguement like another poster made, where notation be like x = [0,1] might be proposed.
If you read Pull the lever when x aloud, you must read it as "Pull the lever when x is less than zero." Thus, " " is "greater than", for that reason specifically. Also, Unicode calls it U+003C LESS-THAN SIGN and U+003E GREATER-THAN SIGN. At least, that's the terms that the article is using, and I think there's sufficient context to identify that, and go along w/ it.
Earlier quoted context omitted.
Where is the article using a >, aside from examples of what it is advocating against?
is there really a naming distinction between ‘>’ and ‘ the ‘greater’ than sign? Interesting if so! I always assumed it was context dependent (i.e x < 10 could be said 10 is greater than x, so it’s still acting as a greater than sign - but I see why I’m probably wrong here). I was interested in seeing an arguement like another poster made, where notation be like x = [0,1] might be proposed.
Earlier quoted context omitted.
That... has nothing to do with nemo1618's wish. The python statement 2 4.
Nobody would ever purposefully write 2 4 … it's a bug. Maybe if the bounds on the example were variable. 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.
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 (Contrast Ruby, which offers almost every convenience in ranges, including literal notations, that you could ask for.
x.between?(6,9)
or very explicitly x.between?(5.0.next_float, 10.0.prev_float)I really think this is just bikeshedding over style. If we were optimizing for readability and predictability, we'd standardize on the most commonly used format. ``if (x > 5 && x Putting a rule that variables should always be on the left hand side of a comparison also gives you only 2 ways to write any conditional, so it's just as good as getting rid of ``>``. It also has the advantage of being by far the most widesp…
Are you serious? These are just 2 neat ways for expressing common boundaries conditions. The point is it's more readable instead of using '>'. That is all.
Ha, 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.