perlmeditation
Laurent_R
Yesterday, for the last day of The Perl Conference (formerly known as YAPC) in Glasgow, Scotland, Curtis "[Ovid]" Poe delivered a very inspiring keynote address on the future of Perl.
<p>
Ovid's idea was to imagine where Perl 5 would stand in ten years from now.
<p>
These are some of the things Perl would have in 10 years in Ovid's vision:
<p>
<ul>
<li>(Non experimental) Function signatures along with a gradual typing system;</li>
<li>A simple core OO system (see [http://blogs.perl.org/users/ovid/2018/07/the-future-of-perl-5.html])</li>
<li>An inline keyword to support functions in-lining to boost performance while not repeating oneself;</li>
</ul>
As an example for the first point above, consider the following subroutine:
<c>
sub fibonacci {
my $n = shift;
return 1 if $n == 1 or $n == 0;
return fibonacci($n-1) + fibonacci($n-2);
}
</c>
This subroutine should work correctly if the subroutine is called with a positive integer, but a number of things could go wrong: what will happen if no parameter is passed to the subroutine? or if the parameter is a negative integer, say -3? or if the parameter is a positive number but not an integer, e.g. 3.14? or if the parameter is not a number but a string? (Note that there would also be a problem with a large integer, but that's a different story.)
<p>
For the above subroutine to be correct, you would need to add probably half a dozen boiler plate code lines to guard against invalid input, for example maybe something like this:
<c>
sub fibonacci {
die "..." unless defined $_[0];
my $n = shift;
die "..." unless is_a_number($n); # the is_a_number function is to be defined
die "..." if $n < 0;
die "..." if $n != int $n;
# ...
}
</c>
<p>
With (non experimental) function signatures and proper typing, all you would need might just boil down to something like:
<c>
sub fibonacci (PositiveInt $n) {
return 1 if $n <= 1;
return fibonacci($n-1) + fibonacci($n-2);
}
</c>
I think this would look quite cleaner.
<p>
I hope the video of Ovid's talk will on-line soon.
<p>
Comments are welcome.
<p>
<i>Update (Aug 23):</i> [ovid] created a new meditation explaining his views with some details here: [id://1220917].