Python is readable

Steve Howell showell30 at yahoo.com
Wed Mar 21 20:54:14 EDT 2012


On Mar 21, 4:34 pm, Steven D'Aprano <steve
+comp.lang.pyt... at pearwood.info> wrote:
> On Wed, 21 Mar 2012 11:22:01 -0500, Evan Driscoll wrote:
> > On 01/-10/-28163 01:59 PM, Steve Howell wrote:
> >> Code shouldn't necessarily follow the example of English prose, but it
> >> seems that English has had some influence:
>
> >>   1  push(stack, item) # Push on the stack the item
> >>   2  push(item, stack) # Push the item on the stack
> >>   3  stack.push(item)  # On the stack, push the item
> >>   4  stack item push   # On the stack, take the item and push it
> >>   5  item stack push   # Take the item and on the stack, push the
> >>      former.
> >>   6  item push stack   # Take the item; push it on the stack.
>
> >> The first three ways are the most common ways of arranging the grammar
> >> in mainstream programming languages, and they are also the three most
> >> natural ways in English (no pronouns required).
>
> >> #1/2 are imperative.  #3 is OO.
>
> > In my opinion, people who make statements such as "#1/2 are imperative,
> > #3 is OO" are missing pretty much the entire point of what OO is.
>
> > OO is much more about semantics and the way code is structured. The
> > difference between #1/2 (especially #1, of course) and #3 is
> > surface-level syntax only.
>
> +1000
>
> I like to talk about "object oriented SYNTAX" (emphasis added) to
> distinguish the typical OO dotted syntax obj.attr (or obj->attr) from
> other syntax varieties. But this must be understood as mere convention.
> One could invent an OO language which used syntax "push(stack, item)" or
> even something exotic like "item!push~stack" and it would remain OO, only
> with unusual syntax.
>

Sorry if I caused confusion here.  When I labelled certain syntaxes as
"imperative" and certain syntaxes as "object-oriented," I never meant
to imply anything about the semantic layer.  (I think Evan misread my
post a bit, and then went a little overboard with his comment that
people like me "are missing the entire point of OO.")

Clearly, I get the fact that there can be multiple valid syntaxes to
express the same underlying operation, as evidenced by my presenting
six permutations of stack/push/item.

The discussion that I thought would be interesting is this--given six
seemingly arbitrary ways of expressing the same idea, how do you
decide?  My hypothesis is that we all have prior conditioning such
that the arrangement of words actually *does* matter.  And the
conditioning comes from multiple realms--we speak natural languages,
we have familiarity with arithmetic notation, and we have traditions
from programming itself.

The place where token arrangement resonates best with me is
arithmetic.  I can deal with all of the expressions on a semantic
level:

  5 + 3
  5 3 +
  + 5 3

On a purely theoretical level, the choice of syntax doesn't really
matter (it's just a convention), but the convention is so strong, it
matters on a readability level.  Even though I can grok prefix/
postfix, I feel uncomfortable in programming languages that don't have
"infix" sugar.  Imagine if Python didn't support infix sugar.  No
semantic change, right?  But it would still matter for some...







More information about the Python-list mailing list