Check if a given value is out of certain range

Steven D'Aprano steve at pearwood.info
Sun Oct 4 09:47:57 EDT 2015


On Sat, 3 Oct 2015 10:12 pm, Laura Creighton wrote:

> Actually, the fact that adults have more difficulty processing
> negations is one of the earliest things proven experimentally
> in experimental psychology.

I don't think I've questioned that under some circumstances some negations
can be hard to understand. I've certainly written my share of code
involving negatives that I've had to refactor to understand. A typical
example:

def function(arg, dontpreprocess=False):
    """Perform function on arg. If dontpreprocess is not true, 
    arg is preprocessed."""
    if not dontpreprocess:
        arg = preprocess(arg)
    ...

And of course there are the legendary chains of negations:

don't not cancel the preprocessor suppressor

Does the preprocess run or not? :-)

But I don't think we can jump from a general observation about negations to
the conclusion that a logical disjunction of two different comparisons is
necessarily easier to understand than a negated chained comparison. Some
negations are easy to understand:

    Don't touch that!

and some negations may technically be harder to understand, but in a
practical sense the difference may be negligible:

    if x == 1: ...

    if x != 1: ...


I refuse to believe that the second is *significantly* harder to reason
about than the first.


[...]
> It seems that people tend to hear what they expect to hear, and that
> effect overwhelms any 'this is harder to constuct logically' effect.

I can certainly believe that. It explains a class of errors:

"I'll have the cheese and salad sandwich, no butter, no salt or pepper."

"Okay." [proceeds to make sandwich with butter, salt and pepper]


I've had that happen to me more times than I can remember. People only
listen with half an ear, especially if they're tired, distracted,
emotional, bored, busy, or breathing.

 
> Also, the 'mouse is quicker' experiment was rather more nuanced than
> you reported.  It seems when measuring 'what is faster' the cognitive
> load is important.  Time seems to go faster when you are thinking
> harder about something, than when you are not.  (i.e. how did my
> coffee get cold?  I just started hacking on this thing?)  It seems
> that mouse editing was less of a cognitive load than typing, for
> the people studied, thus they reported that keyboard was faster,
> when it wasn't for them.

Thanks for the anecdote, it was fascinating.

My point was not so much about the advantage (if any) of mouse over
keyboard, which I'm sure will depend on a multitude of factors, but of
people's ability to judge their own efficiency, which I maintain is often
not very good.



-- 
Steven




More information about the Python-list mailing list