Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #99869
| From | Antoon Pardon <antoon.pardon@rece.vub.ac.be> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: static variables |
| Date | 2015-12-02 12:09 +0100 |
| Message-ID | <mailman.118.1449054600.14615.python-list@python.org> (permalink) |
| References | (5 earlier) <565e4329$0$1612$c3e8da3$5496439d@news.astraweb.com> <mailman.97.1449019041.14615.python-list@python.org> <565e4861$0$1587$c3e8da3$5496439d@news.astraweb.com> <mailman.104.1449045275.14615.python-list@python.org> <565ec669$0$1586$c3e8da3$5496439d@news.astraweb.com> |
Op 02-12-15 om 11:22 schreef Steven D'Aprano: > On Wed, 2 Dec 2015 07:34 pm, Antoon Pardon wrote: > >> Op 02-12-15 om 02:24 schreef Steven D'Aprano: >>> Heh, I agree, and as I suggested, it might be good to have an actual >>> mechanism for static locals. But using a class is no better: your "static >>> storage" is exposed as an instance attribute, and even if you flag it >>> private, *somebody* is going to mess with it. >> Why don't you invoke the consenting adults now? > Because I don't wish to. > > I can invoke consenting adults to defend people drinking soft drinks and > eating chocolate, doesn't mean I have to invoke consenting adults to defend > the practice of middle-class film-makers goading homeless people into > fighting and other dangerous acts for trivial amounts of money. > > https://en.wikipedia.org/wiki/Bumfights If you want your arguments to be taken seriously, then you better should. If you use an argument when it suits you and ignore it when it doesn't you are showing you don't really have an argument. You are just showing your preference and making it sound like an argument. >> People have come here >> arguing for all kind of extra features, which would somehow defend >> against messing with certain variable or attributes the author wants >> protected. The general respons has always been, that we are consenting >> adults here. > Yes, and that's fine. Consider the word *judgement* -- in our (the > collective community) judgement, certain things are acceptable for > consenting adults and others are not. Which makes "consenting adults" just empty posturing that means nothing more than /we like it that way/ or /we don't have a problem with that./ > But if it makes you feel better, if I were to champion this feature, I would > suggest that the initialised static variable be stored in a writable dunder > attribute of the function, just like default values are today. If you > wanted to inspect, or even modify, the static variables, you could access > function.__static__[x]. > > >> Static variables, are just a feature to protect what is essentially >> a global variable against messing from somewhere else. > No, that's not the reason for static variables. The primary reasons for > static variables are efficiency and encapsulation. No it isn't. Global variables are just as efficient and encapsulation is just one means to protect a variable against messing. Efficiency: consider a function that requires a considerable amount of initialisation, which only needs to be done once. In older languages like Pascal which lack static variables, you might perform that initialisation every time you call the function. Or, you might break encapsulation by storing something that belongs with the function outside the function. Static variables let you have your cake and eat it too: you can keep the variable with the function, avoiding namespace pollution, which still allowing the efficiency of having that variable calculated once only. >> So why is >> this feature worthy of discussion and others are not? > Because I say so. Since it's my suggestion, that's the only reason I need. > > >
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
static variables Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-11-30 17:15 +0000
Re: static variables Terry Reedy <tjreedy@udel.edu> - 2015-11-30 12:38 -0500
Re: static variables BartC <bc@freeuk.com> - 2015-11-30 20:32 +0000
Re: static variables Steven D'Aprano <steve@pearwood.info> - 2015-12-01 12:01 +1100
Re: static variables Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-12-01 08:26 +0000
Re: static variables Peter Otten <__peter__@web.de> - 2015-12-01 10:01 +0100
Re: static variables Grobu <snailcoder@retrosite.invalid> - 2015-12-01 10:15 +0100
Re: static variables Steven D'Aprano <steve@pearwood.info> - 2015-12-02 12:02 +1100
Re: static variables Erik <python@lucidity.plus.com> - 2015-12-02 01:16 +0000
Re: static variables Steven D'Aprano <steve@pearwood.info> - 2015-12-02 12:24 +1100
Re: static variables Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-12-02 09:21 +0100
Re: static variables Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-12-02 09:34 +0100
Re: static variables Steven D'Aprano <steve@pearwood.info> - 2015-12-02 21:22 +1100
Re: static variables Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-12-02 12:09 +0100
Re: static variables Steven D'Aprano <steve@pearwood.info> - 2015-12-03 00:11 +1100
Re: static variables Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-12-02 14:41 +0100
Re: static variables Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-12-02 13:48 +0000
Re: static variables Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-12-02 15:07 +0100
Re: static variables Ian Kelly <ian.g.kelly@gmail.com> - 2015-12-02 08:15 -0600
Re: static variables Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-12-02 14:31 +0000
Re: static variables Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-12-02 16:30 +0100
Re: static variables Ian Kelly <ian.g.kelly@gmail.com> - 2015-12-02 14:30 -0600
Re: static variables Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-12-03 10:06 +0100
Re: static variables Chris Angelico <rosuav@gmail.com> - 2015-12-02 20:23 +1100
Re: static variables Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-12-02 10:47 +0100
Re: static variables Marko Rauhamaa <marko@pacujo.net> - 2015-12-02 12:18 +0200
Re: static variables Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-12-02 11:56 +0100
Re: static variables Marko Rauhamaa <marko@pacujo.net> - 2015-12-02 13:30 +0200
Re: static variables Steven D'Aprano <steve@pearwood.info> - 2015-12-03 00:17 +1100
Re: static variables Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2015-12-01 10:58 +0100
Re: static variables Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-12-01 11:47 +0000
csiph-web