Re: Re: names for init block keywords?
"Mark Hahn" <[email protected]>
| Newsgroups | gmane.comp.lang.prothon.user |
|---|---|
| Message-ID | <002901c467b3$3836aa10$0d01a8c0@MarkVaio> |
Paul Prescod wrote: > In object oriented programs I find it very seldom the case that I need > to do something on the first run of a function. For example your > example is just as easily written: > > def func(): > """function to solve all the world's problems""" > after: > func = turbocharge(func) > func.staticVar = 0 > > func.staticVar += 1 I actually got the need for "once" from a c.l.p. thread. Several claimed the need for it. It is not only the difference in timing but the difference in scope. Don't forget that "after" is in the outer scope and "once" is in the function scope. You are right though that it is only replacing an if statement whereas the "after" keyword is filling a more fundamental gap. > The only time it would matter is if the code in the once block had > side effects and they really couldn't happen yet but could only > happen later. Seems pretty rare to me and easily handled with static > variables. > > Not big on the keyword name "after". > > "init:" or "initialize:" might be better. I think "init" would be confused with "init_" which would usually be near there. The concepts are dangerously close to begin with. How about "outer:" ? It is already a keyword and it means the outside scope which this code runs in. I like that.