On Dec 31, 2004, at 2:24 PM, Terrence Brannon wrote:

However, it is not clear that all the extra work to make the inline code
succint is worthwhile. The "magical" version of the hello_world.pm
program is:


      $tree->name('terrence brannon')->date('5/11/1969')->as_HTML;

    The "plain Jane" version is:

      $tree->get_name->replace_content('terrence brannon')
           ->get_date->replace_conent('5/11/69);

It's not clear to me that either of these named-accessor, mutator-chaining interfaces is the optimum idiom; wouldn't the following be clearer?


      $tree->replace_content_elements(
           'name' => 'terrence brannon',
           'date' => '5/11/69
      );
      print $tree->as_HTML;

    In fact, it is nice to know that all tree processing
    actions will be handled like this:

$tree->$id_name->$library_method(@method_args);

It seems more natural to me to treat the ID as data, along these lines:

      $tree->$library_method($id_name => @method_args);

Why select an interface that forces you to generate methods for every ID'd element? (And what happens when my HTML designer gives me a template with IDs named 'new' or 'delete'?)

More generally, I would side with Aristotle's position against mutator chaining, set forth at <http://perlmonks.org/index.pl/417872>, particularly in cases which seem to mix mutators with sub-object accessors -- are you really calling get_date() on the result of replace_content(), as shown in the "plain" example above? Yikes!

-Simon


_______________________________________________ sw-design mailing list [email protected] http://metaperl.com/cgi-bin/mailman/listinfo/sw-design

Reply via email to