xdg has asked for the wisdom of the Perl Monks concerning the following question:

I'm looking for some pithy ways of describing different accessor styles. I'm planning to use this with some accessor generating code, e.g. { style => 'perl'}. I've seen a variety of terms used here and elsewhere and am looking for something that is both brief and clear. Potential examples:

What names do you think work best for these styles? Are there other styles you personally prefer and what would you call it, e.g. "Java" style: getName and setName?

Update: Lots of (++) received, but few suggestions! Please post comments -- a couple lines on which of the style names above you favor is fine.

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Replies are listed 'Best First'.
Re: Pithy names for accessor styles?
by merlyn (Sage) on Jan 19, 2006 at 22:54 UTC
    And as long as you're naming things, about the return value from setters? The styles I enumerate in the Alpaca are:
    • setter returns new value
    • setter returns old value
    • setter returns self (for chaining)
    • setter returns success/fail
    • setter returns some undocumented value (whatever was easiest to implement)

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      And as long as you're naming things, about the return value from setters?

      It's in the plan, but I see that as an orthogonal decision for what to call the setter in the first place. The choice for what to name them also seemed a little more self-evident: "new_value", "old_value", "self". I hadn't thought of doing success/fail, as I'm also planning on having a user hook that can filter/validate in the setter and die with an error message to indicate failure.

      -xdg

      Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

      Whatever the documention reads, the last bet is probably the safest assumption. Don't trust anything more than you have to. :-)
Re: Pithy names for accessor styles?
by duckyd (Hermit) on Jan 20, 2006 at 01:54 UTC
    As long as you're looking at what others do, Class::MethodMaker offers "-java" and "-eiffel" styles.
Re: Pithy names for accessor styles?
by Anonymous Monk on Jan 20, 2006 at 01:09 UTC

    Those accessors always make me feel pithy.

Re: Pithy names for accessor styles?
by Aristotle (Chancellor) on Jan 20, 2006 at 22:14 UTC

    I’d say:

    1. Combined (alias: Perl)
    2. Get/set (alias: Java)
    3. Eiffel
    4. Lvalue

    Makeshifts last the longest.

Re: Pithy names for accessor styles?
by Anonymous Monk on Jan 20, 2006 at 22:37 UTC
    A separate style offered by Class::Meta as noted in doc:

    The boolean data type is the only one that uses a slightly different approach to the creation of affordance accessors: It creates three of them. Assuming you're creating a boolean attribute named "alive", it will create these accessors:

    sub is_alive { shift->{alive} } sub set_alive_on { shift->{alive} = 1 } sub set_alive_off { shift->{alive} = 0 }
    Suggested accessor style name is 'bool' or 'boolean'.