good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re^5: Creating dispatch table with variable in function nameby Laurent_R (Canon) |
on Nov 23, 2017 at 11:16 UTC ( [id://1204132]=note: print w/replies, xml ) | Need Help?? |
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.
In Section
Seekers of Perl Wisdom
|
|