Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #33965

Re: How to pass class instance to a method?

Path csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <d@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'explicitly': 0.04; 'interpreter': 0.04; 'true,': 0.04; 'case.': 0.05; 'everybody,': 0.05; 'arguments': 0.07; 'dependency': 0.07; 'function,': 0.07; 'interpreter.': 0.07; 'parameter': 0.07; 'practice,': 0.07; 'pretend': 0.07; 'puts': 0.07; 'rest,': 0.07; 'statically': 0.07; 'strings.': 0.07; 'subject:How': 0.09; 'broken.': 0.09; 'degree,': 0.09; 'docs.': 0.09; 'does,': 0.09; 'nonnegative': 0.09; 'restriction': 0.09; 'runtime': 0.09; 'subject:method': 0.09; 'target,': 0.09; 'thread,': 0.09; 'tonight.': 0.09; 'typed': 0.09; 'undefined.': 0.09; 'bug': 0.10; 'cc:addr:python-list': 0.10; 'language,': 0.11; 'thread': 0.11; 'static': 0.13; 'language': 0.14; 'do,': 0.15; '(eg.': 0.16; '*any*': 0.16; 'background,': 0.16; 'behaviour.': 0.16; 'brightest': 0.16; 'code?': 0.16; 'compiler,': 0.16; 'declared,': 0.16; 'did,': 0.16; 'hint': 0.16; 'illegal.': 0.16; 'jumping': 0.16; 'keywords.': 0.16; 'mainstream': 0.16; 'non-trivial': 0.16; 'redundant.': 0.16; 'subject:class': 0.16; 'subject:instance': 0.16; 'subject:pass': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'worst': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'certainly': 0.17; 'documented': 0.17; 'else,': 0.17; 'restrictions': 0.17; 'string,': 0.17; 'typing': 0.17; 'written,': 0.17; '>>>': 0.18; 'code,': 0.18; 'parameters': 0.20; 'putting': 0.20; 'written': 0.20; 'all,': 0.21; 'trying': 0.21; 'bit': 0.21; 'do.': 0.21; 'not,': 0.21; 'anonymous': 0.22; 'int,': 0.22; 'defined': 0.22; 'cc:2**0': 0.23; 'example': 0.23; 'nearly': 0.23; 'this:': 0.23; "haven't": 0.23; "i've": 0.23; 'seems': 0.23; 'agile': 0.24; 'cc:no real name:2**0': 0.24; 'idea': 0.24; 'second': 0.24; 'pass': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'common': 0.26; 'first,': 0.27; "doesn't": 0.28; 'chris': 0.28; '>>>>': 0.29; 'cat': 0.29; 'comparison': 0.29; "d'aprano": 0.29; 'documenting': 0.29; 'implied': 0.29; 'name?': 0.29; 'piece': 0.29; 'steven': 0.29; 'yes.': 0.29; 'manual': 0.29; 'source': 0.29; 'that.': 0.30; 'blog:': 0.30; 'e.g.': 0.30; 'projects.': 0.30; 'function': 0.30; 'code': 0.31; '(and': 0.32; 'generally': 0.32; 'could': 0.32; 'says': 0.33; 'surely': 0.33; 'header:Reply-To:1': 0.68; 'fact,': 0.69; 'person.': 0.69; 'biggest': 0.71; 'received:74.208': 0.71; 'reply-to:no real name:2**0': 0.72; 'url:2011': 0.72; 'foreign': 0.72; 'products.': 0.74; 'square': 0.75; 'url:wordpress': 0.75; 'bulk': 0.78; 'are)': 0.84; 'calls,': 0.84; 'enforced': 0.84; 'extreme,': 0.84; 'lightweight': 0.84; 'partially': 0.84; 'presumably': 0.84; 'articles,': 0.91; 'dozen': 0.91; 'seriously,': 0.91; 'trouble.': 0.91; 'angel': 0.93; 'before?': 0.93; 'blog,': 0.93
Date Tue, 27 Nov 2012 00:18:55 -0500
From Dave Angel <d@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121011 Thunderbird/16.0.1
MIME-Version 1.0
To Steven D'Aprano <steve+comp.lang.python@pearwood.info>
Subject Re: How to pass class instance to a method?
References <3193e3dd-0507-4ff7-9026-ee80e5d9c1dd@googlegroups.com> <pan.2012.11.26.16.56.29.389000@nowhere.com> <CALwzidn54ko2AGEj2QmanfFsoUBSqrNJ=TwNjCJt7-+_O2qu-w@mail.gmail.com> <mailman.300.1353967142.29569.python-list@python.org> <50b3eab5$0$29994$c3e8da3$5496439d@news.astraweb.com> <mailman.307.1353986116.29569.python-list@python.org> <50b43d48$0$21875$c3e8da3$76491128@news.astraweb.com>
In-Reply-To <50b43d48$0$21875$c3e8da3$76491128@news.astraweb.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:4/OAc9qfEDbFw8ODGCf5J8KqSJV102+IpJmHRgxz/fF Y4ukMWteEXi/4n8qouSUnZbfMgH5cMI5urF3+Pf4HxtkB2uoBk s9r5k4o0wcRhBtVDcfUEwCIs/whmu7tjmiqwBYyG7VU8cmsfls DFU9bZy6kcUTYCq0RRk/XhmaEscMn5+F31sYloMOi7uvckKqHi SJx7uIzqIjDqeWomvZWjCpEv8HgPozb/0FeslALdtL0H70rEyG wM2s3cZwbh/EBjRQ9q1A7EjLGH0Z1YHys209YDAp1RGcRx/cKu aIDq2H4QEiN61uA8oWCnts2lU3UU/lAvEMRSojHQUN55iIeOA= =
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To d@davea.name
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.309.1353993554.29569.python-list@python.org> (permalink)
Lines 107
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1353993554 news.xs4all.nl 6890 [2001:888:2000:d::a6]:41451
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:33965

