News for hackers. Stuff that matters.
Re:Not Your Grandfather’s Perl by theonething on Thursday September 08, 2022 @04:48PM (#32771895)
are Perl function signatures the PHP/Python equivalent of type hints?
Re:Not Your Grandfather’s Perl by duskwuff on Thursday September 08, 2022 @05:44PM (#32772491)
This 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.
Re:Not Your Grandfather’s Perl by int_19h on Thursday September 08, 2022 @10:29PM (#32774610)
> 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.

Re:Not Your Grandfather’s Perl by Karrot_Kream on Friday September 09, 2022 @06:21AM (#32777509)
Lol 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.