Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^5: Creating dispatch table with variable in function name

by Laurent_R (Canon)
on Nov 23, 2017 at 11:16 UTC ( #1204132=note: print w/replies, xml ) Need Help??


in reply to Re^4: Creating dispatch table with variable in function name
in thread Creating dispatch table with variable in function name

Yes, dsheroh++, I agree: quite possibly it isn't much more virtuous, and yes, you might still very well refer to a sub that does not exist and the compiler won't tell you about it.

On the other hand, it is much easier to check that all your subrefs correspond to actual subs when they are explicitly listed in the dispatch table as in your example than when their names are dynamically created, and it is also probably easier to make sure that your tests cover all of them.

Also, if we insist that symbolic references for package variables should be avoided (at least for "usual" programs, I am not talking here of pieces of white magics introduced for extending the language), then we should presumably also try to avoid similar constructs for subroutines.

As I said already, I am not saying that this is bad, I am just asking monks for their opinions on this subject. I have actually done similar things a couple of times, and even explicitly written things to the symbol table in order to extend the language (by replacing a subroutine by another one). I don't think I would do that for regular plain-vanilla coding.

  • Comment on Re^5: Creating dispatch table with variable in function name

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2020-05-25 15:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (146 votes). Check out past polls.

    Notices?