Raku and the (Re)blessed Child

by Arne Sommer

Raku and the (Re)blessed Child

[56] Published 12. February 2020

Why doesn't «rebless» work in Raku anymore?

See also Part 2: Exploring Rebless with Raku for sample code.

Back in 2018 I started working on a Raku (or Perl 6 as the language was called then) course and accompanying textbook. My aim for the book is to cover as much as possible of the language, so the chapter on Object Oriented programming has a section about «rebless».

The official documentation [1] did not really explain it. Googling («perl6 rebless») revealed that brian d. foy had asked a question about it on Stackowerflow in 2017 [2]. The answer he got helped me as well, and I wrote the section with a program showing how it could be used in practice.

For some reason I ran the «rebless» program again in January this year, but now it didn't work. The official documentation [1] was still as unhelpful as before. So I created a new Stackowerflow question [3], and got replies. None of them correct, until Jonathan spilled the beans.

He had rewritten the «rebless» code, and removed the functionality that had been described for brian. The removed functionality was not part of the official Raku test suit, and thus not part of the official language definition. So he argues that it was ok to change it.

That may be technically correct, but it isn't nice to any users of that functionality. I had code that worked when I wrote it, and that had stopped working without any prior warning. Yes, it was just sample code in a book, so the damage was minimal. For me. But anybody reading my book and trying it out would be in for a nasty surprise.

Programmers look up features in books and articles, and not just the official documentation. And when they find code snippets that work, they use them - regardless of what the official documentation may or may not have to say about it. This is a problem that will increase as Raku is more widely used, as we all hope for.

This is not meant as criticism. I know that Raku is developed by volunteers, and I appreciate the time they spend on developing the language. But breaking changes should be mentioned in the official documentation. This is important when there are articles out there with code that doesn't work anymore. When that happens we surely want the users to consult the official documentation. And find the answer.

I am prepared to contribute with the documentation, if there is interest. Tutorials (more of them) may be the way to go, but I don't know. I'll at least keep updating and revising my Beginning Raku book. (The «rebless» section will be updated in the next release; v.1.04).

I worked on a more complicated example, and had to create another Stackoverflow question [4] for help. The answer was quite obvious in hindsight, but that's life. The nice thing about the Raku community is that I got the answer I needed.

The fact that «rebless» is not available on the object itself (e.g. «$object.rebless(New-Class)», but through the convoluted «Metamodel::Primitives.rebless($object, New-Class)» syntax should give a hint that this is something that probably isn't meant for everyday usage.

See also Part 2: Exploring Rebless with Raku for sample code.

References

  1. docs.raku.org/routine/rebless»
  2. brian d. foy's Stackowerflow Question
  3. My first Stackowerflow Question
  4. My second (followup) Stackowerflow Question