Typing sounds like a good thing. It's almost always not. Why? Because we get lost in the idea of "correctness," and so what looks like:
sub fibonacci (PositiveInt $n) { return 1 if $n <= 1; return fibonacci($n-1) + fibonacci($n-2); }
actually reads more like:
sub fibonacci ($n ... # Wait, wait... hold on a second! What is this $n thing you claim # to be sending me?! Is this a thing? Is it the kind of thing that # I approve of? What about my friends? Will my friends respect # this thing? Let's ask them... Hold on, now, do I trust my # friends? Maybe not. Better take some precautions... # Time for some state management in the form of eval. That's light # weight, right? # Also, now is a good time to pre-format some error messages just # in case. Okay, I think this $n thing is up to snuff, but just in # case, I'm going to do some state management. Hold on a bit... ) { return 1 if $n <= 1; return fibonacci($n-1) + fibonacci($n-2); }
What I'd rather see is the ability to quickly validate, completely under my control, and completely duck-typed. For example:
sub fibonacci($n {$n >= 0 && int($n) == $n}) { return 1 if $n <= 1; return fibonacci($n-1) + fibonacci($n-2); }
Where this expands to something more or less like:
sub fibonacci($n) { die '$n failed check "$n >= 0 && int($n) == $n"' unless $n >= 0 && + int($n) == $n; ... }
I have no problem with typing as a shorthand that people can use if they want, where
sub fibonacci(PostiveInt $n) {
is equivalent to
sub fibonacci($n {$n = PostiveInt->new($n)}) {
But in that case, I've opted in to a potentially very expensive type construction from my potentially very simple value.

In reply to Re: The Future of Perl 5 by ajs
in thread The Future of Perl 5 by Laurent_R

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.