Hacker News new | ask | show | jobs
by kbenson 3253 days ago
> So, how exactly these different ways of getting sub arguments are useful?

Because in the second (add2), you might do something interesting with the second (or third) arguments depending on the first. You might have optional arguments. Your arguments might be a list of items you don't know the size of. It allows you to develop what you need out of the extensible core mechanism. Modules can and have built on that.

> # There may be some other ways to extract arguments

There are. Now you can just do

    sub add( $arg1, $arg2 ) {
        $arg1 + $arg2;
    }
My personal favorite is to use Function::Parameters[1]

    fun add( Num $arg1, Num $arg2 ) {
        $arg1 + $arg2;
    }
which allows named params, type constraints (runtime), default params, etc.

1: https://metacpan.org/pod/Function::Parameters

1 comments

I cannot imagine any way of practical (ab)using this flexibility that could not be covered in Python with its only way of handling arguments.