Show key headers only | View raw


On 11/26/2012 11:10 PM, Steven D'Aprano wrote:
> On Mon, 26 Nov 2012 22:14:59 -0500, Dave Angel wrote:
>
>> On 11/26/2012 05:18 PM, Steven D'Aprano wrote:
>>> On Mon, 26 Nov 2012 16:58:47 -0500, Dave Angel wrote:
>>>
>>>> In a statically typed language, the valid types are directly implied
>>>> by the function parameter declarations, while in a dynamic language,
>>>> they're defined in the documentation, and only enforced (if at all) by
>>>> the body of the function.
>>> Well that certainly can't be true, because you can write functions
>>> without *any* documentation at all, and hence no defined type
>>> restrictions that could be enforced:
>> That's backwards.  Any body should be a bug in that case.  It doesn't
>> matter what you pass to a function that is unspecified, it's behavior is
>> undefined.  Calling it is inherently illegal.
> Have you ever programmed before? *wink*

I think you know the answer to that.  But for anyone else, I've been in
various aspects of software development for 42 years, longer if you
count various projects which were not turned into products.  And the
approximately dozen patents were nearly all for things which shipped,
not just theoretical concepts.

>
> Seriously, as much as we would like to have full documentation of every 
> piece of code before it is written, such a thing is awfully heavyweight 
> for all but the biggest projects.
>
> In practice, many functions never get documented at all, or only 
> partially documented. Whether this is a good thing or not, it is a fact, 
> and no mainstream language *requires* you to write documentation, nor is 
> the documentation is used to determine runtime behaviour. If it did, it 
> would be code, not documentation.
>
> In lightweight or agile software development methodologies ("Bingo!") or 
> exploratory development, you often write the code before you know what it 
> does, or even what you want it to do. E.g. I'll sometimes have a vague 
> idea of what I want a function or method to do, and go through three or 
> four iterations of writing code before it is stable enough to begin 
> documenting it.
>
> Given the practical reality that documentation is often neglected, there 
> is a school of thought that says that *code* is the One True source of 
> information about what the code does, that documentation is at best a 
> hint or at worst completely redundant. While I think that's a bit 
> extreme, I can see the point. If function f() puts the cat on the mat, 
> but is documented as putting the hat on the cat, how do you know whether 
> the documentation is wrong or the code?
Yes, and yes.  They're both wrong.  Function f() is just broken. 
Especially it's name.

