Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #83363

Re: Comparisons and sorting of a numeric class....

References (5 earlier) <54ace9f0$0$2738$c3e8da3$76491128@news.astraweb.com> <87tx02gb9d.fsf@elektro.pacujo.net> <54adc53c$0$12999$c3e8da3$5496439d@news.astraweb.com> <877fwx3i8f.fsf@elektro.pacujo.net> <CALwzidkn5E3uxQ3Et9r-0_WUTjPLfHtY7mqwnhNVe2MGCi528Q@mail.gmail.com>
From Chris Kaynor <ckaynor@zindagigames.com>
Date 2015-01-08 10:44 -0800
Subject Re: Comparisons and sorting of a numeric class....
Newsgroups comp.lang.python
Message-ID <mailman.17483.1420742711.18130.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

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

> On Wed, Jan 7, 2015 at 11:21 PM, Marko Rauhamaa <marko@pacujo.net> wrote:
> > Steven D'Aprano <steve+comp.lang.python@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...

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Comparisons and sorting of a numeric class.... Andrew Robinson <andrew3@r3dsolutions.com> - 2015-01-06 18:01 -0800
  Re: Comparisons and sorting of a numeric class.... Steven D'Aprano <steve@pearwood.info> - 2015-01-07 08:10 +0000
    Re: Comparisons and sorting of a numeric class.... Chris Angelico <rosuav@gmail.com> - 2015-01-07 19:21 +1100
    Re: Comparisons and sorting of a numeric class.... Marko Rauhamaa <marko@pacujo.net> - 2015-01-07 12:01 +0200
      Re: Comparisons and sorting of a numeric class.... Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-08 10:46 +1100
        Re: Comparisons and sorting of a numeric class.... Marko Rauhamaa <marko@pacujo.net> - 2015-01-08 08:21 +0200
          Re: Comparisons and sorting of a numeric class.... Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-08 07:57 -0700
            Re: Comparisons and sorting of a numeric class.... Marko Rauhamaa <marko@pacujo.net> - 2015-01-08 21:41 +0200
          Re: Comparisons and sorting of a numeric class.... Chris Kaynor <ckaynor@zindagigames.com> - 2015-01-08 10:44 -0800
            Re: Comparisons and sorting of a numeric class.... Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-09 23:27 +1100
              Re: Comparisons and sorting of a numeric class.... Chris Angelico <rosuav@gmail.com> - 2015-01-09 23:43 +1100
                Re: Comparisons and sorting of a numeric class.... Marko Rauhamaa <marko@pacujo.net> - 2015-01-09 16:28 +0200
                Re: Comparisons and sorting of a numeric class.... Paul Rubin <no.email@nospam.invalid> - 2015-01-09 07:06 -0800
                Re: Comparisons and sorting of a numeric class.... Chris Angelico <rosuav@gmail.com> - 2015-01-10 02:14 +1100
                Re: Comparisons and sorting of a numeric class.... Marko Rauhamaa <marko@pacujo.net> - 2015-01-09 17:16 +0200

csiph-web