On Wed, Dec 18, 2002 at 09:31:41AM +0000, Piers Cawley wrote:
> Dave Storrs <[EMAIL PROTECTED]> writes:
> > It seems like Perl6 is moving farther and farther away from Perl5's
> > (almost) typelessness.
>
> It depends what you mean by typed. Perl has always had strongly typed
> *values* (which strike me as being a damn sight more useful than
> typed variables).
No argument from me. When I want/need the abilities that come with
specifying type, I want the language to support it. I just don't want
to _have_ to do it, when I don't want/need those abilities.
>In a language with typed values, being able to
> declare a typed variable is useful for a few reasons:
>
> * After watching things in a profiler, you sacrifice programmer
> flexibility by typing a couple of variables as a way of giving the
> Optimizer something to get its teeth into (if you have a typed
> variable then you can limit the amount of runtime checking you have
> to do in favour of compile time checks)
Agreed.
> * For setting up multiply dispatched methods and functions. Consider
> the example below (which I know I've used before).
>
> sub grep ( (Rule | Block) $selector, @*args ) { @args.grep($selector) }
> sub grep ( (Rule | Block ) $selector, Collection $collection ) {
> $collection.grep($selector)
> }
>
> sub grep ( WeirdSelector $selector, @*args ) {
> grep $selector.as_block, *@args;
> }
>
> Because we can declare the types of the function parameters we can
> let the language sort out the dispatch for us. Without typed
> parameters and multi dispatch those three function definitions
> become:
>
> sub grep ( $selector, $first, @*args ) {
> if @args.length {
> return [ $first, @args ].grep($selector);
> }
> else {
> $first.grep($selector);
> }
> }
>
> method Object::grep ($self: $selector {
> [ $self ].grep($selector);
> }
Hm. I'm way short on sleep today, so I'm probably missing something,
but I don't see why Perl can't sort this out without a specific
typing.
On a more nit-picky level, the first two subs in the top block seem to
show that arrays are not derived from Collection. Surely, if
everything is an object, they should be?
> Which, to my way of looking at things is deeply ugly.
I certainly find the first version easier to read...which, given my
particular set of prejudices, makes it enormously preferably in my
eyes.
> * And last and least, for 'strictness'. Personally I think this is
> the least useful choice; the programmer sacrifices flexibility for
> having the compiler catch errors that would be more usefully caught
> in a test suite. And to make matters worse, if you want the
> compiler to catch the errors you have to make *everything*
> explicitly typed, and and life's too short for buggering about like
> that thank you very much.
Agreed.
--Dks