Hi
I was meditating about designing DSLs and especially how to robustly implement with like in JS to a have clearer and less verbose code.
So I thought to use Tk as a use case and found this 20 year old https://www.perl.com/media/_pub_1999_10_perltk_index/sld001.htm demo.
The code is extremely verbose and I'm asking myself if this is really state of the art.
For instance the code from https://www.perl.com/media/_pub_1999_10_perltk_index/sld010.htm
Is it really necessary to always repeat ...
- -background => 'cyan'
- ->pack()
- and finally my $t1 looks like sloppy code which will generate warnings
my $t1 = $left1->Label(-text => ' ',
-background => 'cyan')->pack();
my $t1 = $left1->Label(-text => ' Day ',
-background => 'cyan')->pack();
my $t1 = $left1->Label(-text => ' Week ',
-background => 'cyan')->pack();
my $t1 = $left1->Label(-text => ' Month ',
-background => 'cyan')->pack();
my $t1 = $left1->Label(-text => ' Year ',
-background => 'cyan')->pack();
If needed I'd rather implement a helper like:
with ($left1) {
default -background => 'cyan';
chain { pack() };
Label(-text => ' ');
Label(-text => ' Day ');
Label(-text => ' Week ');
Label(-text => ' Month ');
Label(-text => ' Year ');
}
(pseudocode)
But before reinventing the wheel I'd like to discuss my doubts. =)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.