Moose, mixins and stuff

| Perl | 5 Comments

Everywhere you look these days in Perl literature, chances are that you'll come across references to Moose, how great and flexible it is and so forth.

Since I had such a lousy game of golf this afternoon and lost my first matchplay round six down, I needed a way to inspire myself. So what could be better then reading the Moose::Manual this evening?

Boy, was I in for a frustrating surprise.

I hate to admit it, but all this Moose stuff is not easy for me (grumble). Rather than getting all excited and inspired like I hoped, I'm sorry to admit that it's making me feel rather sad that I cannot figure this out.

Am I supposed to be able to understand this Moose stuff? After so many years of getting pleasure in tackling all kinds of complex programming issues, have I simply reached my limit? Time to give up trying to be a Perl guru, jump ship, and be forced to become a golf hacker the rest of my life? What do other fine Perl souls out there think about it?

Here's an example that better illustrates my frustrations. In the Moose::Manual::Concepts one goes on and on about classes, attributes, methods and roles. Not bad. A role has zero or more of this, a role has zero or more of that, a role has zero or more of this and that. Getting more difficult.

Later on one learns that a role is somewhat like mixins or interfaces in other OO languages. Getting more difficult. What the heck is a mixin (and how do you pronounce it)? The good old Wikipedia saves the day with a nice, clear definition:

"In object-oriented programming languages, a mixin is a class that provides a certain functionality to be inherited by a subclass, while not meant for instantiation (the generating of objects of that class). Inheriting from a mixin is not a form of specialization but is rather a means of collecting functionality. A class may inherit most or all of its functionality from one or more mixins through multiple inheritance."

Huh? Nearing apogee and getting impossibly difficult.

Whatever happens, I have promised myself to hang in there. Read and reread as much as I can. Stay smart. Get smarter. Figure it all out or else.

What with so many Perl gurus out there getting all fired up about Moose, mixin and stuff, why I want to join the fun as well!

Tomorrow it's all about Moose::Manual::Classes and then next the world.

Wish me luck.

5 Comments

Theory can be difficult, especially if the terms used are unfamiliar. So learn by example! Try reading Moose::Cookbook. There are a bunch of recipes which go through roles.

Roles are one of the hardest things to grasp really, there is no clear analog in traditional Object Orientation. This means of course that they are one of the most powerful and interesting aspects of Moose. Comparing to mixin's is obviously an attempt to give an analogy to something some people may have known (Ruby uses them extensively I'm given to understand), another analogy people have given is Java Interfaces that actually provide a default implementation.

Ultimately though the power to Moose isn't any single feature but is the mixture of powerful tools that provide the effects demonstrated in Moose::Manual::Unsweetened. Some of those tools are more complex (Roles) and some are more simple (attributes and generated methods) to understand. Moose like any good toolbox provides you the ability to work with just a hammer before having to learn the jigsaw.

Roles are code reuse without inheritance (and implicit relationship is-a between classes). It was thanks to Roles description that I had understood what mixins are ;-)

Random entries

Here are some random entries that you might be interested in:

Recent Assets

  • 2023-09-24-jong-tegen-oud-1.jpg
  • 2023-09-24-jong-tegen-oud-2.jpg
  • just-call-me-fred.png
  • foggy-morning.png
  • oma-2023-07-27.jpg
  • i-almost-died.png
  • chipping-from-twenty-meters.png
  • de-koepel.png
  • screenshot-www.udemy.com-2023.05.18-10_02_39.png
  • screenshot-www.golf.nl-2023.05.08-09_57_30.png
  • IMG-20230423-WA0000.jpg
  • me-and-my-radio-paradise-hat.png

Recent Comments

Golf Handicap

Information

This personal weblog was started way back on July 21, 2001 which means that it is 7-21-2001 old.

So far this blog contains no less than 2498 entries and as many as 1877 comments.

Important events

Graduated from Stanford 6-5-1979 ago.

Kiffin Rockwell was shot down and killed 9-23-1916 ago.

Believe it or not but I am 10-11-1957 young.

First met Thea in Balestrand, Norway 6-14-1980 ago.

Began well-balanced and healthy life style 1-8-2013 ago.

My father passed away 10-20-2000 ago.

My mother passed away 3-27-2018 ago.

Started Gishtech 04-25-2016 ago.