Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Sorry, one steap ahead of you again. :-) That breaks down when you need to add a nameless widget to another also nameless widget:
for (HBox->new) { $_->config1($param1); $_->config2($param2); my $sb = Scrollbar->new; for ($sb) { $_->config1($param3); $_->config2($param4); } $_->add($sb); $window->add($_); }

You need a temporary variable, although at least this one can be tightly scoped.

It also mingles method calls against several different widgets into a single block, which makes it harder to see what gets added where when. Your proposal is ok on a smaller scale, but scales badly - if you nest several unnamed widgets, it gets messy quick.

If you look at the tutorial at you'll see a really ugly style with lots of variable reuse and calls to different widgets interwoven in a single block. It made my head swim trying to read even the shorter example programs. configure_object was the result of several iterations of refactoring for readability.

It took enough effort and was beneficial enough that I felt I had to share this.

Update: Actually I suppose one can coerce the for approach into clean separation by adding some do to the mix:

$window->add(do { my $hbox = HBox->new; for ($hbox) { $_->config1($param1); $_->config2($param2); $_->add(do { my $sb = Scrollbar->new; for ($sb) { $_->config1($param3); $_->config2($param4); } $sb; }); $hbox; });
but that's quickly slipping into the realm of cumbersome. I really spent some serious time trying to get this whole deal to look reasonably readable, and no conventional tools would help, hence the snippet.

Makeshifts last the longest.

In reply to Re^4: multiple method calls against the same object (f.ex GUI programming) by Aristotle
in thread multiple method calls against the same object (f.ex GUI programming) by Aristotle

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • 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 or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2022-10-05 22:05 GMT
Find Nodes?
    Voting Booth?
    My preferred way to holiday/vacation is:

    Results (25 votes). Check out past polls.