I haven’t typed an import statement in over a year

I’m reading The Pragmatic Programmer at the moment. Chapter 3 has a section about using power-editors; it has an example showing how easy it is to sort lines of the import section of a Java file in Emacs or vi.

Reading that felt strange. I remember doing the same thing in Emacs before, but I use IntelliJ IDEA for Java files now. But that wasn’t the strange thing.

I realized that I haven’t manually typed an import statement for over a year.

I don’t think I’ve even seen an import statement for a while. I keep the import statements “folded”. IDEA tells me if there is a redundant import statement by “greying” the folded import section, and Alt-Ctl-O fixes that. And it keeps them sorted in the right order, too.

  • anon

    btw, for emacs users, if you use the jdee package (http://jdee.sunsite.dk/) (if you’re doing any java development with emacs, you really should get it), you can import the class at point with C-c C-v C-z (jde-import-find-and-import). you can kill extra imports with jde-import-kill-extra-imports. you can sort imports with jde-import-organize (sorts java packages high by default, customizable to group otherwise) or jde-import-sort (does a strict alphabetical organization).

    also, i3sp has an ant task for creating jdee project files (http://sourceforge.net/projects/i3sp-build)

    not having to deal with import explicitly really is a great thing…

  • anon

    the link for i3sp-build got messed up. http://sourceforge.net/projects/i3sp-build

  • Robert BurŽn

    Please note that Eclipse ( http://eclipse.org ) does import handling rather nicely too! (At least for versions 2.1+, which is what I use.)

  • http://freeroller.net/page/oburn Oliver Burn

    Matt, you were never really a power user of Emacs. I tried to show you the JDEE package about 2 years ago. That said, I would take Eclise/IDEA over Emacs these days. The refactoring support is the killer difference.

  • http://blog.bitecode.com/ Glen Smith

    Timing! I pickup up my copy of the Pragmatic Programmer on Monday (which I ordered about four weeks ago). I’m only up to chapter one (but I did glance across that tip about editing).
    Even though Eclipse 2.1 is my main IDE on Win32 & Linux these days, I’ve actually started using jEdit as my general purpose editor (ie. text files, XML, perl, php, shell scripts). Does everything I want (on both platforms), has some wicked-cool shortcuts, and has syntax colouring for just about anything I’ve even heard of.
    The idea of knowing one editor really well (as opposed to just IDE) is still a cool idea worth exploring, I reckon. Ditto for the shell.