Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #90115
| References | <344fd8f6-75c1-4b7d-888d-c5c9d4498ec3@googlegroups.com> <878ud27waw.fsf@elektro.pacujo.net> <4ea2d5ac-8c19-4a53-9a09-fe6dbe4a52bd@googlegroups.com> <5549ab43$0$11108$c3e8da3@news.astraweb.com> <b0022fbc-74e2-4990-9773-9e5e07d51f14@googlegroups.com> |
|---|---|
| Date | 2015-05-08 14:33 +1000 |
| Subject | Re: asyncio: What is the difference between tasks, futures, and coroutines? |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.216.1431059590.12865.python-list@python.org> (permalink) |
On Fri, May 8, 2015 at 2:06 PM, Rustom Mody <rustompmody@gmail.com> wrote:
>> > If the classic Pascal (or Fortran or Basic) sibling balanced abstractions
>> > of function-for-value procedure-for-effect were more in the collective
>> > consciousness rather than C's travesty of function, things might not have
>> > been so messy.
>>
>> I'm not really sure that having distinct procedures, as opposed to functions
>> that you just ignore their return result, makes *such* a big difference. Can
>> you explain what is the difference between these?
>>
>> sort(stuff) # A procedure.
>> sort(stuff) # ignore the function return result
>>
>> And why the first is so much better than the second?
>
> Here are 3 None-returning functions/methods in python.
> ie semantically the returns are identical. Are they conceptually identical?
>
>>>> x=print(1)
> 1
>>>> x
>>>> ["hello",None].__getitem__(1)
>>>> {"a":1, "b":2}.get("c")
>>>>
Your second example is a poor one, as it involves calling a dunder
method. But all you've proven with that is that the empty return value
of Python is a real value, and can thus be stored and retrieved.
With print(), you have a conceptual procedure - it invariably returns
None, so it'll normally be called in contexts that don't care about
the return value. What about sys.stdout.write(), though? That's most
often going to be called procedurally - you just write your piece and
move on - but it has a meaningful return value. In normal usage, both
are procedures. The ability to upgrade a function from "always returns
None" to "returns some occasionally-useful information" is one of the
strengths of a unified function/procedure system.
With .get(), it's actually nothing to do with procedures vs functions,
but more to do with Python's use of None where C would most likely use
NULL. By default, .get() uses None as its default return value, so
something that isn't there will be treated as None. In the same way as
your second example, that's just a result of None being a real value
that you can pass around - nothing more special than that.
The other thing you're seeing here is that the *interactive
interpreter* treats None specially. In a program, an expression
statement simply discards its result, whether it's None or 42 or
[1,2,3] or anything else. You could write an interactive interpreter
that has some magic that recognizes that certain functions always
return None (maybe by checking their annotations), and omits printing
their return values, while still printing the return values of other
functions. I'm not sure what it'd gain you, but it wouldn't change the
concepts or semantics surrounding None returns.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
asyncio: What is the difference between tasks, futures, and coroutines? Paul Moore <p.f.moore@gmail.com> - 2015-05-05 08:22 -0700
Re: asyncio: What is the difference between tasks, futures, and coroutines? Zachary Ware <zachary.ware+pylist@gmail.com> - 2015-05-05 11:11 -0500
Re: asyncio: What is the difference between tasks, futures, and coroutines? Paul Moore <p.f.moore@gmail.com> - 2015-05-05 10:55 -0700
Re: asyncio: What is the difference between tasks, futures, and coroutines? Terry Reedy <tjreedy@udel.edu> - 2015-05-05 13:15 -0400
Re: asyncio: What is the difference between tasks, futures, and coroutines? Marko Rauhamaa <marko@pacujo.net> - 2015-05-05 20:45 +0300
Re: asyncio: What is the difference between tasks, futures, and coroutines? Rustom Mody <rustompmody@gmail.com> - 2015-05-05 21:47 -0700
Re: asyncio: What is the difference between tasks, futures, and coroutines? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-06 15:48 +1000
Re: asyncio: What is the difference between tasks, futures, and coroutines? Rustom Mody <rustompmody@gmail.com> - 2015-05-07 21:06 -0700
Re: asyncio: What is the difference between tasks, futures, and coroutines? Chris Angelico <rosuav@gmail.com> - 2015-05-08 14:33 +1000
Re: asyncio: What is the difference between tasks, futures, and coroutines? Rustom Mody <rustompmody@gmail.com> - 2015-05-07 21:53 -0700
Re: asyncio: What is the difference between tasks, futures, and coroutines? Rustom Mody <rustompmody@gmail.com> - 2015-05-07 21:55 -0700
Re: asyncio: What is the difference between tasks, futures, and coroutines? Chris Angelico <rosuav@gmail.com> - 2015-05-08 15:09 +1000
Re: asyncio: What is the difference between tasks, futures, and coroutines? Rustom Mody <rustompmody@gmail.com> - 2015-05-07 23:36 -0700
Re: asyncio: What is the difference between tasks, futures, and coroutines? Chris Angelico <rosuav@gmail.com> - 2015-05-08 16:42 +1000
Re: asyncio: What is the difference between tasks, futures, and coroutines? Dave Angel <davea@davea.name> - 2015-05-08 07:53 -0400
Re: asyncio: What is the difference between tasks, futures, and coroutines? Chris Angelico <rosuav@gmail.com> - 2015-05-08 23:02 +1000
Re: asyncio: What is the difference between tasks, futures, and coroutines? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-05-06 09:11 -0400
Re: asyncio: What is the difference between tasks, futures, and coroutines? Rustom Mody <rustompmody@gmail.com> - 2015-05-07 21:20 -0700
Re: asyncio: What is the difference between tasks, futures, and coroutines? Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-05 11:46 -0600
Re: asyncio: What is the difference between tasks, futures, and coroutines? Paul Moore <p.f.moore@gmail.com> - 2015-05-05 11:03 -0700
Re: asyncio: What is the difference between tasks, futures, and coroutines? Skip Montanaro <skip.montanaro@gmail.com> - 2015-05-05 12:55 -0500
Re: asyncio: What is the difference between tasks, futures, and coroutines? Terry Reedy <tjreedy@udel.edu> - 2015-05-05 18:38 -0400
csiph-web