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

Objects without stashes?

Thread Next
Leon Timmermans
May 25, 2012 07:54
Objects without stashes?
Message ID:
I hate the way classes/objects work. In particular, I think stashes of
globs of other stuff is paradigm that fails, and I don't think I stand
alone in that. We all know how much effort it is to work with them,
even when abstractions are available that make them less inconvenient.
It makes me wonder why we're sticking to it so badly? Perl has always
had a very minimalistic definition definition of what an object is. To
quote perltoot:

> An object is different from any other data type in Perl in one and only one way: you may dereference it using not merely string or numeric subscripts as with simple arrays and hashes, but with named subroutine calls. In a word, with methods.

There is nothing, absolutely nothing, about this that requires stashes
(or for that matter, there's nothing that requires packages/classes
either). What if we simply added a vtable to all objects when
blessing? At its minimal, this vtable would only need to support two
methods: fetchmethod and ref, though more may be prudent (meta would
be an obvious one, clone and destroy may be useful too). I think this
would allow us to add new paradigms in a sensible and extensible way,
without breaking too many other things.


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About