This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author esegall
Recipients docs@python, esegall, rhettinger
Date 2016-04-25.17:08:47
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1461604127.51.0.101130929166.issue26842@psf.upfronthosting.co.za>
In-reply-to
Content
I agree with most of your points: A tutorial should be brief and should not go down rabbit holes. Expanded discussion of default parameter behavior would probably fit better with the other facets of parameter speceification and parameter passing, perhaps as a FAQ. 

But I also believe a change to the current presentation is needed. Perhaps it would be best to introduce default arguments using simple numerical types, and refer to a separate explanation (perhaps as a FAQ) of the complexities associated with using mutable objects as defaults. 

> Also, I don't really like the provided explanation, "there are two cases ...".  The actual execution model has one case (default arguments are evaluated once when the function is defined) and there are many ways to use it.

The distinction between the two cases lies in storage of the result, not in argument evaluation. In the non-default case, the result is stored in a caller-provided object, while in the default case, the result is stored in a callee-provided object. This results in different behaviors (as the example makes clear); hence the two cases are not the same. 

This distinction is important to new users because it's necessary to think of them differently, and because (to me, at least) one of them is very non-intuitive. In both cases, the change made to the object is a side effect of the function. In the non-default case, this side effect is directly visible to the caller, but in the default case, it is only indirectly visible. 

Details like this are probably obvious to people who are very familiar with both call by object reference and to Python's persistent lifetime of default argument objects, but I don't think that group fits the target audience for a tutorial.
History
Date User Action Args
2016-04-25 17:08:47esegallsetrecipients: + esegall, rhettinger, docs@python
2016-04-25 17:08:47esegallsetmessageid: <1461604127.51.0.101130929166.issue26842@psf.upfronthosting.co.za>
2016-04-25 17:08:47esegalllinkissue26842 messages
2016-04-25 17:08:47esegallcreate