Comparisons and sorting of a numeric class....

Chris Kaynor ckaynor at zindagigames.com
Thu Jan 8 13:44:39 EST 2015


On Thu, Jan 8, 2015 at 6:57 AM, Ian Kelly <ian.g.kelly at gmail.com> wrote:

> On Wed, Jan 7, 2015 at 11:21 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
> > Steven D'Aprano <steve+comp.lang.python at pearwood.info>:
> >
> >> Marko Rauhamaa wrote:
> >>> I prefer the Scheme way:
> >>>    #f is a falsey object
> >>>    everything else is a truthy object
> >>
> >> The Scheme way has no underlying model of what truthiness represents,
> just
> >> an arbitrary choice to make a single value have one truthiness, and
> >> everything else the other. It's just as meaningless and just as
> arbitrary
> >> as the opposite would be:
> >>
> >>     #t is True
> >>     everything else is falsey
> >> [...]
> >> I'd rather the Pascal way:
> >>
> >>     #t is True
> >>     #f is False
> >>     everything else is an error
> >
> > An advantage of the Scheme way is the chaining of "and" and "or". For
> > example, this breaks in Python:
> >
> >    def dir_contents(path):
> >        if os.path.isdir(path):
> >            return os.listdir(path)
> >        return None
> >
> >    def get_choices():
> >        return dir_contents(PRIMARY) or \
> >            dir_contents(SECONDARY) or \
> >            [ BUILTIN_PATH ]
>
> That depends on what the function is intended to do in the first
> place. Why would you want to return the contents of an empty directory
> rather than the default?
>
> Anyway, to make that work as you want it in Scheme, dir_contents would
> have to return #f, not None. Does it really make sense for a
> non-predicate function to be returning the value "false"?


I'd like to second this. I don't believe either way is inherently superior
to the other.

Lately, I've been doing quite a bit of work in lua, and many times have
wished that empty strings, tables, and 0 acted "falsey", but at the same
time, previously working in Python, there were plenty of times I wished
they acted "truthy". It merely depends on what algorithm I am using at the
time...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150108/25b1e657/attachment.html>


More information about the Python-list mailing list