Consider this:
my @args = ([1, 2, 3], "hello"); push @callbacks, sub { $_[0]->[0] = "tampered" };
Is this not tampering? Your statement is correct in a copy-by-value world, but not in a copy-by-reference world.

Yes, so? You have not been any more paranoid than me. Your code does not make a deep copy of @args so your validate() has no chance of detecting that sort of tampering either.

Btw, "strictures[1] and friends" means "strictures and other stuff like strictures", not "use strictures and have co-developers you are friends with".

I do not think you should make sweeping generalizations like that, to each his/her own, and you have no right to tell me different.

You are confusing a statement of fact for an opinion on style. There are two reasons to add validation code like yours, and in neither case does it make sense.

The first is when the data examined is user input. But if it's code that you have been fed by a user, such as would be the case in this example, you have lost right away. Even if you made a deep copy, someone determined enough could use PadWalker to tamper with your original @args as well as their copy and you'd have no way to detect that. If it runs inside your Perl interpreter, you better be able to trust it.

The other is if you want to guard against your own mistakes — the same reason to rely on strictures, enable warnings, use three-argument open(), and so on. But what does your validation code help? Look at it. Now look at the code I wrote. Which one is easier to maintain? In which one would bugs be easier to spot?

[1] Larry's term for the rules enforced by strict.

Makeshifts last the longest.


In reply to Re^6: Action at a great distance by Aristotle
in thread Action at a great distance by sfink

Title:
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, details, 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, summary, 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.