[Purdue-pm] Perl 5 Dispatch Tables
Mark Senn
mark at purdue.edu
Tue May 28 17:20:45 PDT 2019
> I'm not sure how a typical dispatch table is violating DRY.
> [... -mark]
> sub create_dispatch_table ($config) {
> my $dispatch = {
> 'thing_one' => \&thing_one,
> 'thing_two' => \&thing_two,
> };
> return($dispatch);
> }
> [... -mark]
From
https://dzone.com/articles/software-design-principles-dry-and-kiss
The DRY Principle: Don't Repeat Yourself
DRY stand for "Don't Repeat Yourself," a basic principle of software
development aimed at reducing repetition of information.
>From my earlier message:
In short, I don't use conventional dispatch tables because they
violate the don't repeat yourself principle. I'm only dispatching
to subs based on trusted information and the core of the idea is
I should have written
I only use dispatch tables to dispatch to non-anonymous subs
based on trusted information.
To me,
my $dispatch = {
'thing_one' => \&thing_one,
'thing_two' => \&thing_two,
};
is an example of repetition. For the case I wrote about, this code
is not needed. Since it's not needed I don't use it---it's just
more code to support. Given a word w, I always call a subroutine
whose name can be computed from w. In other words, I don't need to do
'thing_one' -> \&some_name_that_cannot_be_be computed_from_thing_one
-mark
More information about the Purdue-pm
mailing list