Python is readable
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Wed Mar 21 19:34:28 EDT 2012
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.
Contrariwise, a purely functional language might use declarative or OO-
like syntax. Syntax is orthogonal to the data model, although some data
models naturally suggest some syntaxes over others.
(Syntaxes? Syntaxen? Syntacies?)
The first OO language I ever used was Hypertalk, which used a message-
passing model:
send mouseUp to button OK of card Prefs
and an optional function-call syntax like this:
put the average of field Values into field Average
which I guess makes Hypertalk a message-passing OO language with
imperative syntax.
> About the strongest statement you can make along those lines is that #3
> will allow you to do dynamic dispatch on the type of 'stack' while #1/2
> won't, but even that isn't true of course.
Of course. At runtime, the interpreter is able to dispatch to the correct
method of 'stack' regardless of where the tokens are in the source code.
--
Steven
More information about the Python-list
mailing list