develooper Front page | perl.perl5.porters | Postings from July 2012

Re: Objects without stashes?

Thread Previous | Thread Next
From:
Jesse Luehrs
Date:
July 13, 2012 14:55
Subject:
Re: Objects without stashes?
Message ID:
20120713215452.GF30375@tozt.net
On Fri, Jul 13, 2012 at 02:25:27PM -0700, Rev. Chip wrote:
> On Thu, Jul 12, 2012 at 10:43:01PM -0500, Jesse Luehrs wrote:
> > On Thu, Jul 12, 2012 at 08:09:31PM -0700, Rev. Chip wrote:
> > > On Fri, May 25, 2012 at 04:47:17PM +0200, Leon Timmermans wrote:
> > > > I hate the way classes/objects work. In particular, I think stashes of
> > > > globs of other stuff is paradigm that fails ...
> > > 
> > > At the micro change level, how about just allowing arbitrary hash refs as
> > > stashes?  Seems like any self-respecting MOP would need that anyway, and
> > > it's a useful feature for anyone doing mixins.
> > 
> > On the one hand, any implementation of a MOP that actually works well is
> > not going to have any interaction with stashes at all (the indirection
> > of going through typeglobs is unnecessary and just slows things down and
> > complicates things for no reason - all MOP-based classes would need is a
> > map of methods).
> 
> I didn't use the term "stash" or "glob", and that was on purpose.  I would
> like to see this work, where the RHS of bless is a simple hash that stays
> simple:
> 
>     bless [0], { inc => sub { ++$_[0][0] },
>                  dec => sub { --$_[0][0] },
> 		 DESTROY => sub { print "BYE\n" } };
> 
> and I don't see why that isn't both easy and helpful today, even before
> p5-mop is ready.  Supporting overloading might be tricky if it's not a
> stash, I'll grant you, but I'm sure it's feasible.

Blessing things into something that's not a stash would be a lot more
effort. Currently, a real stash that holds { inc => sub { ... } } would
be interpreted as inc holding a constant subroutine which returned a
coderef. Changing the meaning like this would mean that we would have to
switch on "real stash" vs "anonymous stash" everywhere we currently
interact with a stash, which would be a pretty serious pain. I liked the
original idea where anonymous stashes were structured exactly like
something you'd get from \%Foo:: (typeglobs and everything), because
that would be an incredibly trivial change.

-doy

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About