Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python.': 0.02; 'skip:[ 20': 0.04; 'value,': 0.04; 'interpreter': 0.05; 'method.': 0.07; 'none,': 0.07; 'result,': 0.07; 'contexts': 0.09; 'function,': 0.09; 'meaningful': 0.09; 'unified': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'stored': 0.12; "wouldn't": 0.14; 'distinct': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'information"': 0.16; 'magic': 0.16; 'none.': 0.16; 'semantically': 0.16; 'semantics': 0.16; 'subject:between': 0.16; 'subject:tasks': 0.16; 'usage,': 0.16; 'ignore': 0.16; 'wrote:': 0.18; 'normally': 0.19; "python's": 0.19; 'value.': 0.19; 'example': 0.22; 'cc:addr:python.org': 0.22; '(or': 0.24; 'cc:2**0': 0.24; 'second': 0.26; 'pass': 0.26; 'certain': 0.27; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'thus': 0.29; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'program,': 0.31; 'that.': 0.31; '(maybe': 0.31; '>>>>': 0.31; 'default,': 0.31; 'pascal': 0.31; 'piece': 0.31; 'procedures.': 0.31; 'checking': 0.33; 'fri,': 0.33; 'subject:the': 0.34; 'could': 0.34; 'something': 0.35; 'one,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'functions.': 0.36; 'opposed': 0.36; 'subject:?': 0.36; 'example,': 0.37; 'being': 0.38; 'pm,': 0.38; 'rather': 0.38; 'anything': 0.39; 'ability': 0.39; 'explain': 0.39; 'sure': 0.39; 'system.': 0.39; 'skip:p 20': 0.39; 'called': 0.40; 'expression': 0.60; 'most': 0.60; 'simply': 0.61; "you're": 0.61; 'first': 0.61; "you've": 0.63; 'real': 0.63; 'skip:n 10': 0.64; 'more': 0.64; 'here': 0.66; 'between': 0.67; 'surrounding': 0.68; 'default': 0.69; 'special': 0.74; 'gain': 0.79; '2015': 0.84; 'balanced': 0.84; 'difference.': 0.84; "it'd": 0.84; 'returns.': 0.84; 'strengths': 0.84; 'treats': 0.84; 'collective': 0.91; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=JxLlr2jTAW1YL6api5uPiM5YfTDOgDXt8L5+hek7ObQ=; b=PNqBSxPg6+1RZjZZxgK55MbcvZp1FKjl0vHpkWlFUzLRox+2Gnsmm9cy4HFofrkOsw CzeTaA3SWM4EsKcEJicsmGaejZ/Dzf0ePol+4AZYwoZSShCg9EPAUlG8kDK5Z0IgOpXS ny47IKyOvBxKF/dB55dJUXdbyrchbPrxq4OaDRFK6j7xWAzsEiLnhGAu74KgqtJKwwPG KobdV+QLc6bWn7H+mSfIvBdYbisrfjFjXNgOifNSkalS353kcmiEhpI4jkyhvtxPttPX aBM19qJymhWXH2f7XLFOVByWBi6LdBLlJWtY2KnH4wev/q1T85TkxJCYCF3yqAF/R+TC F3Lw== MIME-Version: 1.0 X-Received: by 10.50.114.35 with SMTP id jd3mr1983445igb.14.1431059586851; Thu, 07 May 2015 21:33:06 -0700 (PDT) In-Reply-To: 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> Date: Fri, 8 May 2015 14:33:06 +1000 Subject: Re: asyncio: What is the difference between tasks, futures, and coroutines? From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 56 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1431059590 news.xs4all.nl 2925 [2001:888:2000:d::a6]:58178 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:90115 On Fri, May 8, 2015 at 2:06 PM, Rustom Mody 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