<< Something's Going On In The XML World | Home | The C++0x Working Draft: Get It Now >>

Friday Java Non-Quiz: Sharing An Obscure IDE Trick Day

If you couldn't tell from last weeks questions that I'm running out of legitimate Java quiz questions, I don't know how loudly I have to say it.

Let's face it, Java is a pretty low-surprise language. Tedious maybe, but never mysterious. The contrast with C++ is astounding. I have to debug some JNI code yesterday, and when I got to the C++ part, I do indeed have to stare at lines like

int a = 0;
foo(a);
if (a == 1) bar();

and go, "That's impossible!"

Anyway, I did learn a new IntelliJ IDEA trick recently from the IDEA Refcardz. Thanks to CodeToJoy for alerting me to their existence.

It's Ctrl-Shift-UpArrow and Ctrl-Shift-DownArrow. What it does is to move things up or down within scope:

  • If the cursor is on a statement, it moves the statement relative to adjacent statements. The movement stops when the statement hits an opening or a closing brace of a if statement, while statement or a method definition.
  • If the cursor is on the name of a method or a field, it moves the method or field up or down relative to other methods or fields within its defining class.

What other IDE tricks have you learned recently? Can you do what I just described in your favorite IDE, Java or other languages?



Re: Friday Java Non-Quiz: Sharing An Obscure IDE Trick Day

C# has a nice solution to this problem: "ref" and "out" are explicitly written at the call site http://msdn.microsoft.com/en-us/vcsharp/aa336814.aspx

Re: Friday Java Non-Quiz: Sharing An Obscure IDE Trick Day

C also has a nice solution to the problem: use &.

Re: Friday Java Non-Quiz: Sharing An Obscure IDE Trick Day

Yes, but then you lose the two important guarantees of references, 1) can't be null and 2) can't change what they refer to.

Re: Friday Java Non-Quiz: Sharing An Obscure IDE Trick Day

Sure you can ;) It is a common C idiom to pass a ** to a destroy function in order to be a 'good citizen' and change the original pointer to point to NULL. Granted its a little ugly, but I think the intent is a little more clear than C++ references.

Re: Friday Java Non-Quiz: Sharing An Obscure IDE Trick Day

Thanks for the shout-out, Weiqi

In Eclipse, Control-Shift-L is a favourite because it shows me other shortcuts... one ring to find them all


Add a comment Send a TrackBack