Check if a given value is out of certain range

Chris Kaynor ckaynor at zindagigames.com
Thu Oct 1 18:48:35 EDT 2015


On Thu, Oct 1, 2015 at 3:03 PM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> On Thu, Oct 1, 2015 at 3:45 PM, John Gordon <gordon at panix.com> wrote:
> > In <87r3le1ht3.fsf at elektro.pacujo.net> Marko Rauhamaa <marko at pacujo.net> writes:
> >> Wouldn't
> >
> >>    x < 0 or 10 < x
> >
> >> be even more visual?
> >
> > [SNIP]
> >
> > Another strike is that the code isn't consistent with itself; it puts the
> > variable on the left in the first comparison, then swaps to the right for
> > the second comparison.
>
> And on the other hand, it consistently uses the < operator rather
> than swapping to > for the second comparison.

I would argue that the former consistency is more important than the
second, mostly because my mode of thought is along the lines of:
- Do I have more than 10 apples? (x > 10) or
- Do I have fewer than 10 apples? (x < 10)
rather than
- Is 10 fewer apples than I have? (10 < x) or
- Is 10 more apples than I have? (10 > x)

Because the former set is how I think, the former set is the easier to
understand. By no means does it mean I cannot understand the later
set, but it takes more thought to parse the meaning.

If a bunch of code consistently used the second, my mind would adapt
to more easily parse it, but it would take a while to transition
between the sets, especially compared to transitioning within a set.

Chris



More information about the Python-list mailing list