Python is readable

Chris Angelico rosuav at gmail.com
Wed Mar 21 00:16:36 EDT 2012


On Wed, Mar 21, 2012 at 1:44 PM, Steve Howell <showell30 at yahoo.com> wrote:
> I think it's a matter of perspective, so there's no right answer, but
> I always think of the program object as also being the grammatical
> object, with the implied subject/actor being Python itself.  For
> example, consider this code:
>
>  stack.push(item)
>
> It's not the stack that's pushing.  It's the stack being pushed on
> to.

In code, though, the push() method is defined in and on the stack
object (or more likely, on the class that instantiated it, but near
enough). So the stack is being asked to push something onto itself. It
is still viably the subject. Yes, the implied subject could be the
language interpreter; but it could just as easily be the CPU, or those
friendly nanobots, or that guy moving the rocks in XKCD 505. But in
the abstraction of the line of code, you don't care how CPython goes
about loading globals, calling bound methods, and incrementing object
reference counts - you just care that the stack is pushing this item
onto itself.

Some method names are definitely written as though their primary
argument is the object, not the subject. Either option works. Do you
think about code as the subject+verb and a data structure as the
object, or the object as the subject and the method as the verb?
Fundamentally no difference.

ChrisA



More information about the Python-list mailing list