On Thu, Jan 8, 2015 at 6:57 AM, Ian Kelly <ian.g.ke...@gmail.com> wrote:
> On Wed, Jan 7, 2015 at 11:21 PM, Marko Rauhamaa <ma...@pacujo.net> wrote: > > Steven D'Aprano <steve+comp.lang.pyt...@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...
-- https://mail.python.org/mailman/listinfo/python-list