<p dir="ltr"><br>
On 25 Jan 2015 03:34, "Guido van Rossum" <<a href="mailto:guido@python.org">guido@python.org</a>> wrote:<br>
><br>
> Can you guys get a room?</p>
<p dir="ltr">More explicitly - I think we've established we *don't actually know* why the statement/expression distinction improves readability, just that decades of experience suggests it does.</p>
<p dir="ltr">Further speculation here is unlikely to bring further clarity, so anyone interested in seeing it pursued to the point of reaching a more definitive conclusion would be well advised to get in touch with folks that actually research programming language readability (e.g. the authors of this paper from a few years ago: <a href="http://neverworkintheory.org/2011/10/24/an-empirical-comparison-of-the-accuracy-rates-of-novices-using-the-quorum-perl-and-randomo-programming-languages.html">http://neverworkintheory.org/2011/10/24/an-empirical-comparison-of-the-accuracy-rates-of-novices-using-the-quorum-perl-and-randomo-programming-languages.html</a> and their more recent follow-up <a href="http://neverworkintheory.org/2014/01/29/stefik-siebert-syntax.html">http://neverworkintheory.org/2014/01/29/stefik-siebert-syntax.html</a>)</p>
<p dir="ltr">Cheers,<br>
Nick.</p>
<p dir="ltr">><br>
> On Sat, Jan 24, 2015 at 3:06 AM, Andrew Barnert <abarnert@yahoo.com.dmarc.invalid> wrote:<br>
>><br>
>> On Jan 23, 2015, at 23:53, Ron Adam <<a href="mailto:ron3200@gmail.com">ron3200@gmail.com</a>> wrote:<br>
>><br>
>> I fear we're probably getting pretty far off-topic for python-ideas, but I'm going to respond anyway.<br>
>><br>
>> > On 01/24/2015 12:06 AM, Andrew Barnert wrote:<br>
>> >> On Friday, January 23, 2015 2:06 PM, Ron Adam<<a href="mailto:ron3200@gmail.com">ron3200@gmail.com</a>><br>
>> >> wrote:<br>
>> >><br>
>> >>>><br>
>> >>>> On 01/23/2015 08:56 AM, Nick Coghlan wrote:<br>
>> ><br>
>> >>>>>> I really like that "each statement is like a single step in a<br>
>> >>>>>> mathematical proof" analogy.<br>
>> >>>><br>
>> >>>> I agree.<br>
>> >>>><br>
>> >>>><br>
>> >>>> There are some other distinctions.  When you consider these, you can<br>
>> >>>> see how many language designers come to similar solutions.<br>
>> >>>><br>
>> >>>><br>
>> >>>> Expressions evaluate in unique name spaces, while statements<br>
>> >>>> generally do not. Consider "a + b"; it is evaluated in a private<br>
>> >>>> method after the values a and b are passed to it.<br>
>> ><br>
>> >> I don't think that's true.<br>
>> ><br>
>> > Not all the time, which is why I said "generally". :-)<br>
>> ><br>
>> >> Consider "a[b] = c", which is a statement,<br>
>> >> but it's evaluated in a private method after the values a, b, and c are<br>
>> >> passed to it. The fact that it's a.__setitem__ rather than a.__add__<br>
>> >> doesn't seem particularly important. I think the key is that __setitem__<br>
>> >> doesn't have a return value--like (nearly) everything in Python that<br>
>> >> mutates state--and therefore there's no expression for it. The question<br>
>> >> is, what does that buy?<br>
>> ><br>
>> > Right, and good question, but consider that it's not adding or altering the name space the 'a' object is in.  It's a convenience/exception for using objects.<br>
>><br>
>> I think that's the point. In theory, objects are just syntactic sugar for closures; in practice, objects are an intuitively useful way to represent mutable state. And the fact that things that mutate an object are statements (whether directly, because they're __setattr__ type calls, or indirectly, because they're expressions that return None and can therefore only be used in expression statements) is important in making Python readable in practice.<br>
>><br>
>> > If objects were done with closures, then the same modification would be done with an assignment statement.  And then the generalisation would be more consistent.  But at a cost is other ways.<br>
>> ><br>
>> >>>> Statements are used to mutate the current name space, while<br>
>> >>>> expressions generally do not.<br>
>> >> This is closer. I think, more generally, statements are used to mutate<br>
>> >> the important state that the local function is all about mutating. And<br>
>> >> the thing that gets mutated is almost always the leftmost thing. That<br>
>> >> definitely helps in scannability.<br>
>> ><br>
>> > I'm not quite sure I follow that.  I think what you are calling the important state, I think of as the shared state. A value that will be used multiple times in the same frame.<br>
>><br>
>> By "important state", I just mean whatever state the reader is likely to care about. And such state is almost always modified by a statement with some readable identification on the left side--whether it's a global/closure/local assignment, an attribute assignment, an element assignment, and augmented version of any of the above, a method call that doesn't return self (and will therefore only be used in an expression statement). So each statement means (at most) one state transition. And it's almost always the leftmost thing that's affected. And I think that aids readability.<br>
>><br>
>> > Binding a name to a value mutates the names pace, but it does not mutate the name.  It's still the same name.<br>
>> ><br>
>> > Again this can be view multiple way if you consider how it actually works.  Some languages use a stack to implement a name. And in a new frame, a new bound value would get pushed on the name stack.  I'm not completely sure that python doesn't do something like that in some places to speed thing up.  But I don't think so.<br>
>><br>
>> Sure, pure non-mutating languages can use a stack to implement bindings. But in a mutating language, that doesn't work if you have closures. CTM explains what you get out of mutable state (and what it costs) very nicely. Of course in practice any Python implementation has to be able to detect whether a given scope might have closures referring to it, so it _could_ switch to rebinding using a bindinmg stack, but in practice any Python implementation is likely to convert local accesses to offsets as CPython does, which is a much better optimization (at least for a language where rebinding is idiomatically common) that precludes that option.<br>
>><br>
>> >>>> Statements can alter control flow, while expressions generally do<br>
>> >>>> not.<br>
>> >> Sure, but I think this part only really helps if control flow is somehow<br>
>> >> visible. In Python, it is, because control flow almost always means<br>
>> >> compound statements, which means indentation, and very little else means<br>
>> >> indentation.<br>
>> ><br>
>> > You are referring to the visual aspect, while I'm referring to what a statement does.  Same thing. ;-)<br>
>><br>
>> Well, I'm highlighting the visual aspect because I think that's important to Python's readability, and to why statements contribute to that readability. If statements and expressions had similar indentation rules (as in CoffeeScript), I don't think Python would get the same benefit from having statements.<br>
>><br>
>> >>>> Having a clear distinction between expressions and statements makes<br>
>> >>>> reading and understanding code much easier.<br>
>> >> Definitely. That's the part I think is key, but am struggling to<br>
>> >> explain.<br>
>> >><br>
>> >> I think Guido offers a great analogy in mathematical proofs, but the<br>
>> >> question is to find the actual commonality behind the analogy.<br>
>> ><br>
>> > Form follows function...  Just one way to look at it.  Sometimes what something does can come from the shape it has too.<br>
>><br>
>> Yes. But sometimes the shape is limiting, rather than expanding--and yet that limitation itself can be used to add meaning. (See Guido's point about code that fits in a window/screen/page.)<br>
>> So function partly follows form. And mathematical proofs are a great example. The fact that there are a limited number of ways you're allowed to get from the previous statements to the next one makes each step more readable.<br>
>><br>
>> >> After some more thought on this, I think what it comes down to is that<br>
>> >> (idiomatically-written) Python lets you skim the control flow (because<br>
>> >> all non-trivial control flow, and very little else, is expressed in<br>
>> >> terms of indentation) and the state transitions (because each statement<br>
>> >> generally mutates at most one thing, and it's the leftmost thing), so<br>
>> >> you can quickly find the part of the code you actually need to read<br>
>> >> carefully, instead of having to read the whole thing.<br>
>> >><br>
>> >> I've written this idea up in a bit more detail here:<br>
>> >><br>
>> >> <a href="http://stupidpythonideas.blogspot.com/2015/01/statements-and-expressions.html">http://stupidpythonideas.blogspot.com/2015/01/statements-and-expressions.html</a><br>
>> ><br>
>> > Very interesting.. and thanks for the mention.  ;-)<br>
>><br>
>> Sure; as I said, your last paragraph (well, the last one I quoted) puts the whole thing I'm trying to answer much more clearly than I've been able to.<br>
>><br>
>> > One of the things that makes a difference is to be able to hold a simplified model in your mind while you are working on it.<br>
>><br>
>> Yes! That's something else that was on the tip of my tongue that I couldn't explain clearly. Being able to hold enough of the syntax in your head to parse code subconsciously (which CoffeeScript lacks, as Guido pointed out) is part of it, but you're right, the big deal is being able to hold the entire model in your head.<br>
>><br>
>> And at a different level, that's what makes scanability of flow control and state changes so important, which I couldn't explain before. That's the model of an imperative-style function that you need to be able to internalize to understand the function holistically.<br>
>><br>
>> Thanks.<br>
>><br>
>> > The separation of statements and expressions definitely helps me with that.  If I can easily keep the name space in my mind... or at least the part of it that correspond with the block of code I'm looking at, It really helps me to visualise things in a meaningful way and see what effect the statements will have on the name space.<br>
>><br>
>> Exactly. Which is why the "one obvious mutation per line (usually)" property is so important.<br>
>><br>
>> But I think describing it purely in terms of the local namespace hides the fact that it applies just as well to OO-style code (where most mutation is to the namespace of self or one of the other parameters) as to traditional structured imperative code.<br>
>><br>
>> > When statements and expressions don't represent what they do in an obvious way, then all bets are off.  It becomes a mental stumbling block.<br>
>><br>
>> > Much of this became clear to me when I wrote a simplified script language that adds statements to a mini scheme like language.  I did need to use braces for blocks.  Even though I didn't need to use visual indentation, I still preferred formatting the programs in a similar style to python.  In this mini language, the separation of statements and expressions is even more pronounced because all expressions are s-expressions, and all statements are not expressions.<br>
>> ><br>
>> > And going one bit further, I used dictionaries for names spaces, like python, but used lists for statement blocks.  So statement blocks have order, but name spaces don't.<br>
>> ><br>
>> ><br>
>> >>>> I believe Python follows most of these conventions in most places,<br>
>> >>>> and when it doesn't, it's usually for a practical reason that are<br>
>> >>>> fairly obvious.<br>
>> >>>><br>
>> >>>> For example, an "or" expression is a bit of both.<br>
>> >>>><br>
>> >>>> Another example of how python chooses a practical alternative is we<br>
>> >>>> can nest expressions instead of using "call" statements on separate<br>
>> >>>> lines and a stack to hold the augments and return values.  That is<br>
>> >>>> what python does in the byte code so we don't have to do it in<br>
>> >>>> explicit statements.<br>
>> >>>><br>
>> >>>> If you factor out all expressions you get byte code.  Or if you<br>
>> >>>> factor out all statements you get something like lisp.<br>
>> >> I don't think either part of that is true.<br>
>> ><br>
>> > It wasn't meant to be taken absolutely literally.  Which is why I said... "something like".<br>
>><br>
>> OK, but I don't think it's figuratively true in any useful sense either. Languages like Ruby prove that removing statements doesn't have to mean something like Lisp. We aren't stuck with the models of the 60s. So the question of what you give up by factoring out all statements turns out to be more complicated (and more interesting) than it was in those models.<br>
>><br>
>> > There is quite a bit of wiggle room when it comes to how different people think about things, and what words we use to describe them.  Some times the hardest part of a discussion is getting the same mental picture in more than one person.  :-)<br>
>> ><br>
>> >> Bytecode is full of things<br>
>> >> that are expressions—even your paradigm case of an operator expression<br>
>> >> is handled by an opcode.<br>
>> ><br>
>> > I see opcodes as being similar to keywords that are used in a statement form.  And I view the stack as being a temporary value space.  Of course, I know certain combinations of several opcodes together may correspond to a particular python expression, but individually, each byecode along with it's following few values, are byte code statements to me.<br>
>> ><br>
>> > And even if a single bytecode was the equivalent of a python expression, my point was you can use statements replace statements with expressions.<br>
>><br>
>> I don't know what you meant here. Maybe that a stack machine language has a fixed, non-extensible set of expressions, but its set of statements can be effectively arbitrarily extended with jsr/ret to other bytecode? If so, I'll buy that, but I'm not sure how it's relevant. I don't know of any examples of readable expression-free code that compare to such examples of readable statement-free code as, say, anything written in OCaml, or any Ruby code that sticks to single-return style. Eliminating expressions is clearly a non-starter for a readable language; eliminating statements is actually arguable--and the whole point is to find the arguments against doing so.<br>
>><br>
>> > Byte code is a good example of that.  But you still have functions calls.. You just can't nest them in the same way you do with python function calls, you must push them on the stack and use CALL "statements" to execute it, and then use another statement to store the value that gets put on the top of the stack.  (or push another function on the stack that will use that value...)<br>
>> ><br>
>> ><br>
>> >> And conversely, CoffeeScript (if you avoid<br>
>> >> break/continue/return statements) factors out all statements, and Ruby<br>
>> >> comes close to doing so, and yet they're really not more Lisp-like than<br>
>> >> Python in any meaningful way.<br>
>> ><br>
>> > See the next paragraph... ;-)<br>
>> ><br>
>> >>>> Of course this subject is definitely a very subjective one which<br>
>> >>>> relays on agreeing on the general meaning of the above sentences.<br>
>> >>>> OR... YMMV.<br>
>><br>
>> Sure, but I'm not sure I understand the meaning you're going for.<br>
>><br>
>> And, more importantly, I think there is an objective sense in which Python uses statements to gain subjective readability, and that objective sense is something we can question and try to answer.<br>
>> _______________________________________________<br>
>> Python-ideas mailing list<br>
>> <a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
>> <a href="https://mail.python.org/mailman/listinfo/python-ideas">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
>> Code of Conduct: <a href="http://python.org/psf/codeofconduct/">http://python.org/psf/codeofconduct/</a><br>
><br>
><br>
><br>
><br>
> -- <br>
> --Guido van Rossum (<a href="http://python.org/~guido">python.org/~guido</a>)<br>
><br>
> _______________________________________________<br>
> Python-ideas mailing list<br>
> <a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/python-ideas">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
> Code of Conduct: <a href="http://python.org/psf/codeofconduct/">http://python.org/psf/codeofconduct/</a><br>
</p>