It is generally a good thing, I'm mostly talking about
the "signatures" stuff that allows functions with stuff that looks like
usual languages.
Other benefits include somewhat "cheap" check for correct number of parameters
and generally making code shorter.

Basically this converts very perlish code like

package OpenBSD::PackingElement::DirlikeObject;
sub process_dependency
{
        my ($self, $mtree) = @_;

        $mtree->{dir}{$self->fullname} = 1;
}


into
package OpenBSD::PackingElement::DirlikeObject;
sub process_dependency($self, $mtree)
{
        $mtree->{dir}{$self->fullname} = 1;
}

which is
- shorter
- more readable for people not used to perl
- actually errors out on runtime if you use more parameters than expected,
thus tightening the actual usage.

(I also hope that the binding is/will become more efficient than writing
stuff manually)




Stuff to watch out for:

- it supersedes the syntax for prototypes. So if you had prototypes
(I did!), you need to explicitly write :prototypes in front of them.

For instance, constant methods like
package X;
sub is_okay()
{
        1;
}


would become:

package X;
sub is_okay :prototype() ($)
{
        1;
}


under the new rules.
I'm actually wondering whether keeping the prototype is worth it.

- it's still possible to not add any signature when you don't know.

- use v5.36; implies "use strict;" "use warnings;" and "use feature qw(say);"
which is cool

- beware that calling code without parenthesis, e.g., stuff like
&$code;
*will* not create a new context (and thus reuse @_ implicitly, which doesn't
mesh well with signatures)

- parameters which aren't used can use a single $ or something, which leaves
the question of documentation.

After fiddling a bit with it, I've settled on documenting the method
fully in comments, e.g., for instance:

# $class->recognize($filename, $fsobj, $data):
#       called for each class in order until the "default" file
#       some retrieved data such as file's contents are cached for
#       efficiency
sub recognize($, $, $, $)
{
        return 1; 
}


(which is very useful for any base class that actually does nothing)


- lambdas (anonymous subs) can use signatures.  Note that stuff like 
File::Find explicitly takes 0 parameters, whereas stuff like signal handler
is woefully underspecified !

Reply via email to