R
Rainer Weikusat
The complete text is available here:
http://search.cpan.org/~doy/Moose-2.0604/lib/Moose/Manual/Concepts.pod
,----
| Attributes are not methods, but defining them causes various accessor
| methods to be created. At a minimum, a normal attribute will have a
| reader accessor method. Many attributes have other methods, such as a
| writer method, a clearer method, or a predicate method ("has it been
| set?").
`----
This idea seems to have been 'borrowed' from 'Javabeans'. But
considering that the whole point of classes is to hide their
implementation details from class users, automatically generating
a set of 'access methods' which is isomorph to the set of implementation
details seems wrong to me. Some 'attributes' (or 'properties') may
indeed need to be publically accessible but the majority of them
shouldn't: There's no conceptual difference between a 'structure'
which has only public members and a class which exposes all of its
attributes via 'getter' and 'setter' &c methods, the latter is just a
way to accomplish the same as the former with more overhead.
,----
| A method is very straightforward. Any subroutine you define in your
| class is a method. Methods correspond to verbs, and are what your
| objects can do. For example, a User can login.
`----
The 'static OO language' background is again shining through here
clearly. The people who are usually credited with inventing 'modern
OO' in form of Smalltalk didn't think of methods as 'subroutines tied
to an instance of a datastructure' but as 'messages' which can be sent
to otherwise intransparent 'objects' which may or may not react to
such a message in whatever way they chose to. The same is true for
'Perl OO' -- any method name can be used on any object instance and it
is up to the class to react to this message in whatever way it sees
fit, including that what it sees fit may change over time. Perl is
clearly not 'modern' here insofar modern is regarded as equivalent to
'try to get as much Smalltalk out of a C-compiler which can
conceivably be gotten out of it without adding intolerable overhead
for 1980s hardware' aka 'C++' and all its conceptual descendants.
,----
| A role is something that a class does. We also say that classes
| consume roles. For example, a Machine class might do the Breakable
| role, and so could a Bone class. A role is used to define some concept
| that cuts across multiple unrelated classes, like "breakability", or
| "has a color".
|
| [...]
|
|
| Role are somewhat like mixins or interfaces in other OO languages.
`----
An 'interface' is the Java-way to work around the problem that
'methods' are not 'messages' and hence, without additional declaration
hackery, instances of unrelated classes can't be used by the same code
even despite they may define other methods compatible with what this
code expects. Since 'Perl OO' is message-based and not 'compile-time
relationship' based, this kludge simply isn't needed: Any Perl code
can send any kind of message to any Perl object.
The reason why I'm refering to this as 'a kludge' is that the sole
purpose of an interface declaration is to inform the compiler that two
things which aren't different in a certain aspect, eg, when two
unrelated classes implement two identically-named methods with
identical return types and signatures (prototypes?) are really not
different in this aspect despite the compiler is not capable of/
suposed to(?) detect this on its own.
,----
| Method Modifiers
|
| Could only be done through serious symbol table wizardry, and you
| probably never saw this before (at least in Perl 5).
`----
I indeed didn't see this anywhere since I read through the CLOS
combination rules for generic methods for the last time, something I
always considered a prime example of the desire to build the universal
abstraction gone wild without any concern for good design and
practical usefulness ('good design' is supposed to refer to
"perfection is not when there's nothing more to add but when there's
nothing more to be removed").
Strangely, I also didn't miss it.
,----
| Type
|
| Hand-written parameter checking in your new() method and accessors.
|
| With Moose, you define types declaratively, and then use them by name
| with your attributes.
`----
With Perl, I write code which works when its arguments satisfy certain
constraints and leave it to the caller to meet these
constraints. I'm not usually interested in fighting my tools for
ideological reasons such as the assumption that 'strong typing' would
be a desirable property in its own right.
http://search.cpan.org/~doy/Moose-2.0604/lib/Moose/Manual/Concepts.pod
,----
| Attributes are not methods, but defining them causes various accessor
| methods to be created. At a minimum, a normal attribute will have a
| reader accessor method. Many attributes have other methods, such as a
| writer method, a clearer method, or a predicate method ("has it been
| set?").
`----
This idea seems to have been 'borrowed' from 'Javabeans'. But
considering that the whole point of classes is to hide their
implementation details from class users, automatically generating
a set of 'access methods' which is isomorph to the set of implementation
details seems wrong to me. Some 'attributes' (or 'properties') may
indeed need to be publically accessible but the majority of them
shouldn't: There's no conceptual difference between a 'structure'
which has only public members and a class which exposes all of its
attributes via 'getter' and 'setter' &c methods, the latter is just a
way to accomplish the same as the former with more overhead.
,----
| A method is very straightforward. Any subroutine you define in your
| class is a method. Methods correspond to verbs, and are what your
| objects can do. For example, a User can login.
`----
The 'static OO language' background is again shining through here
clearly. The people who are usually credited with inventing 'modern
OO' in form of Smalltalk didn't think of methods as 'subroutines tied
to an instance of a datastructure' but as 'messages' which can be sent
to otherwise intransparent 'objects' which may or may not react to
such a message in whatever way they chose to. The same is true for
'Perl OO' -- any method name can be used on any object instance and it
is up to the class to react to this message in whatever way it sees
fit, including that what it sees fit may change over time. Perl is
clearly not 'modern' here insofar modern is regarded as equivalent to
'try to get as much Smalltalk out of a C-compiler which can
conceivably be gotten out of it without adding intolerable overhead
for 1980s hardware' aka 'C++' and all its conceptual descendants.
,----
| A role is something that a class does. We also say that classes
| consume roles. For example, a Machine class might do the Breakable
| role, and so could a Bone class. A role is used to define some concept
| that cuts across multiple unrelated classes, like "breakability", or
| "has a color".
|
| [...]
|
|
| Role are somewhat like mixins or interfaces in other OO languages.
`----
An 'interface' is the Java-way to work around the problem that
'methods' are not 'messages' and hence, without additional declaration
hackery, instances of unrelated classes can't be used by the same code
even despite they may define other methods compatible with what this
code expects. Since 'Perl OO' is message-based and not 'compile-time
relationship' based, this kludge simply isn't needed: Any Perl code
can send any kind of message to any Perl object.
The reason why I'm refering to this as 'a kludge' is that the sole
purpose of an interface declaration is to inform the compiler that two
things which aren't different in a certain aspect, eg, when two
unrelated classes implement two identically-named methods with
identical return types and signatures (prototypes?) are really not
different in this aspect despite the compiler is not capable of/
suposed to(?) detect this on its own.
,----
| Method Modifiers
|
| Could only be done through serious symbol table wizardry, and you
| probably never saw this before (at least in Perl 5).
`----
I indeed didn't see this anywhere since I read through the CLOS
combination rules for generic methods for the last time, something I
always considered a prime example of the desire to build the universal
abstraction gone wild without any concern for good design and
practical usefulness ('good design' is supposed to refer to
"perfection is not when there's nothing more to add but when there's
nothing more to be removed").
Strangely, I also didn't miss it.
,----
| Type
|
| Hand-written parameter checking in your new() method and accessors.
|
| With Moose, you define types declaratively, and then use them by name
| with your attributes.
`----
With Perl, I write code which works when its arguments satisfy certain
constraints and leave it to the caller to meet these
constraints. I'm not usually interested in fighting my tools for
ideological reasons such as the assumption that 'strong typing' would
be a desirable property in its own right.