Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^4: Verbose Tk Code

by LanX (Saint)
on Feb 28, 2021 at 20:07 UTC ( [id://11128916]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Verbose Tk Code
in thread Verbose Tk Code

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 :)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

update

improved code for method-wrapper.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-19 16:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found