Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

The answer is simple, really. Previously I disliked source filters because I knew they could be a source of serious bugs that could be difficult to find. Further, source filters can require all sorts of tweaking as we find this special case and that special case and struggle to ensure that we've covered them all.

Now, however, Filter::Simple handles many of the "worst case" scenarios. For example, you no longer have as much concern about filtering quoted text, comments or POD. If I had to deal with that, this module would be much larger and probably would not have been written. As it stands, I merely filter the "code" portion of the target module and everything works.

Another thing which has changed my mind is testing. I now do many things that I would never have dreamed about previously because I have the tests to immediately tell me if I've failed. I can reach for more powerful tools without worry about misusing them because of tests.

And finally, dogmatism of any sort scares me. When someone says "never do X" I immediately want to find reasons why X might be a good thing to do. In this case, by allowign function signtures and multi-method dispatch, an entire class of bugs in Perl is almost completely eliminated. Further, this is a class of bugs that other languages generally don't have, so this puts Perl on more of an equal footing. For example, consider how the &name code would look in Java (given that we cannot exactly duplicate the behavior because it's not possible to have different return types for methods with the same name):

public String name () { return name; } public String name(String name) { = name; return name; }

And doing that in Perl, as seen previously:

sub name { my $self = shift; if (1 == @_ && ! ref $_[0]) { $self->{name} = shift; return $self; } elsif (! @_) { return $self->{name}; } else { croak "Unknown arguments to name()"; } }

I thought Perl was supposed to be more concise? In cases like this, it's not. However, my code makes Perl about as concise as Java and still allows for the full power of Perl. Argument validation in Perl is so tedious that many people (including me) tend to ignore it. Sure, test suites frequently catch the resulting bugs -- but not always. Further, the edge cases get ignored. We find ourselves doing silly things like passing an array reference around until eventually someone tries to call a method on it and they have to trace through a call stack to find out where the arrayref was first passed.

My code is an attempt to alleviate that problem and eliminate the ability to write these bugs. Safeguarding against problems is typically cheaper than fixing them. My personal experience with source filters has convinced me that, when used properly, the gains can tremendously outweigh the losses.


New address of my CGI Course.

In reply to Re^2: Use method/function signatures with Perl by Ovid
in thread Use method/function signatures with Perl by Ovid

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

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (4)
    As of 2018-01-21 17:27 GMT
    Find Nodes?
      Voting Booth?
      How did you see in the new year?

      Results (228 votes). Check out past polls.