Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Antoon Pardon Newsgroups: comp.lang.python Subject: Re: What is a function parameter =[] for? Date: Tue, 24 Nov 2015 15:58:12 +0100 Lines: 72 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> <565139f0$0$1598$c3e8da3$5496439d@news.astraweb.com> <5652c4ac$0$1621$c3e8da3$5496439d@news.astraweb.com> <56531ba1$0$1597$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de z0qF8znYR+GPbb3AVLlX9gYBS15zZpOYYImHcRbpeL1Q== 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; 'python,': 0.02; 'static': 0.03; 'defaults': 0.05; 'feature.': 0.07; 'mutable': 0.09; 'replied': 0.09; 'storage.': 0.09; 'python': 0.10; 'python.': 0.11; 'syntax': 0.13; 'def': 0.13; 'missed': 0.15; 'variables': 0.15; 'argument.': 0.16; 'b):': 0.16; 'better?': 0.16; 'cleaner': 0.16; 'cleanly': 0.16; 'closures': 0.16; 'effect,': 0.16; 'hypothetical': 0.16; 'received:adsl-dyn.isp.belgacom.be': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'rough': 0.16; 'simulate': 0.16; 'third,': 0.16; 'variables:': 0.16; 'wrote:': 0.16; 'abuse': 0.18; 'variable': 0.18; '>>>': 0.20; '2015': 0.20; 'referring': 0.22; 'am,': 0.23; 'code.': 0.23; 'header:In-Reply- To:1': 0.24; 'feature': 0.24; 'mon,': 0.24; 'header:User-Agent:1': 0.26; 'parameters': 0.27; 'function': 0.28; 'idea': 0.28; 'received:192.168.1.3': 0.29; 'storage,': 0.29; 'url:wikipedia': 0.29; 'url:wiki': 0.30; 'code': 0.30; 'received:be': 0.30; 'statement': 0.32; 'maybe': 0.33; 'point': 0.33; 'class': 0.33; "d'aprano": 0.33; 'science,': 0.33; 'steven': 0.33; 'surely': 0.33; 'exist': 0.35; 'nov': 0.35; 'something': 0.35; 'but': 0.36; 'should': 0.36; 'instead': 0.36; 'url:org': 0.36; 'to:addr:python- list': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'two': 0.37; 'agree': 0.37; 'turn': 0.37; 'no,': 0.38; 'why': 0.39; 'url:en': 0.39; 'enough': 0.39; 'received:192': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'future': 0.60; 'your': 0.60; 'default': 0.61; 'telling': 0.61; 'today,': 0.62; 'charset:windows-1252': 0.62; 'skip:n 10': 0.62; 'more': 0.63; 'between': 0.65; 'said:': 0.66; 'course.': 0.67; 'intelligent': 0.76; 'bang': 0.84; 'borrow': 0.84; "d'aprano:": 0.84; 'galileo,': 0.84; 'misses': 0.84; 'received:195.238': 0.84; 'schreef': 0.84; 'desk.': 0.91; 'serious': 0.97 X-Belgacom-Dynamic: yes X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2CWAQAoelRW/9Xi9VENUYQOwgojhWwCgXYQAQEBAQEBAYU/AQEEeBELGAkWDwkDAgECAUUTCAKILwitOIx6hCYBAQEBBgEBAQEbBIZUhH6ERGOEEgWWUIUkiA2BW5Z+g3I4gjwdgVeEU4FJAQEB User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.8.0 In-Reply-To: <56531ba1$0$1597$c3e8da3$5496439d@news.astraweb.com> 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:99349 Op 23-11-15 om 14:58 schreef Steven D'Aprano: > On Mon, 23 Nov 2015 09:40 pm, BartC wrote: > >> On 23/11/2015 07:47, Steven D'Aprano wrote: >> >>> I think it would be cleaner and better if Python had dedicated syntax for >>> declaring static local variables: >> >> Interesting. So why is it that when /I/ said: >> >> > On Mon, 23 Nov 2015 12:21 am, BartC wrote: >> > >> >> But if it's used for static storage, then why not just use static >> >> storage? >> >> You replied with the insulting: >> >> > /head-desk >> >> ? >> >> Maybe it's my turn to bang my head on the desk. > > Let me steal^W borrow an idea from Galileo, and present the explanation in > the form of a dialogue between two philosophers of computer science, > Salviati and Simplicio, and a third, intelligent layman, Sagredo. > > https://en.wikipedia.org/wiki/Dialogue_Concerning_the_Two_Chief_World_Systems > > > Salviati: Function defaults can also be used for static storage. > > Simplicio: If you want static storage, why not use static storage? > > Salviati: Function defaults in Python *are* static storage. > > Although they not the only way to get static storage, as closures can > also be used for that purpose, they are surely the simplest way to get > static storage in Python. > > Sagredo: Simplest though it might be, surely a reasonable person would > consider that using function parameters for static storage is abuse of the > feature and a global variable would be better? > > Salviati: Global variables have serious disadvantages. I will agree that > using function parameters for static storage is something of a code smell, > but good enough for rough and ready code. Nevertheless, it would be good if > Python had dedicated syntax for static storage. > > Simplicio: Ah-ha! Gotcha! > > Salviati: No, perhaps you missed that I was referring to a hypothetical > future addition to Python, not a current feature. But even if it did exist > today, your statement misses the point that by using function defaults I > *am* using static storage. In effect, you are telling me that rather than > using static storage I should instead use static storage. If you really want mutable static storage, you can simulate it more cleanly with a closure than using a default argument. def factory(): static_dict = {} def myfunc(a, b): mutate static_dict as much as you like return myfunc myfunc = factory() Or you can use a class of course.