LanX has asked for the wisdom of the Perl Monks concerning the following question:
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. =)
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery