Answers.Body: <p>I think the typical order has more to do with grammatical conventions actually.</p>
  
  <blockquote>
    <p>Joe is heavier than Bob</p>
  </blockquote>
  
  <p>Joe is the subject, the one we're talking about; Bob is just an object we compare against.</p>
  
  <blockquote>
    <p>Joe weighs more than 90kg</p>
  </blockquote>
  
  <p>vs.</p>
  
  <blockquote>
    <p>90kg is less than Joe weighs</p>
  </blockquote>
  
  <p>The second one is a very odd sentence.</p>
  
  <blockquote>
    <p>[subject] [verb] [object]</p>
  </blockquote>
  
  <pre><code>[variable] [operator] [constant]
  </code></pre>
  
  <p>This would be a pretty normal construction, such as:</p>
  
  <pre><code>x &lt; 0
  </code></pre>
  
  <p>or</p>
  
  <pre><code>x &gt; 0
  </code></pre>
  
  <p>but odd would be:</p>
  
  <pre><code>0 &lt; x
  </code></pre>
  
  <p>Because the value of 0 isn't changing. Zero is not the "subject" of what we're doing. <code>x</code> is the subject, the variable, the interesting thing.</p>
  
  <p>So what if we're comparing two variables?</p>
  
  <pre><code>x &lt; y
  </code></pre>
  
  <p>It's possible both of these are new values to us, but intuitively, this code feels like it's more about <code>x</code> than about <code>y</code>. Consider:</p>
  
  <pre><code>if x &lt; y: do something
  if x &gt; z: do something
  </code></pre>
  
  <p>Now, clearly, <code>x</code> is our main subject, running against various other variables to see if something needs to be done.</p>
  
  <hr>
  
  <p>So, my impression is that any preference for <code>&lt;</code> over <code>&gt;</code> or otherwise pales in comparison for the preference to put the "subject" of the comparison on the left.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-15T01:14:39.580Z
Answers.Text: While your statement is true for many written and spoken languages, I think that programming has different needs. Also, some languages reverse word order, so 90kg < Joe would be normal. When I am scanning code, I like to locate the constants. I can guess that the other part is a variable. Constants dictate what will happen, variables are just along for the ride.
Answers.UserDisplayName: Scott Rowe
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-09T09:17:03.677Z
Answers.LastActivityDate: 2019-12-09T09:17:03.677Z
Answers.UserDisplayName: ObscureOwl
Answers.Body: <p>Similar to Buffy, I suspect that which use is more natural depends on the framing of the problem.</p>
  
  <pre><code>while (countdown &gt; 0)
  </code></pre>
  
  <p>makes perfect sense.  By contrast,</p>
  
  <pre><code>while (0 &lt; countdown)
  </code></pre>
  
  <p>feels less intuitive, if only because there is a bias towards leaving the variable on the left side of an expression.</p>
  
  <p>I think that the key (and this is what I would communicate to my students) is to make whatever choices you make carefully reflect the mental model of the problem.  This should create the clearest code, and produce the fewest errors.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-15T00:59:34.773Z
Answers.Text: I guess I tend to use "Yoda Comparisons" because I was trying to avoid the C error of using = when I meant ==. If I try to assign x to zero, the compiler will not let me. Also, constants tend to be shorter than variables, especially in an OO context. So several comparison lines in succession would all be something like "0 < abcdef.ghe.jkmnop.qrstu(wxyz)"  and it would be easy to read the thing compared against instead of having to hunt for it at the far right of the lines. So, to me "while (0 < whatever)" is good. I know the big long string is the variable part, I want to know the constant.
Answers.UserDisplayName: Scott Rowe
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-07T02:15:03.890Z
Answers.LastActivityDate: 2019-12-07T02:15:03.890Z
Answers.UserDisplayName: Ben I.
Answers.Body: <p>First, I doubt that there are any such statistics because the effect would seem to be so small as to be overwhelmed by other, more common, things. You could, perhaps, create an instrument (as in a compiler) to look for such things and look for effects in, say, unit tests of the code. But that implies that a lot of things come together. </p>
  
  <p>But, I would also suggest that your basic understanding of human psychology may be naive. It could well be that there are people who actually think more effectively in "greater than" mode. As a mathematician, I've often been confused by left-right and by east-west, especially when they all show up in the same context. But it is, I'm pretty sure, because, I look at things with a "frameless" view. What is left and what is right depends on where I think of myself as viewing from. </p>
  
  <p>Also, some times it is just more "natural" to express things with greater than, as in "error > 0.05". </p>
  
  <p>So, I think a teaching "rubric" that punished students for using one form over the other would be misplaced. It would, in some situations, lead the user to perform an extra step in their thinking, and that, alone, could lead to an error. </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-15T01:08:09.980Z
