On Thu, May 28, 2020 at 07:00:51PM +1200, Greg Ewing wrote:
> On 28/05/20 12:38 pm, Rob Cliffe wrote:
> >why not go further (as the OP suggested as far as I recall)
> >and allow the more concise
> >
> >     def order(eggs = 4, spam ?= Spam()):
> >         etc.
> 
> That clutters up the header with things that are not part of
> the function's signature. All the caller needs to know is that
> the spam argument is optional. 

I don't think you thought that through all the way.

"All I need to know is that the mode argument to `open()` is optional, I 
don't need to know whether it defaults to read or write..."

I don't think so.


> The fact that a new Spam object
> is created on each call if he doesn't supply one is an
> implementation detail.

Being an implementation detail implies that the functional behaviour 
will be identical either way, but that's incorrect under at least four 
circumstances:

- Spam objects are mutable, e.g. lists, dicts, set;

- calling Spam has side-effects;

- calling Spam is particularly costly;

- or if the result of calling Spam depends on the current state of 
  the runtime environment, e.g. anything time dependent, anything 
  to do with the state of the file system or a database, etc.


The default value used by a parameter is certainly important, and one of 
the most common reasons I call `help(func)` is to see what the default 
values are. They should be in the signature, and it is an annoyance when 
all the signature shows is that it is None, and then I have to trawl 
through screenfuls of docs, or search the web, to find out what the 
actual default is.


-- 
Steven
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/IL3K5G2K4Y752HQKA26EEZCIGNOT56P4/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to