[Tutor] R: Re: Re: Re: Class learning

Cameron Simpson cs at zip.com.au
Sat Jan 24 21:20:18 CET 2015


On 24Jan2015 15:03, Mark Lawrence <breamoreboy at yahoo.co.uk> wrote:
>On 24/01/2015 01:50, Cameron Simpson wrote:
>>My intuition is that a function is costly (potentially) and that
>>consulting an attribute is very cheap.  I don't want to break such
>>intuition.
>
>It's not just your intuition, it's a fact.  Function calls are costly, 
>relative to attribute lookup that is, at least in cPython.  I've no 
>idea what the impact is in other implementations.  I'd guess that 99% 
>of the time 99% of Python programmers needn't worry about it.

Like Alan, you've missed my intent here.

To quote from my reply to Alan:

  I am not referring to the overhead of making a function call, but the
  intuitive cost that distinguishes something one thinks of as an attribute from
  something one thinks of as a function: a function may entain an arbitrary
  amount of work whereas an attibute is almost free, and constant in cost.

  I'm not talking about optimisation here, I'm talking about the notion of a
  value that is derived from (unspecified and perhaps costly) computation versus
  a value that is merely stored, and trivially retrieved.

  The an attribute/method/function very closely resembles the latter, I am prone
  to make it into a property.

Cheers,
Cameron Simpson <cs at zip.com.au>

On two occasions I have been asked [by members of Parliament],
'Pray, Mr. Babbage, if you put into the machine wrong figures, will
the right answers come out?'  I am not able rightly to apprehend the
kind of confusion of ideas that could provoke such a question.
        - Babbage


More information about the Tutor mailing list