Ovid's idea was to imagine where Perl 5 would stand in ten years from now.
These are some of the things Perl would have in 10 years in Ovid's vision:
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.)sub fibonacci { my $n = shift; return 1 if $n == 1 or $n == 0; return fibonacci($n-1) + fibonacci($n-2); }
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:
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; # ... }
With (non experimental) function signatures and proper typing, all you would need might just boil down to something like:
I think this would look quite cleaner.sub fibonacci (PositiveInt $n) { return 1 if $n <= 1; return fibonacci($n-1) + fibonacci($n-2); }
I hope the video of Ovid's talk will on-line soon.
Comments are welcome.
Update (Aug 23): ovid created a new meditation explaining his views with some details here: Recap: The Future of Perl 5.
In reply to The Future of Perl 5 by Laurent_R
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |