RFC 307, by Simon Cozens

In a context with apocalypses and exegeses, no wonder there’s also a PRAYER somewhere: precisely in this RFC 307, by Simon Cozens, which was actually rejected, but somehow ended up anyway in Apocalypse 12 together with the one it that superseded it, RFC 189. Both proposals talk about what is going ot happen when an object is created, an action that has traditionally been called blessing in the Perl world.

So let’s get first to the rejected one, which is simpler. It says

This RFC proposes a special sub, PRAYER, which is automatically called on blessing.

The term blessing is Perlese for welcoming a data structure into the object world. In Perl objects are little more than hashes with a tag tacked on them, so you bless a data structure with the class it’s going to belong to. However, that’s pretty static, and it’s only sticking together two pieces of data:

my %foo = bless { bar => "baz" }, "Foo";
say %foo; # Foo=HASH(0x1b05558)

Not even a formal definition of a package (again, Perlese for classes) or attributes or whatever are needed. But imagine we need to ensure the data structure includes a certain attribute, or need to create an additional one from existing attribute values. Well, use one of the existing object orientation packages such as Moo. Moose even has per-attribute triggers, that can be used to check them once they have been set. But really not an object-wide C.

So we really need one. And we need one WITH CAPITAL LETTERS because that’s how we call the IMPORTANT things, or actually the things that happen under the hood when we do something. Perl already does have a few of those. UNIVERSAL is the ur-class (we call it Mu in Raku). That class includes DOES and VERSION; there’s also AUTOLOAD which is called when a method does not exist in a class, as well as DESTROY.

Other RFCs, recently commented, proposed other seudo-classes that used capital leters: NEXT, for instance.

This last method is interesting: it’s called at a certain phase in the object lifecycle; at the very end of it, namely.

Ob-pun about the mixed metaphor of objects starting their life with a blessing and ending with simple destruction.

So Perl had a single phaser. This RFC advocated for getting, at least, a couple of symmetric ones, at both ends of the object lifecycle. Which was precisely in the turf of RFC 189, which proposed a set of hierarchical BUILD (lost chance to call them INCEPT) and DESTROY calls, invoked up and down the object inheritance chain.

Which is why this RFC was rejected, I guess. However, this RFC goes a little beyond that, or sideways from that, so it made sense to pick it up for the apocalypsis 12, instead of subsuming it into 189. In a way, BUILD is what it asks for off the bat: it’s the “prayer” that gets called from bless. But rephrase it slightly, “what’s called when something has been blessed” and it becomes something totally different: not a building routine, but a, wait for it, tweaking routine (or method, or submethod, which is what it eventually became).

In this way, Raku got TWEAK. RFC 189 begat BUILD, which creates a nice and bundled object. But after this object has been created, and it’s solidly wrapped into a self data structure, you might still need to TWEAK it, and do stuff that can only be done when and if the object is already BUILT. This is what TWEAK is for. And it can be put to good use in cases like checking if the constructor has been called with an unexisting attribute (which uses the self variable to grab all existing attributes), or to register self with some external object, or, actually, anything you might want to do with an object that has been aready blessed.

This also says something about the process that created Raku; an RFC that was rejected eventually ended up as an useful, and interesting, feature of the final language. Because, in the true open source spirit, with many eyes all bugs are shallow, and also many eyes look stuff all over again and find its real worth and meaning. Which is what you need when designing a 100 year language, I guess.

Published by jjmerelo

Servidor de ustedes

One thought on “RFC 307, by Simon Cozens

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: