Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Re^5: Naming Subs

by dug (Chaplain)
on Jan 13, 2003 at 21:34 UTC ( [id://226607]=note: print w/replies, xml ) Need Help??


in reply to Re^5: Naming Subs
in thread Naming Subs

You are aware that the symbol table is basically a dispatch hash on steroids? That invalidates your wasted space comment.

That's an interesting view of things. Would adding a third, or maybe a fourth layer of indirection make things more readable and maintainable? It's precisely because the symbol table is a dispatch hash that I don't think one is necessary in the code I posted. It is redundant.

-- dug

Replies are listed 'Best First'.
Re^7: Naming Subs
by Aristotle (Chancellor) on Jan 13, 2003 at 22:34 UTC
    I don't think so. To clarify, when I use dispatch hashes, I almost always store anonymous functions in them. I don't like taking references to named subs for dispatch hashes, it requires me to keep the refs and subnames in sync and offends my sense of Once And Only Once. I should have made that clear from the get go I guess.. Once you take that into account, it becomes a technique for lexically (or semantically, if you pass a reference to the dispatch hash around) scoping functions. And that's a good idea for all the same reasons we use scoping in other contexts.

    Makeshifts last the longest.

      That makes sense, thought the syntax of creating your hash must get a bit messy unusual if you have large and/or many subs. Only a bit though.

      I was just thinking about how you would handle modularising the functionality, in terms of the source code rather than semantically?

      I probably haven't thought this through properly yet, but to try and explain what I mean, say your writing an editor. The dispatch table is used to invoke actions depending upon user input. The user input can take the form of keystrokes, mouse gestures, CLI comands and possibly menus. Ignoring for the moment any problems that might arise from storing/translating keystroke or mouse gesture info into a hash key. It makes a certain amount of sense to segregate the functionality along those lines into seperate modules, if only for ease of editing. I realise that the segregation would more likely be on the basis of different criteria (eg. edit action on current file, configuration action on current file, global configuration action etc.)

      The point is, once you have sub code in different source files, how would you go about building this into a dispatch hash for use in the main input queue processing loop?

      Add to this the requirement to allow the remapping of the keyboard commands and the desire for the ability to define keystroke/menu commands to user defined 'macros' (I use the term loosely) and I having trouble envisioning how to build and maintain the hash table.

      This is actually quite close to something I'm working on right now, hence my interest.


      Examine what is said, not who speaks.

      The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.

        I'd probably not use a dispatch hash then. Dispatch hashes are more of a smallscale solution. It might make more sense to have classes implementing the actions and various mapping mechanisms that translate from input to method calls. In case of a command line input, a dispatch hash would of course be an obvious approach to implementing such a mapper. In other cases, the mapping may pose very different requirements.

        I don't know, it's hard to say without any concrete idea about the requirements of the design you're talking about.

        Makeshifts last the longest.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-24 02:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found