Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Perl IDE and New Foreign APIs

by tomazos (Deacon)
on Sep 09, 2005 at 08:20 UTC ( [id://490465]=perlmeditation: print w/replies, xml ) Need Help??

Further to this non-article (476795) that I'm not going to write, I've been working through O'Reilly's "Java Examples in a Nutshell" exercises in Eclipse 3.1 with Java 5 (or 1.5 or 2.0 or J2SE, I wish Sun would sort their versioning out and have their marketing department shot). I also tackled some 1000-point questions on TopCoder in Java. Some of them are actually difficult (admittedly usually because of the physics or numerical analysis involved and not for the language contortions). On TopCoder I also saw more C#/.NET code. (I’m interested to know why there is a fork from Ruby to C# in the levenez’s language history - haven’t quite worked that out)

The biggest differences in workflow that I've noticed, apart from the Java code being on average about four times as verbose as the equivalent Perl code (and Java 5 language proper approaching the design of C++ at an alarming rate), I think comes from the some of the niceties of the Eclipse IDE.

I’m no emacsian-master by a long shot. To come clean, I’ve actually been using EditPlus2 on a Windows client machine to edit my Perl code. I started out using WIMP GUI IDEs 15 years ago and never got out of the habit. I think it has something to do with that whole “recognition vs recall” thing - and I have a short memory sometimes.

Being more specific:

In Eclipse you have a javadoc window open that follows your cursor. Whenever you go over a symbol in your source it displays the documentation associated with that given symbol (by looking at the symbol’s source code and parsing out the comments like perldoc). You can also go to the Type Hierarchy and get a tree of the sub/superclasses of the class you are looking at (with methods). After you type a class name or instance identifier in the source you can hit CTRL-space and it will give you a drop down menu of all the methods it has. You can select one and it types the function name for you.

Why not something similar in Perl? Or what is some of the equivilant in Perl IDEs (emacs for example)? Take Set::Object for example. My usual workflow would be to cpan install module, copy and paste the Synopsis into my code and then munge it into what I need, and then hopefully remember the API if I need to use it again.

I’m sure there must be equivilant magic in Perl-land.

I guess my question would be how do you work with a new foreign API in Perl? Is it a matter of studying the entire module's perldoc in a seperate window and then retaining that information when writing your source? Is there a way in your Perl IDE (eg emacs) to get to the documentation of a given package or blessed reference at the cursor?

More generally, what are some of the tricks you use to do things that offer the same benefits as the features of a recognition-based IDE?

As a specific example using Set::Object - Let's suppose you wanted to use it but didn't know anything about it. Can you describe in detail your workflow of acquiring and using the API through your Perl environment?

-Andrew.


Andrew Tomazos  |  andrew@tomazos.com  |  www.tomazos.com

Replies are listed 'Best First'.
Re: Java vs Perl and Eclipse vs Emacs (serious)
by castaway (Parson) on Sep 09, 2005 at 08:32 UTC
    I've just skimmed through this.. You should maybe be a bit more loose in your questioning, you appear to be assuming that everyone that programs Perl uses Emacs, and everyone programming Java uses Eclipse, clearly this is not the case.. To allow everyone to answer, and not with "But don't use Emacs, use Editor XXX", you should maybe invite comments from users of other editors as well. (I also suspect you'll get a lot of comments about Emacs not being the most advanced Perl IDE too.. but thats your choice I guess)

    First note though: Have you looked at the Perl plugin for Eclipse? I think its http://e-p-i-c.sourceforge.net - I'm not sure it does simultaneous docs though..

    In Emacs, anyway, I use the wonderful "split window" command (ctrl-x 2), and open the manpage of whatever I need in the second window (ctrl-x o M-x man Set::Object), or just have it open in another terminal.. Since I don't use my editor windows full screen, that works fine too.

    C.

      Thanks castaway. I've updated the post to reflect your suggestions.

      I will have to take a look at the Perl Eclipse Plugin. Thanks again.

      -Andrew.


      Andrew Tomazos  |  andrew@tomazos.com  |  www.tomazos.com
Re: Java vs Perl and Eclipse vs Emacs (serious)
by chb (Deacon) on Sep 09, 2005 at 08:49 UTC
    I usually tweak my emacs to show me documentation (perldoc, hyperspec, man...) on F1 in every language I work with. I would hate it if the IDE documentation flickered everytime the cursor moves to a new symbol (I have never worked with eclipse, I actually guessed this behaviour from your description - might be terribly wrong or not as annoying as it sounds to me).

    I had somewhat bad experiences with code-completion-helpers in delphi, which didn't always work reliably, which is, in my opinion, worse than having no such thing. Maybe eclipse performs better. To save typing I use dabbrev-expand in emacs. It looks just at the text in my edit buffer and doesn't try to parse the language. This is, of course, a rather low-level approach, but it has the big advantage of 'no surprises'.

    If I need to find available methods in a class, emacs can always jump to its declaration with a few keystokes (via tags, cscope etc.). This even works if there is a lump of uncompileabe code before the point I'm working at. Can eclipse handle that?

      You're most likely right about the flickering. You most likely wouldn't like the Microsoft Word style underlining of things (red for error, yellow for warning) and the menu of suggestions it offers to fix things ((a) import java.util.regex.* (b) remove Matcher (c) define new class Matcher etc) either. :)

      I've taken a look at dabbrev-expand. I think it doesn't check a foreign namespace unless you point it at the file. This is what you mean by low-level. I guess in Eclipse/Java it compiles the code continuously and autocompletes methods based on the current class or identifier at the cursor (and only them).

      When you say jump to the declaration? You mean in a different buffer it opens the file that declares the symbol? I think if the buffer doesn't compile in eclipse it will only work for class names (take you to their entry in the Type Hierarchy browser window or the original source) - otherwise it can't know which member is from which class.


      Andrew Tomazos  |  andrew@tomazos.com  |  www.tomazos.com
        You mean in a different buffer it opens the file that declares the symbol?

        yes, exactly. And yes, you are right, I don't like word's underlinings and other uncalled-for visual distractions like popup-menus :-)

Re: Perl IDE and New Foreign APIs
by itub (Priest) on Sep 09, 2005 at 15:18 UTC
    I use vim, with a couple of custom tricks. 1) the K key in normal mode calls perldoc -f and perldoc on the word under the cursor. 2) tab at the end of a word when in insert mode autocompletes the current word based on words in the current buffer, the alternate buffer, and some other places I don't remember (I think it can also search included files and a "dictionary file").
Re: Perl IDE and New Foreign APIs
by chanio (Priest) on Sep 10, 2005 at 03:59 UTC
    When I started trying M$ Visual Studio some years ago, I was amazed with those lots of 'gadgets' and its intuitiveness. But some months later, I found myself coding with the Notepad. Just because of the antipedagogic direction of the use of such things. It doesn't let you think ahead, you always have to be choosing things, and you can't remember what you have just typed. A kind of 'Doom'-like defensive programming!

    On the other side, you find that all the difficulties of learning how to use emacs would some day allow you to live in a complete city of awsome things (send emails, read news, know about the weather, callendar, chat, etc.).

    I now, find myself comfortable using SCite (for me, the best of both worlds). That is easily customizable at most of my needs.

    Besides, it seems that all the creators are actually avoiding to start a new and expected era of programming tools. Today, they are all very much alike! And the new thing in all, seems to be M$'s way of programming.

    I would like to see some shortcuts that could start a chosen programming schema to apply to the selected code. That would launch a special screen with a graphical drawing where one would name variables and functions involved in that sort of 'pattern'. More 'drawings' for coding. More colors to paint zones. More animations to show 'tendencies'. But all easy to enable/dissable when needed. Every code should have its own personality, its own world.

    Yet, XML is not well used as another programming tool. It should talk standards.

    A perl IDE shouldn't be based in such relative language expressions as perls. But in a more general sense, in the flow of all the script...

    If some IDE could have a tool to dessign screens with Tk, it would become the most famous choice from all the rest of graphical modules.

    { \ ( ' v ' ) / }
    ( \ _ / ) _ _ _ _ ` ( ) ' _ _ _ _
    ( = ( ^ Y ^ ) = ( _ _ ^ ^ ^ ^
    _ _ _ _ \ _ ( m _ _ _ m ) _ _ _ _ _ _ _ _ _ ) c h i a n o , a l b e r t o
    Wherever I lay my KNOPPIX disk, a new FREE LINUX nation could be established
Re: Perl IDE and New Foreign APIs
by wazoox (Prior) on Sep 13, 2005 at 10:36 UTC

    I'm using nedit (http://www.nedit.org) as my standard editor since 1997 at least. However I didn't expanded it much (using macros, etc) until recently. here's what I've done :

    • I've written a "calltips" file that provides help on perl internal functions. (you'll find it here : Nedit perl calltips and on ftp.nedit.org)
    • I've written a couple of macros to generate ctags file, that can be used to provide contextual help to current files functions in the same way the calltips do.
    • I've modified an existing macro to provide autocompletion to perl internals and current file stuff (no parameters completion for now though)
    • I've written some other macros to compile the scripts, run them, etc.
    • I've also written a macro to use Devel::Refactor with a single keypress, just like in Eclipse.

    Well that's all for now, I don't really feel the need for any other tool right now, I'll try to get paramater completion if possible when I have some spare time...

    In case anyone's inteested in the nedit stuff, here's the "refactor" macro and script:

Re: Perl IDE and New Foreign APIs
by blakem (Monsignor) on Sep 10, 2005 at 12:00 UTC
    We use a highly customized emacs at work... A few of the features we've added are:

    - Jump to perl-thing-at-point, whether its a method, module, constant, subroutine, or filename
    - Show the inheritance hierarchy of this module, or the one under point
    - Add a use line for the class under point
    - Deparse a chunk of highlighted perl, adding parens to clarify precidence
    - Jump from code to test (and vice versa) in one button
    - Run the unit test
    - Update the test count
    - See the current cvs diff for this file or sandbox
    - Navigate previous cvs changes for this file
    - Show the entire CVS checkin that added a particular line
    - Apply/Revert a hunk from a cvs diff file
    - Show CVS annotation or log comment for current line
    - Jump from a CVS diff file directly to the line in the code
    - Insert a random MAC address (for writing unit tests)
    - Insert a source filter around the current block so only a portion of the unit test is run, so you can focus in on a particular test thats failing
    - Toggle formatting of lists or hashes that span more than 80 columns
    - find all occurances of a string in our code base
    - show all methods named X
    - find all callers of method X
    - Jump to the SUPER method of the one you're overriding
    - Jump to the superclass of the current module
    - run 'make' with various useful targets
    - Display the apache error logs in a way that makes them easy to read and jump quickly to source of the error
    - make sure the current perl file compiles cleanly
    - pull up a perldoc on whatevers under the point
    - Insert various useful debugging lines temporarily, i.e. Carp
    - toggle pairs of single quotes to double quotes and vice versa
    - Fold unnecessarily long copyright chunks into one line
    - Tab complete module names based on the .pm files in the filesystem
    - Toggle between prefix and postfix versions of if,foreach,while

    And thats just a quick list I came up with by scanning through our config file... I'm sure there's lots of other good stuff in there that I missed. Its gotten to the point where our die-hard vi users are beginning to transition to emacs so they can develop faster. ;-)

    -Blake

      Any chance of you posting your .emacs and any extra lisp that goes with it?

      loris

        I really would like to, but the code is technically owned by my employer. I doubt if there would be much push-back if I tried to get permission to release the code, but I haven't done that yet. The configuration is also rather customized for our code base, and would need to be massaged quite a bit to make it totally functional on another project.

        -Blake

      Pretty cool...I've been using Eclipse (on Java) recently, and it doesn't do a whole lot more than that, unless you count the "refactoring" tools or plugins you can add.

      So, how do you customize emacs like that? A bunch of lispy-config files? And how long did it take to get that kind of usefulness built up? It would come in very handy for some of my personal (Perl) projects, but I don't know if I have time to learn "yet another config language"...

        I would really like refactoring tools for perl... but the language makes it very difficult (some would say impossible) to get right.

        I'm working at an extreme programming shop, doing pair programming in perl. Most of the nifty emacs ideas came about while pairing. i.e. your pair says, "Lets go see how 'munge_data' is implemented." If it takes thirty seconds to get the method on the screen, it really breaks up the flow of the session, and you lose focus on what you we're doing in the first place....

        So, to answer your question, I've been at my current job for a couple of years now, and really only got into the highly-customized emacs craze within the last year or so... The configuration consists of a bunch of lisp functions, and some small perl utilities that get invoked from the lisp to handle the really tricky parts.

        -Blake

Re: Perl IDE and New Foreign APIs
by zby (Vicar) on Sep 10, 2005 at 13:56 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-25 20:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found