Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

schwern (1528)

  (email not shown publicly)
AOL IM: MichaelSchwern (Add Buddy, Send Message)

Schwern can destroy CPAN at his whim.

Journal of schwern (1528)

Monday July 12, 2010
07:06 PM

"def" or "func"?

[ #40444 ]

perl5i 2.3.0_01 now has basic methods and subroutine signatures with code basically lifted straight from Method::Signatures::Simple. MooseX::Declare got me addicted, now I want them everywhere.

use perl5i::2;
def add($this, $that) {
    return $this + $that;
method new($class: %args) {
    return bless \%args, $class;
my $echo = def($arg) { return $arg };

Its alpha for two reasons. First, I don't have time right now to really thoroughly test it, but I really want it.

Second, overriding "sub" is hard. Its been done but its a bit twitchy. Defining a new keyword is easy(er). So what should that keyword be? I've come up with two that have good arguments. "def" and "func". Both are short. "def" has the benefit of being used by other programming languages a Perl programmer is likely to encounter and not hate (Python, Ruby, Scala, Groovy). "func" is nice because it pretty clearly means "function" whereas "define" is a bit ambiguous.

perl5i currently does both. Only one will survive in version 3 (the other will be deprecated). Before you comment on which is your favorite, try it for a little bit. I found a difference between what I thought I like and what I actually use.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.