Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: The value of declarations

by moritz (Cardinal)
on Apr 07, 2009 at 14:35 UTC ( [id://756043]=note: print w/replies, xml ) Need Help??


in reply to The value of declarations

I share your love for strict and declarations, and I'm pleased that Perl 6 has strict mode enabled by default (except for one-liners).

It also comes with very expressive signatures, different declarations for subs and methods (which also improves introspection) and all sorts of other things you can expect from a modern programming languages. Heck, even sub names will be checked at compile time (actually at CHECK time, iirc) and you'll get very friendly error messages.

Replies are listed 'Best First'.
Re^2: The value of declarations
by TimToady (Parson) on Apr 07, 2009 at 16:45 UTC
    The one place where the design of Perl 6 doesn't quite jibe with this meditation is that, while Perl 6 can do compile-time checking of named arguments on subroutines, it refuses to do so for method calls. (It does this by supplying a default slurpy %_ parameter to methods.) The reasoning for this is that base methods should be allowed to ignore named parameters that are intended only for derived methods, and vice versa. Perhaps there is some way to check named arguments against all the candidates at run time, but it seems as though this could get expensive, and we're at least trying to maintain the hope that Perl 6 could be very fast in theory, even if 6.0.0 doesn't actually achieve that. (And we don't expect it to, since we're optimizing for correct over fast for now.) Anyway, we're still open to ideas in this area, maybe an optional check that only runs first time when dispatch order is established (or reestablished).
      I wonder, can you do any reliable compile time checks on methods at all? I think this is valid:
      my $x = eval 'class A { method foo($bar, $baz} }; A.new'; $x.foo();

      Any compile time check would complain about a missing method.

        Some checks could be done if you had a way to tell the compiler you weren't going to do something like this.

        __PACKAGE__->no_monkey_business; # no new methods/method signatures c +an happen now. # or perhaps use static_methods qw( MyClass ); #compile this class with only expli +citly declared methods allowed.

        Where the declaration says that only the methods that exist for the class at that time, or perhaps those that have been explicitly declared are available.

        Even better if you could turn it off from outside the class file, so you could do some monkey patching if needed:

        # in main: no static_methods MyClass; # uses MyClass with static_methods turned +off.


        TGI says moo

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://756043]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-12-06 04:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which IDE have you been most impressed by?













    Results (39 votes). Check out past polls.