Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Re: Class automators should be standard

by danb (Friar)
on Jan 14, 2004 at 18:43 UTC ( [id://321331]=note: print w/replies, xml ) Need Help??


in reply to Re: Class automators should be standard
in thread Class automators should be standard

(And imho I don't the appearance of a class which uses C:MM for some getter/setter methods but hand-rolls others... just doesn't fit my code aesthetic.)

It fits my code aesthetic; in fact, I think it is very attractive. But even if I didn't, I would continue to mix C:MM and hand-rolled code because of this lazy principle:

If it is simple and/or repetitive, the computer should do it.

Do you think that the principle itself is ugly, or just the "C:MM with hand-rolled code" implementation of the principle?

I think the following is a great example of C:MM, due to my liberal application of the hubris virtue. ;-)

use Business::Shipping::CustomMethodMaker new_with_init => 'new', new_hash_init => 'hash_init', boolean => [ 'update', 'download', 'unzip', 'convert', 'is_from_west_coast', ], hash => [ 'zone' ], grouped_fields_inherit => [ optional => [ 'zone_file', 'zone_name', ], required => [ 'from_state', ], ];

The above would take a lot of coding to represent manually. You can see simple methods, and slightly-less-simple methods (like the required() and optional() methods, which automatically call parent methods and concatenate the results to their own). (Note that the above is using a sub-classed version of C:MM, taken from the Business::Shipping project.)

While I'm on the subject, I think it would be great if Java had something like C:MM, but the closest you can get is those code-generators that run just before compile.

As far as the topic's original question, I wouldn't mind if all or none of the OO modules were in the core. Newbies can continue to find the ones they like by reading the OO docs. (Damian Conway's book was my initiation to the Perl OO world.) Which makes me wonder, is there an "OO Perl Module Survey" doc somewhere that is updated when new OO modules come out?

-Dan

Replies are listed 'Best First'.
Re: Re: Re: Class automators should be standard
by rkg (Hermit) on Jan 14, 2004 at 20:52 UTC
    Ok, I'l agree with your point about making the computer do the boring repetitive stuff.

    But back to my question:

    How do you handle getter/setters when the attributes interact? In your shipping example, what would keep me from (assuming I understand the methods correctly) setting  from_state to Massachusetts and is_from_west_coast to TRUE? Shouldn't setting the state cause the west coast flag to flip on or off as appropriate?

    A handrolled get/set could enforce all these things; doesn't C:MM fall short here?

    I am not C:MM bashing; I use it and am a fan; I just haven't figured out how to handle interrelated attribs yet.

    Thanks for your comments

    rkg

      Your point is a good one. It is necessary to hand-roll methods that do anything non-simple, like keeping is_from_west_coast() in the correct state.

      Because of that, C:MM can only be used for simple methods. In my case, that means C:MM methods are usually private methods, and public methods are hand-rolled.

      I am looking forward to automatic method constructors getting smarter in the future. I could imagine a module that combines something like Params::Validate with C:MM, like so:

      use Class::MethodMaker optional => [ 'zone_file' => [ 'no spaces', 'alpha only', 'uppercase', 'error on parameter failure' ] ];

      -Dan

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://321331]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-25 08:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found