Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: what's a proper way to code method synonyms

by leocharre (Priest)
on Sep 06, 2006 at 21:10 UTC ( #571551=note: print w/replies, xml ) Need Help??


in reply to Re: what's a proper way to code method synonyms
in thread what's a proper way to code method synonyms

I'm developing a module CGI::PathRequest (seemed like the best name). It's an object that encapsulates various queries to a resource being accessible in a cgi environment. Usualyl a http accessible file.

You optionally initiate it by passing it a relative path.. And as you query it, it gives you info like relative path, absolute path, prettied up filename, is_text, is_dir, is_image, get an excerpt (if a text file) some other things that are really useful to me when I code CGI.

I want to give a coder using this module a lot of freedom. I want it to be intuitive.

How should someone query the instance for an absolute path? The more conservative way is: $object->get_absolute_path , but it could be more intuitive for someone to ask for $file->abs_path - so I have both. Someone should not *have* to read the documentation to use a module that serves such basic data. Is *one* way to pitch this.

It doesn't *need* to have that many synonims. I remember reading somewhere that a good application is liberal about what it accepts and conservative about what it outputs. I am trying to be liberal about what it accepts- about how you can ask it questions.

Yes, they can look at the documentation (which i wrote first).. But I want it to be intuitive. I almost would like to be able to ask $object->get_me_the_absolute_path and let the thing resolve by itself what the heck i want ( i know there's a module for that.. was it Sam Treggar?).

  • Comment on Re^2: what's a proper way to code method synonyms

Replies are listed 'Best First'.
Re^3: what's a proper way to code method synonyms
by merlyn (Sage) on Sep 06, 2006 at 22:05 UTC
    Someone should not *have* to read the documentation to use a module that serves such basic data. Is *one* way to pitch this.
    And then if I want to subclass your class, I have to subclass every possible spelling. No thanks. There's no excuse for not reading the docs to determine the right method name. Name them consistent, and I'll only have to learn once.

    Not to mention that even if you find five aliases for a method name, I'll type in the sixth. All that effort for nothing.

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

      I've heard little in the gist of "hey that's great, i wish more modules had synonyms!".

      At least for me, hearing your thoughts on this puts the dirt in the grave. Thank you.

      I'm going to take out the synonyms.

      I still have to make up my mind about which to keep. For example- the method named abs_path is more intuitive, at the same time good sense would be to call it get_absolute_path. So I have to pick between the shorties and the longsies. More like the midsies.

      Which to pick it's a hard call.. Consistent. Should I make braindead named routines (rel_path vs get_relative_path) because that's what's expected (because other modules have already named things a certain way)? That is a form of consistency.

Re^3: what's a proper way to code method synonyms
by planetscape (Chancellor) on Sep 07, 2006 at 16:09 UTC

    Erm... Won't that make for an absolute maintenance nightmare when someone has to go in and clean up code that someone else wrote using every possible variant of every possible method? Such a person might well hunt you down for this... (only half kidding)

    HTH,

    planetscape

      Actually .. This is kind of easy with vim.. at least a lot easier. Yes now that I think of it- if I had to use notepad to edit one of these modules with multiple synonyms.. I would quit my job.

      I'm a fan of unix one liners that spinal tap multiple files. And of cvs.. so... can't mess up.

      I was under the illusion that having synonyms makes it easier to use.. if not maintain.. Anyhow. After reading this thread I am turned off from the idea. And I am not going to use any synonims in modules again. Unless it's for... as merlyn said, legacy.

Re^3: what's a proper way to code method synonyms
by Anonymous Monk on Sep 07, 2006 at 13:03 UTC
    < gross > How about an AUTOLOAD that uses Text::Levenshtein on the symbol table to find the best matching sub < /gross >

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2020-08-06 07:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which rocket would you take to Mars?










    Results (39 votes). Check out past polls.

    Notices?