Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Request for Comments: More annotations for Perl plugin for IntelliJ

by hurricup (Pilgrim)
on Jun 20, 2016 at 19:05 UTC ( [id://1166129]=perlquestion: print w/replies, xml ) Need Help??

hurricup has asked for the wisdom of the Perl Monks concerning the following question:

This is a real request for comments and suggestions. If you are using Perl plugin for IntelliJ, you could see that it uses annotations to help working with project and resolve methods, like #@deprecated, #@returns and #@method

Currently I'd like to add two more annotations and thinking about the proper format.

Variable Types

Currently, variable type may be guessed by the plugin by explicit type definition, like my Foo::Bar $var; or by return value, like my $var = Foo::Bar->new();

Perl explicit type has a flaw: you can't specify different types on multiple declarations, only one for all of them, like my Foo::Bar ($var1, $var2, $var3);, what is not really convenient for arguments unpacking, so you need to change compact format to larger and slower multiple shifts.

So the idea here is to introduce #@type annotation and unpacking will look like:

my ( $self, #@type Foo::Bar $foobar, #@type Foo::Baz $foobaz ) = @_;

For arrayrefs and hashrefs i'd like to use Moose format from isa parameter of has statement: HashRef[Foo::Bar] and ArrayRef[Foo::Bar].

Subs arguments

To improve subs signatures on auto-completion and auto-completion itself, I'd like to add #@args annotation, which may provide additional information about sub argument, like type, optionality and named arguments. Example:

#@returns Some::Class #@arg $arg1 Foo::Bar # some description #@arg $arg2 Foo::Baz #@arg $arg3 # just a description #@arg %args key1, key2 Foo::Zoo, key3 sub somesub{ my ($self, $arg1, $arg2, $arg3, %args) = @_; }

This idea is pretty new, so I don't really know what is the best way to do this. Typing format is pretty obvious but other features - not.

Optional vs mandatory:

#@arg [$var1 HashRef[Foo::Bar]] # description or #@arg optional $var1 HashRef[Foo::Bar] # description or #@oarg $var1 HashRef[Foo::Bar] # description

Named parameters looks pretty solid, aside it's not possible to add a description, but not sure how to use it yet anyway.

I'm also going to make possible to move all subs annotations to a separate file, like Python stub file, it's necessary to work with external OOP modules, which are not annotated and won't ever be.

Please, share your ideas and suggestions.

Replies are listed 'Best First'.
Re: Request for Comments: More annotations for Perl plugin for IntelliJ
by Corion (Patriarch) on Jun 20, 2016 at 19:08 UTC

    For subroutine signatures, why not simply have people use subroutine signatures as god intended? The effort of adding the custom signatures as comments seems to be about equal to adding the signatures directly...

      Well, because at least

      WARNING: Subroutine signatures are experimental. The feature may be modified or removed in future versions of Perl.

      And it's not good practice to use experimental features in production code. And if I remember right, in one of the latest versions signatures syntax been changed (position). And default signatures does not supports typing. And I can't force other authors to use them, so can't have completion/navigation on their modules.

        :)

        comments or experimental feature,

        comments or experimental code,

        comments or code

        comments or code

        comments or code

        Hmm, comments just aren't code

        Is anyone (even you ) using this annotations feature? More than to simply try/test it out? That you've gotten at least one feature request about it?

        Keeping the stuff in a separate file sounds good :D

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-19 22:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found