Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: What is a function parameter =[] for? Date: Sat, 21 Nov 2015 03:24:07 +1100 Lines: 31 Message-ID: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <877flcrh26.fsf@elektro.pacujo.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de ZBIZMxv1vAFkmRMfGne/3Qz87aZrSfZ8b4PI/cqatWeA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '21,': 0.07; 'cc:addr :python-list': 0.09; '*args': 0.09; 'semantics': 0.09; 'def': 0.13; 'explicitly': 0.15; 'value.': 0.15; 'cc:name:python': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'magic': 0.16; 'notation,': 0.16; 'omitted,': 0.16; 'overloaded': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'sentinel': 0.16; 'values:': 0.16; 'why,': 0.16; 'wrote:': 0.16; "shouldn't": 0.18; 'try:': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'proposed': 0.20; 'explicit': 0.22; 'pass': 0.22; 'am,': 0.23; 'sat,': 0.23; 'header:In-Reply-To:1': 0.24; 'compare': 0.27; 'message-id:@mail.gmail.com': 0.27; 'data,': 0.27; 'values': 0.28; 'actual': 0.28; '"no': 0.29; 'argue': 0.29; 'omitted': 0.29; 'allows': 0.30; "can't": 0.32; 'usually': 0.33; 'values.': 0.33; 'except': 0.34; 'received:google.com': 0.35; 'ones': 0.35; 'could': 0.35; 'c++': 0.35; 'nov': 0.35; 'but': 0.36; 'should': 0.36; 'received:209.85': 0.36; 'possible': 0.36; 'cases': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'represent': 0.38; 'rather': 0.39; 'where': 0.40; 'default': 0.61; 'more': 0.63; 'between': 0.65; 'state,': 0.66; 'chrisa': 0.84; 'distinguish': 0.84; 'to:none': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=naWtVuXm6qGndUsLS2Fh7VGhQfhC5IvC4FsbdfXq6zg=; b=VSrXYvdyHzNMLD+94C+/EwLXz7xpNmZ90z+ymUy94zfE8f8R40NgRG2GJHXR+73cSy C5nxnfSQCrJhBLaFYwhp6dwkFfBocU6NNpBoFc5QECOoQPKIrfXFHN0fXMDySxmFA5nz O7IDR7p7H9jn4cAxPE7ZEA/wtH2kV/Gwesxf2C/dJE7u83cpH+ECU91K91JTzBjhmjmm p5gaYApQVURTB5Y/0X91kvxqJYnoHEuYrxQHe208OyTKCkuhdYRVYg2Gh1EmVwVpGkpV lTlzsMtWUOIERZp/flxKKshtfw2YkpULaI/uDdIG/Vnsy9WTBMROq7+ubNLdIAjKmjG6 Xvow== X-Received: by 10.50.225.38 with SMTP id rh6mr771166igc.13.1448036647818; Fri, 20 Nov 2015 08:24:07 -0800 (PST) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:99163 On Sat, Nov 21, 2015 at 3:16 AM, Ian Kelly wrote: >> One could argue that you should always use a sentinel object for default >> values. That also allows you to distinguish between omitted values and >> default values: >> >> def asklist(caption, data, n=omitted, rows=omitted, width=omitted, >> flags=omitted, buttons=omitted, tablist=omitted, >> heading=omitted): >> >> but that would be rather pedantic in most circumstances. > > I think that would be bad design; in general, you shouldn't *need* to > distinguish whether the value was omitted, because it should always be > possible to explicitly pass the default value. The cases where that's not true are usually ones that are more like C++ overloaded functions: def next(iter): return iter.__next__() def next(iter, default): try: return iter.__next__() except StopIteration: return default You cannot have any actual object to represent the default state, for the same reasons that you can't have __next__ return a magic value to represent "no more values". That's why, in the proposed semantics for an explicit late-binding syntax, I compare with *args notation, which _can_ let you distinguish perfectly. ChrisA