How about separating dynamic world and static world?
I write comment before topic. Please see it.
Current subroutine signatures implementation contains two features which purposes are different
My opinion is that argument count checking by subroutine signature is not fit to Perl because Perl is dynamic language.
Perl is dynamic language, so argument count checking is done in run-time, not in compile time. This damage to performance of subroutine call.
Perl one big problem is that subroutine call is slow. If this is improved, Perl have big benefit.
"sub foo($x, $y) { ... }" should be faster than "sub foo { my ($x, $y) = @_ }"
Many existing projects will use subroutine signatures not worrying about performance damage.
How about separating dynamic world and static world?
By the way, I am reading cperl specification by Reini Urban. This is very interesting.
He want to introduce many static features to Perl. This is mainly performance reason.
I think this is good, but a little messy for current perl. mixing dynamic features and static features is not good. Perl 6 mix dynamic features and static features. but This is a little messy for users.
My proposal is that how about separating dynamic world and static world. Static features is used only in static world. Static features are, for example, type checking, argument count checking, inline expansion of method call, typed array.
Static world is that
package Foo : static;# Inheritance is forbidden for performance of compile time
# Attributes. This is static continuous spaces, not hash reference.
has x : IV; # Native type
has y : NV; # Native type
has z : NV[]; # Array is Reference# Multicall is default. Type and argument count is checked
# new is special keyword for object initialization
sub new ($self : Foo, $x : IV) {
$self->{x} = $x;
$self->{y} = 0;
}
sub new ($self : Foo, $x : IV, $y : NV) {
$self->{x} = $x;
$self->{y} = $y;
}sub total($self: Foo) : NV {
my $total : IV;$total = $self->{x} + $self->{y};
return $total;
}
package Bar : static;# can use ffi in static package
extern sub twite($x : IV) : IV;
Perl 6 mix dynamic features and static features. but This is a little messy for users.
Care to elaborate or show an example instead of using argument by assertion?
For example, Perl 6 has the following syntax.
sub foo($foo) { ... }
multi sub foo(Int $int) { say 'int' }
multi sub foo(Str $str) { say 'str' }
First is normal subroutine. This is dynamic language feature.
Last two are function overloading. This is static language feature.
I think this is messy for user because dynamic features and static feature are mixed.
My proposal is that how about separating dynamic feature and static feature in Perl 5.
package Foo;
sub foo ($foo) { ... }
package Bar : static;
sub foo(Int $int) { say 'int' }
sub foo(Str $str) { say 'str' }
Function overloading is indeed a static language feature.
But the
multi
keyword doesn't provide static function overloading.The
multi
keyword provides dynamic multiple dispatch.Function overloading occurs at compile-time, when the compiler looks at the static types of the declared arguments to an overloaded subroutine or method and selects which overloading to call on the basis of those compile-time types.
Multiple dispatch occurs at run-time, when the interpreter looks at the dynamic types of the actual arguments to a multisub or multimethod, and selects which variant to call on the basis of those run-time types.
(I originally explained the important difference between the two concepts in one of the original Perl 6 Exegesis documents.)
So the
multi
keyword is a perfectly appropriate addition to dynamic languages like Perl 6, and maybe even eventually to Perl 5.Indeed, you can use multiple dispatch now in Perl 5 via the
Class::Multimethods::Pure
orKavorka
CPAN modules, and soon via the (next release of) theDios
module as well.Damian Conway
Thanks for your comment.
I think is is not good because performance cost occur when type check is done at run-time,
and it increase launguage complexity.
Perl has already complex syntax. I don't hope more complexity.
For example, I like cpan-minus than cpan-plus. why? cpan-minus is fast, minimal and enough.
I like small aproach which can solve problems smart.
For the long time, Perl is complained for the dirty and complex syntax.
We should recognize more perl complexity is more week point of Perl language.
I strongly oppose the mix of dynamic features and static features in one space.
It mix the week point of dynamic language and the week point of static language.
It don't mix the good point of dynamic language and the good point of static lanuage.
It is slow and complex things.
It is not simple and fast things.
My proposal is that "how about implementing real static features in static package?".
static package is optimised for performance, less memory, and parallelization.
Perl can call the method of static package.
golang is good example.
golang has many syntax limitaion.(not exception, not inheritance, not generics).
but the limitation is good for performance, compile speed, less memory, and parallelization.
I think Perl need the question "What limitation is good for us?".