This is a very old article. It has been imported from older blogging software, and the formatting, images, etc may have been lost. Some links may be broken. Some of the information may no longer be correct. Opinions expressed in this article may no longer be held.
As you may be aware, I’m writing a book which will eventually become a free e-book. This is my third report on how I’m getting along.
If you’ve been paying attention, you might have noticed a distinct lack of CPAN activity from me lately. Well I had a cold for a while, and a few other things that put me behind on a bunch of other projects which had to take priority over open source stuff. I hope to be back with a bang in January 2015!
In the mean time I have started work on the book chapters which introduce objects and classes which I’m sure you’ll agree are two fairly vital topics for object-oriented programming.
One slightly novel approach I’m trying to take is to emphasise the object-oriented part of object-oriented programming. Objects are the main topic, not classes. Conceptually you can create and use objects without bothering much with classes – for example, by composing a bunch of roles and then instantiating an object from that. OK, so internally what Moose/Moo is doing underneath is creating a class which does all those roles, but from the programmer’s perspective Moose/Moo enables quite classless object-oriented programming.
Which is not to say that classes are unimportant, and will not be covered. Of course they’ll be covered. But I’m trying to introduce objects first. How they are passed by reference; how methods are called; and so forth. All that before I cover writing classes, and before I cover writing roles.
Right now I am writing examples like:
my $A = get_some_object();
my $B = $A;
$A->set_value(20);
say $B->get_value();
… which yes, covers the concepts I want to cover, but feels quite contrived. It’s hard to cover these ideas without having to also mention, say, constructors, which I don’t want to introduce until the next chapter. I’m thinking of using Time::Piece in some examples because it can produce objects without visible calls to a constructor, plus it’s a core module.
What do people think? Any problems with this approach? Any other good object-oriented modules I can use to illustrate concepts like method calls, without discussing classes?