Hi Discipulus
thanks for the code links.
> if you have a case where repetition is needed providing some %default is better tan nothing and suffices.
The example in the OP had only one method, the point of with is to handle many different methods on the same object.
with is available in many languages, tho Tk might be the wrong field for applying it.
The other default options were optional, but it surprised me a lot that Tk needed it. Must be related to the TCL brige.
> Why? Because I generally cut and paste my own code.
Well, personally I prefer DRY over boilerplating, but YMMV.
I looked into your code, and I see plenty of possibilities to improve readability.
may I suggest:
{
my $Entry =
sub {
my ($self,$textvar) = @_;
return $self
->Entry(-width => 3,-borderwidth => 4, -textvariable => $t
+extvar)
->pack(-side => 'left', -expand => 1,-padx=>5);
};
# ...
$fr2a->$Entry(\$size_help);
}
instead of many instances of
$fr2a->Entry(-width => 3,-borderwidth => 4, -textvariable => \$size_he
+lp)->pack(-side => 'left', -expand => 1,-padx=>5);
same for other methods.
Please note that you can
- restrict the scope of these anonymous methods to blocks, they are just lexical variables
- give them self-documenting names
- make later adjustments at a central point.
- still add verbose C&P code in the middle
> Corion is right:
TIMTOWTDI ... but YMMV :)
update
improved code for method-wrapper. |