Default Value

Chris Angelico rosuav at gmail.com
Fri Jun 21 03:10:49 EDT 2013


On Fri, Jun 21, 2013 at 1:16 PM, Rick Johnson
<rantingrickjohnson at gmail.com> wrote:
> On Thursday, June 20, 2013 7:57:28 PM UTC-5, Steven D'Aprano wrote:
>> Python functions are
>> created *once*, when defined. The cost of building the
>> function -- compiling the source code to byte code,
>> assembling the pieces into a function object, binding it
>> to a name -- happens once and once only, not every time
>> you call the function. So it is reasonable to expect that
>> since the function is defined once, so are any default
>> arguments.
>>
>
> Here you go again with this diversionary tactics! Of course
> the function is only compiled once! Anything else would be
> ludicrous. PAY ATTENTION! I'm not arguing that the damn
> function should be compiled each time it's called, no, i am
> arguing that each call to a subroutine should be a UNIQUE
> TRANSACTION. That means that no state can be carried from
> one transaction to another.

Why should that be? Why is a subroutine not allowed to retain any state?

You're free to write code in a purely functional style if you like -
all objects must be immutable, all functions must have no side effects
and simply return a value. That's not the only way to code, and it is
*definitely* not a rule to be codified into Python. One of Python's
strengths is that it permits many styles of programming, without
shoehorning every programmer and every task into one model.

Of course, RickPy 4000 is welcome to enforce all these sorts of inane
rules if it likes. I shan't be using it if it does.

ChrisA



More information about the Python-list mailing list