3 ms·
Signatures were added in 5.020, and [edited:] were considered experimental until 5.036.
by duskwuff 4y ago
Signatures were added in 5.020, and [edited:] were considered experimental until 5.036.
- darrenf 4y ago> and are still considered experimental No, 5.36 stabilised them. https://perldoc.perl.org/perldelta#Core-Enhancements https://perldoc.perl.org/perldelta#Core-Enhancements > The 5.36 bundle enables the signatures feature. Introduced in Perl version 5.20.0, and modified several times since, the subroutine signatures feature is now no longer considered experimental. It is now considered a stable language feature and no longer prints a warning.
- jandrese 4y agoOh, that's a bummer. I was kind of excited to use those, but since I never know when I'm going to get a call from the Centos 7 guys I have to stay away from features newer than 5.016. Basically just new enough to get semi-sane UTF support.
- duskwuff 4y agoAh! Looks like I need to upgrade, then -- I was reading from "perldoc feature" in my install, which was still on 5.34.
- forgotmypw17 4y agoThanks for the correction. I don't use them anymore (instead doing a few lines of sanity-check boilerplate in each sub) so that's why I made that mistake.
- theonething 4y agoare Perl function signatures the PHP/Python equivalent of type hints?
- duskwuff 4y agoThis may shock you, but: historically, Perl functions did not have declared arguments. Like, at all. The function just got arguments implicitly passed to it as an array (@_), and parsing that into individual variables was up to the function -- so most functions would start like this: sub myFunction { my ($self, $arg1, $arg2) = @_; ... } Or, in older code, you might even see this: sub myFunction { my $self = shift; # implicitly get the first value from @_ my $arg1 = shift; my $arg2 = shift; ... } Notably, this didn't even check the number of arguments you passed. If you passed too many or too few arguments to a function which worked this way, the extra arguments would silently be ignored, or missing arguments would silently show up as undef. Function signatures turn this into something that'll look much more familiar to users of other languages: sub myFunction ($self, $arg1, $arg2) { ... } which includes checks to make sure that all the expected arguments (and no more) were passed.
- int_19h 4y ago> If you passed too many or too few arguments to a function which worked this way, the extra arguments would silently be ignored, or missing arguments would silently show up as undef. This part probably won't shock anyone given the prevalence of JS today. Which is kinda sad, given that it's 35 years since Perl was first a thing.
- Karrot_Kream 4y agoLol there were places, perhaps times, where Perl subroutines would "shift" as they go along, to create a prose effect. Sometimes you'd get a comment about it, but mostly not. Maddening for any longer function.
- cutler 4y agoAnyone remember smart match? Oh dear - a real low point for Perl.