Answers.Text: There has been research on whether using > vs >= leads to more or fewer errors. (I think the upshot is that people make fewer errors when they use one method consistently instead of trying to be clever.) We often must use "open intervals" where the starting point is an absolute number, like >= 0, and the upper bound is a < comparison, like: 4.9999 is OK but 5.0000 is right out. I used to teach that routinely, from the section of the textbook on Range Comparisons. Not sure anyone really got it, but to me it made sense. Of course, you could say: IF 5.0 NOT <= x THEN... DeMorgan and all that.
Answers.UserDisplayName: Scott Rowe
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-07T01:20:32.263Z
Answers.LastActivityDate: 2019-12-07T01:20:32.263Z
Answers.UserDisplayName: Buffy
Body: <p>I was teach on mathematics that on real line small numbers are on left and big numbers are on right. Therefore, I think the comparison 0&lt;1 is more natural than 1>0, and in general, x less than y is easier to read than y greater than x. Is there any statistics if there are less bugs on programs that uses only less than comparisons than programs uses greater than comparisons or both?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-12-05T19:24:42.003Z
Comments.Text: This isn't exactly a question about how to teach or about best educational practice.  With a bit of modification, though, it could easily fit in this forum. (Plus I have an answer I would love to give if it could be made to fit)
Comments.UserDisplayName: Ben I.
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-12-07T08:16:49.037Z
Comments.Text: @BenI A little modification. **If** we can show that it has high probability of being true, then it should inform teaching.
Comments.UserDisplayName: ctrl-alt-delor
Tags: <best-practice>
Title: Is less than comparison more natural than greater than comparison?
ThreadText: # Is less than comparison more natural than greater than comparison?
  
  (Asked by: username_0 on 2019-12-05)
  
  I was teach on mathematics that on real line small numbers are on left and big numbers are on right. Therefore, I think the comparison 0<1 is more natural than 1>0, and in general, x less than y is easier to read than y greater than x. Is there any statistics if there are less bugs on programs that uses only less than comparisons than programs uses greater than comparisons or both?
  
  **Tags:** best-practice
  
  > **Comments:**
  > **username_1**: This isn't exactly a question about how to teach or about best educational practice.  With a bit of modification, though, it could easily fit in this forum. (Plus I have an answer I would love to give if it could be made to fit)  
  > **username_2**: @BenI A little modification. **If** we can show that it has high probability of being true, then it should inform teaching.  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_3 on 2019-12-09. Score: 5
  
  I think the typical order has more to do with grammatical conventions actually.
  
  > Joe is heavier than Bob
  
  Joe is the subject, the one we're talking about; Bob is just an object we compare against.
  
  > Joe weighs more than 90kg
  
  vs.
  
  > 90kg is less than Joe weighs
  
  The second one is a very odd sentence.
  
  > [subject] [verb] [object]
  
  ```
  [variable] [operator] [constant]
  
  ```
  
  This would be a pretty normal construction, such as:
  
  ```
  x < 0
  
  ```
  
  or
  
  ```
  x > 0
  
  ```
  
  but odd would be:
  
  ```
  0 < x
  
  ```
  
  Because the value of 0 isn't changing. Zero is not the "subject" of what we're doing. `x` is the subject, the variable, the interesting thing.
  
  So what if we're comparing two variables?
  
  ```
  x < y
  
  ```
  
  It's possible both of these are new values to us, but intuitively, this code feels like it's more about `x` than about `y`. Consider:
  
  ```
  if x < y: do something
  if x > z: do something
  
  ```
  
  Now, clearly, `x` is our main subject, running against various other variables to see if something needs to be done.
  
  ---
  
  So, my impression is that any preference for `<` over `>` or otherwise pales in comparison for the preference to put the "subject" of the comparison on the left.
  
  > **Comments:**
  > **username_4**: While your statement is true for many written and spoken languages, I think that programming has different needs. Also, some languages reverse word order, so 90kg < Joe would be normal. When I am scanning code, I like to locate the constants. I can guess that the other part is a variable. Constants dictate what will happen, variables are just along for the ride.  
  
  ---
  
  ### Answer by username_1 on 2019-12-07. Score: 3
  
  Similar to username_5, I suspect that which use is more natural depends on the framing of the problem.
  
  ```
  while (countdown > 0)
  
  ```
  
  makes perfect sense. By contrast,
  
  ```
  while (0 < countdown)
  
  ```
  
  feels less intuitive, if only because there is a bias towards leaving the variable on the left side of an expression.
  
  I think that the key (and this is what I would communicate to my students) is to make whatever choices you make carefully reflect the mental model of the problem. This should create the clearest code, and produce the fewest errors.
  
  > **Comments:**
  > **username_4**: I guess I tend to use "Yoda Comparisons" because I was trying to avoid the C error of using = when I meant ==. If I try to assign x to zero, the compiler will not let me. Also, constants tend to be shorter than variables, especially in an OO context. So several comparison lines in succession would all be something like "0 < abcdef.ghe.jkmnop.qrstu(wxyz)"  and it would be easy to read the thing compared against instead of having to hunt for it at the far right of the lines. So, to me "while (0 < whatever)" is good. I know the big long string is the variable part, I want to know the constant.  
  
  ---
  
  ### Answer by username_5 on 2019-12-07. Score: 3
  
  First, I doubt that there are any such statistics because the effect would seem to be so small as to be overwhelmed by other, more common, things. You could, perhaps, create an instrument (as in a compiler) to look for such things and look for effects in, say, unit tests of the code. But that implies that a lot of things come together.
  
  But, I would also suggest that your basic understanding of human psychology may be naive. It could well be that there are people who actually think more effectively in "greater than" mode. As a mathematician, I've often been confused by left-right and by east-west, especially when they all show up in the same context. But it is, I'm pretty sure, because, I look at things with a "frameless" view. What is left and what is right depends on where I think of myself as viewing from.
  
  Also, some times it is just more "natural" to express things with greater than, as in "error > 0.05".
  
  So, I think a teaching "rubric" that punished students for using one form over the other would be misplaced. It would, in some situations, lead the user to perform an extra step in their thinking, and that, alone, could lead to an error.
  
  > **Comments:**
  > **username_4**: There has been research on whether using > vs >= leads to more or fewer errors. (I think the upshot is that people make fewer errors when they use one method consistently instead of trying to be clever.) We often must use "open intervals" where the starting point is an absolute number, like >= 0, and the upper bound is a < comparison, like: 4.9999 is OK but 5.0000 is right out. I used to teach that routinely, from the section of the textbook on Range Comparisons. Not sure anyone really got it, but to me it made sense. Of course, you could say: IF 5.0 NOT <= x THEN... DeMorgan and all that.  
  
  ---
  
  