Object Oriented Perl Q: Why 'bless'?

I’m just learning oriented Perl at present, and today the ‘bless’ command was introduced for marking an object as belonging to a class.

Everyone was bemused by it–it’s such an odd name for a command. Does anyone know the background of why it’s called that?

Because Larry said so.

The history of Perl includes lots of cheap hacks and kludges to get something working without necessarily doing some proper, official design or engineering. Many such idiosyncratic features are simply referred to as magic. Around the time when Larry and co. were developing Perl 5, they realized that having references (a.k.a. pointers) and objects would be need. Rather than engineer an entire OOP system, they added a magic flag to the data structure for a reference that would make it behave like an object. How do you turn the magic on? You bless it. So there you go.

There’s no magic to it, it’s just an artifact of Perl’s pseduo-OOP behavior in that a normal data structure is elevated from a mere mundane scalar/array/hash to a member of class SuchAndSuch. ‘Bless’ is a fairly apt description with a nice poetic flair, but it could have been called ‘promote’, ‘specialize’, ‘knight’, ‘tap’, etc. In fact, you could easily one of those instead if you like.

My immediate thought was “whoever called it this must have been an RPG player.”–that kinda tallies with friedo’s response.

Programming has traditionally used magical/supernatural terms as humourous metaphors.

Daemons, sprites, pixels, etc.

Larry is also a religious person, unlike a lot of hackers, and he makes no attempt to hide this. He doesn’t promote it, either, but it’s easy to glean from his various and varied writings. With that in mind, it’s pretty easy to see how he’d associate the granting of special powers with blessing.

And, yes, Perl 5’s OO is ugly and bolted-through and more than enough to make a Smalltalker wish for Ruby. But Perl in general is ugly and idiomatic and a lot more concerned with doing the common things quickly than being elegant or small. Which is why I like it so well. :wink: