Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^5: How will you use state declared variables in Perl6?

by TimToady (Parson)
on Jul 08, 2005 at 22:44 UTC ( #473598=note: print w/ replies, xml ) Need Help??


in reply to Re^4: How will you use state declared variables in Perl6?
in thread How will you use state declared variables in Perl6?

Nah, it's only surprising if foo doesn't know it's a method. Methods should never be surprised by being inherited. And Perl 6 methods always know they're methods because they have their own keyword. If foo doesn't properly manage its own state, that foo's problem, not anyone else's.


Comment on Re^5: How will you use state declared variables in Perl6?
Select or Download Code
Re^6: How will you use state declared variables in Perl6?
by BrowserUk (Pope) on Jul 08, 2005 at 22:49 UTC

    Okay. How will a method know how to segregate the management of a state var under inheritance?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
      Why should it have to "segregate", unless you have a busted inheritance hierarchy that doesn't actually represent ISA relationships?

      That being said, if you want to prevent the method itself from being called on behalf of an object of a derived class, just call it a submethod instead, and then the derived class will have to define its own version of the submethod that will presumably refer to its own class attributes. I suspect that in general most class attributes are of interest only to infrastructural methods like constructors and initializers and destructors, and most of those should be submethods in the first place.

      If a method ever has to ask what the actual type of its invocant it, it's usually a clue that something is seriously wrong in the design of either the program or the language. It's the dispatcher that should be making those kinds of decisions before your method is ever called. Perl 6 provides several degrees of freedom in the dispatcher to help you keep that sort of infrastructural spaghetti out of your methods.

      Of course, we won't prevent you from examining the actual type of the invocant if you really want to...

        Why should it have to "segregate", unless you have a busted inheritance hierarchy that doesn't actually represent ISA relationships?

        I was trying to think of a use for state. The potential use I thought of was counting instances of a class--Probably better served by a Class variable anyway--but it could be used that way until inheritance is involved at which point it gets iffy whether instances of the subclass are instances of the class. But forget that as there are better ways of doing it.

        That leaves the question, what is a good use for state vars, which is probably the question Limbic~Region was asking in the first place.

        My summation of the information you provided in this thread is that state vars are basically the same as closures, except that you can declare their scope from within the scope they are to be closed over, rather than having to declare them outside that scope in order for the sub(method/submethod) to close over them.

        Is that a reasonable definition?


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://473598]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2014-08-27 23:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (253 votes), past polls