Method Signatures Make Large Projects More Manageable

Taylor Gillespie By Taylor Gillespie
Expert Author
Article Date:

In many other languages, a function or method states upfront exactly what parameters it expects in order to successfully execute. Along with its name, this is called the “signature” of the function or method. A programmer merely has to look at the signature to know what parameters are expected.

In strongly typed languages, the programmer also knows what types of values the arguments should be. Typically, a programmer need not be concerned with how the function or method actually works, but what is needed for it to work. The signature provides this information, a sort of contract. Not so in vanilla Perl. The Perl module Method::Signatures makes signatures “natively” possible with very little overhead.

As we all know, Perl subroutines accept as a parameter any array of arguments. Technically, this means that Perl subroutines only accept one parameter, a parameter of arguments. Ever. Usually, the first thing Perl subroutines are programmed to do is assign the values of the parameter array to working variables. Only by looking into the actual code of the subroutine does a Perl programmer know how many and what parameters the subroutine expects.

In large projects, having to inspect subroutines for the complete signature can be cumbersome, as can having to assign the variables when writing the subroutine. For these reasons, some organizations use a sort of preprocessor, a source filter, that allows Perl programmers to write subroutines that state their function or method signature as in other languages, and then substitutes out the custom Perl code for the more boilerplate in-routine argument assignment. This is a working solution, but requires the Perl code to be parsed once before the Perl interpreter itself can parse it. The Method::Signatures module can be used to write signatures in-line with the name with a claimed overhead of less than 1% without the use of a source filter. When working with other programmers on the same project, the benefits are substantial in terms of readability, usability, and maintainability.

About Taylor Gillespie
Taylor is a Staff Writer for WebProNews

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • 160×600
  • 152×252
  • Newsletter Signup
    Get The Email Newsletter! Please subscribe using your company email address
  • 336×280
  • 336×130