[Tutor] “has a value of True” versus “evaluates true”
Steven D'Aprano
steve at pearwood.info
Thu Nov 13 23:45:42 CET 2014
On Thu, Nov 13, 2014 at 12:16:19PM -0800, Danny Yoo wrote:
> > Unlike some languages, which choose confusing and arbitrary sets of
> > values that count as truthy or falsey, Python encourages a simple
> > distinction, something versus nothing. Values which represent some kind
> > of "nothing" are falsey:
>
>
> Hi Steven,
>
> Sure. I'm not arguing that Python's choices of what's truthy or
> falsey isn't consistent or hard to remember. What I'm saying is that
> I personally have to deal with multiple languages at once these days.
> (JavaScript is the big one.) I find one of the points where things
> seem needlessly divergent is truthiness. Given that, I personally
> subset the language so that I don't have to spend brainpower on this
> issue.
*shrug*
Any time you use multiple languages, you have to deal with their
differences in syntax and semantics. That's the cost of using multiple
languages. I'm sympathetic to that fact, but I'm not sympathetic to the
suggestion that we should avoid a sensible and useful language feature
because *other* languages do things differently.
Deliberately forgoing the use of a language feature because you have
trouble with it is understandable. You know your own strengths and
weaknesses, and if that helps you avoid bugs that's a good thing. But
the cost is that you may be writing unidiomatic code, or code that works
but can be improved.
If I couldn't remember the difference between [1, 2] and (1, 2), and
consequently wrote list([1, 2]) "just to be sure", we'd all agree that
it was poor coding style even if we sympathised with my confusion over
lists and tuple.
> As a confession: I have run and introduced bugs where the root cause
> was one language's truthiness table diverging from another. Given
> that I recognise that I make this particular class of mistake a bit
> more frequently than I'd like, I try to account for this personal
> weakness and engineer for it. I am not clever.
I think you're a lot cleverer than you give yourself credit for, and
your coping strategy is a matter for you and anyone reviewing your code.
Criticising people's code can often be mistaken for criticising the
person themselves, but it shouldn't be seen that way.
> >> To quote: "Let your statement be: 'Yes, yes', or "no, no': anything beyond
> >> these is of evil."
> >
> > "Have you stopped abusing small children yet?"
>
> :(
>
> I don't understand what your response here means.
"Yes" means that the answerer previously abused children; "No" means
that haven't stopped. If the answerer never abused children at all, the
question is a trap and neither Yes nor No is an accurate, truthful
answer. Matthew's instruction that an accurate answer that explains the
facts correctly ("I have never abused children at all") is to be
considered "evil" is itself wicked, or at least terribly naive.
> My intent in
> quoting Matthew 5:37 was purely as a joke, precisely because the quote
> is so ridiculously out of context and definitely not intended to apply
> to the boolean context of programming languages. My apologies if you
> didn't like that.
Your quote was intended to be humourous, as was my reply. I certainly
wasn't implying that you have abused children.
--
Steve
More information about the Tutor
mailing list