I know all that, and wasn't trying to pretend that documentation is
always or even frequently, adequate.  But the bulk of this part of the
thread has been dealing with a function call, contrasting static typing,
where some work is done by the compiler, and dynamic typing, where
supposedly something is done by the interpreter.  And I claim that the
interpreter cannot in general do anything at the call target, except
count the number of the arguments (maybe) and check the keywords.  So
the only thing that can be done there is manual - check the docs.  If
they're not there, there's just no comparison with the static case.  And
for a non-trivial function, or generally one which calls non-trivial
functions, exhaustively analyzing the code of the function, and of the
function it calls, is impractical.  So people just call the function and
hope.

Static typing isn't nearly enough, and therefore the feeling of security
it gives many is dangerously misleading.  There have been (and
presumably still are) languages which allow subsets of types to be
explicitly declared, for example the type is int, but the restriction is
nonnegative int (eg. square root).  Or the type is int, but the
restriction is between 4 and 7.  Or the parameters have an
interrelationship, or a dependency on the system state: e.g. if the
first parameter is a string, then the second one must be one of 8
specific strings.


>
> [...]
>>> Please, everybody, before replying to this thread, please read this:
>>>
>>> http://cdsmith.wordpress.com/2011/01/09/an-old-article-i-wrote/
>> I read part of it, and it's more than I care to read tonight.  It seems
>> to be written by an anonymous person.  By jumping around in his blog, I
>> see a lot of interesting articles, but i haven't yet figured out who he
>> is.  Does he have a name?  A degree, a job in computers, a reputation?
> Does it matter? Surely what he says should stand or fail on its own 
> merits, not by who he is.

Yes, but since it's very hard slugging at first, I was curious if it
would be worth it.  He uses a number of terms in ways foreign to my
background, and while I admire Humpty-Dumpty-ism, it certainly slows
down comprehension.  Anyway, he's apparently got a reputation with you,
and that alone should make it worth the trouble.  Just not tonight.

> He has a name, although it seems to be hard to find on his current blog: 
> Chris Smith. As for the rest, I don't know.
>
>

One of the brightest people I've ever known is named Smith.  But come to
think of it, that's a pretty common surname.

-- 

DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to pass class instance to a method? ALeX inSide <alex.b.inside@gmail.com> - 2012-11-25 04:11 -0800
  Re: How to pass class instance to a method? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-25 12:37 +0000
  Re: How to pass class instance to a method? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2012-11-26 11:22 +1300
  Re: How to pass class instance to a method? Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2012-11-26 11:08 +0100
  Re: How to pass class instance to a method? Nobody <nobody@nowhere.com> - 2012-11-26 16:56 +0000
    Re: How to pass class instance to a method? Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-26 13:51 -0700
    Re: How to pass class instance to a method? Dave Angel <d@davea.name> - 2012-11-26 16:58 -0500
      Re: How to pass class instance to a method? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-26 22:18 +0000
        Re: How to pass class instance to a method? Dave Angel <d@davea.name> - 2012-11-26 22:14 -0500
          Re: How to pass class instance to a method? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-27 04:10 +0000
            Re: How to pass class instance to a method? Roy Smith <roy@panix.com> - 2012-11-26 23:25 -0500
            Re: How to pass class instance to a method? Dave Angel <d@davea.name> - 2012-11-27 00:18 -0500
    Re: How to pass class instance to a method? Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-26 16:07 -0700
      Re: How to pass class instance to a method? Hans Mulder <hansmu@xs4all.nl> - 2012-11-27 01:36 +0100
    Re: How to pass class instance to a method? Dave Angel <d@davea.name> - 2012-11-26 21:50 -0500
  Re: How to pass class instance to a method? Drew <r.drew.davis@gmail.com> - 2012-11-26 17:14 -0800

csiph-web