Showing posts with label Keyboard Shortcuts. Show all posts
Showing posts with label Keyboard Shortcuts. Show all posts

Saturday, April 12, 2008

Eclipse Shortcuts: or To Eclipse and Back Again

Recently I shifted from coding in VisualStudio+ReSharper to coding in Eclipse. Again. And me being very much a keyboard shortcuts person, I needed to find Eclipse equivalents for all my favourite ReSharper shortcuts. Déjà bloody vu. So I decided I'll spend some time and record the Eclipse versions of my oft used shortcuts for the next time. Here they are:

Most Used
Ctl+Space : completion
Ctl+1 : Quick fix suggestions
F2 : Show tooltip (javadoc, help)
Navigate
F3  : Go to declaration
Ctl+Sh+T : Open type (class)
Ctl+Sh+R : Open resource (file)
Ctl+O : list class members
Ctl+. : Next error/warning/search result
Ctl+E : switch to an open file
Alt+Left : Previous cursor location
Alt+Right : Next cursor location
Ctl+Q : Last edit location
F12 : activate editor
Ctl+M : maximise or restore active view
Ctl+J : Incremental search
Ctl+Sh+J : Incremental search backwards
Ctl+Sh+G : Find references in workspace
Ctl+Alt+H : Open call hierarchy
Alt+Sh+Q,S : open search view
Ctl+F7 : cycle through views
Alt+Sh+Q,P : package explorer
Debug
Alt+Sh+D : Debug menu
Ctl+Sh+B : toggle breakpoint
Ctl+Sh+I : inspect
F5 : Step into
F6 : Step over
F7 : Step out
F8 : Resume
Launch
Alt+Sh+X, T : Run tests
Ctl+F11 : Run last launched
Refactor

Alt+Sh+T : Refactoring Menu
Alt+Sh+M : Extract Method
Alt+Sh+R : Rename
Alt+Sh+C : Change method signature
Alt+Sh+I : Inline variable/method
Alt+Sh+L : Extract local variable
Alt+Sh+V : Move
Code
Ctl+Sh+F : Format
Ctl+Sh+O : get rid of redundant import statements
Alt+Sh+Up : select enclosing element/widen selection
Alt+Sh+Down : narrow selection
Alt+Sh+S : Source menu (override, create constructor,...)
Alt+Sh+Z : Surround with menu (try/catch, for,...)
Alt+/ : word completion
Ctl+Alt+Up : duplicate line

One of these days I should make this list for ReSharper and IDEA as well.

In the meanwhile, if there are any of your favourites I've missed, do let me know.

Tuesday, February 12, 2008

The Magic Number: Another Reason to Learn Your Tools

We developers are often paid to get productive quickly on a large, unfamiliar code base. There are many ways of doing this. One way of NOT doing this is to start from public static void main1 and work your way through each function or class or module till you understand what you want - that way lies failure and madness.

I can think of 3 ways of getting to grips with new code:
  • Use external sources: Talk to others who understand the code base better; Read the documentation; Watch a tutorial screencast; ...
  • Use the debugger: Step through the code and see what it does.
  • Use the Source, Luke: Read through the code.
Of these, I've found the last the hardest. It is this skill - reading through code - that I want to talk about today.

When I say "read through the code", I use read in a sense that is very different from reading a novel or even a text book. It's more of jumping around the code base, reading a bit here, taking in a whole class at a glance, poring over a single method for over an hour, finding the usages of said method, ... If you are a programmer, you know exactly what I'm talking about. While doing this, you are attempting to build a mental picture of what is going on in the code. This is where the Magic Number comes in.

The idea is that human beings2 can only handle a limited number of pieces of information in their working memory. You can think of working memory as the set of registers on your computer's CPU - all of your thinking happens on pieces of information that is in the working memory, and there is a limited amount of it available. Even though you may not agree with the range 5 to 9 specified in the article, for the purpose of this post, it is enough if you accept that there is a limit.

Here's how I think the code reading process works: You start off with understanding a small piece of code - piece A, let's say. Then piece B. And D. And then how B and D are related via C. And Z. Five of the slots in your working memory are now filled. Suddenly you realise that all these pieces are part of the English alphabet - and boom! five used slots shrinks to one used slot! The larger chunk - English Alphabet - occupies just one slot worth of space. You are essentially building up more powerful abstractions with which you are able to explain the purpose of ever larger swathes of code. So your ability to comprehend code depends on how many free slots you have in your working memory.

"Ok, even if all that is true, where do keyboard shortcuts come in?", you ask. Well, which keyboard shortcut to use is a piece of information too. If you are not very familiar with your IDE, then thinking about which keyboard shortcut to use will take up one or two registers in your working memory. Your brain has less free registers and hence is a slower computer. On the other hand, if you are really familiar with your IDE, your fingers automatically press the right key-chord when your brain thinks "I wonder what that method does?" and take you to the definition of the function. This process doesn't use the 5-9 registers at all, but is muscle memory a la riding the bicycle or swimming. More registers to understand the code implies faster understanding.

There is another factor involved as well: frustration. When you are struggling with the tool, the resulting frustration will make you want to take more breaks from your task of understanding the code. When the tool is almost an extension of you, the feeling of being in control will allow you to work longer periods. This is one way the human brain is different from computers - the latter doesn't get tired.

I don't have proof to offer for all the claims I'm making; I do have anecdotal evidence though.
Exhibit 1: While reading Java code, I'm much faster while using IntelliJ IDEA than while using Eclipse. I believe that Eclipse and IntelliJ IDEA are pretty much equal feature-wise. I attribute my higher productivity on IntelliJ IDEA entirely to my much greater familiarity with its shortcuts.
Exhibit 2: I find it easy to switch between reading C# and Java. I think a lot of the credit should go to JetBRAINS' - their masterstroke of reusing the IntelliJ IDEA's shortcuts in ReSharper means minimal muscle memory retraining when switching between these languages.

All of the above are arguments for learning to use your IDE really well - they could apply equally to using the mouse as well. Here's why I prefer the keyboard: accuracy and speed. With the mouse, I'm a bit of klutz. I click the wrong piece of code. I select the wrong region. I'm really slow at reading the available menu options and very likely to pick the wrong one even after all the reading. And my hands ache when I use the mouse for a while. With the keyboard, especially my trusty old Kinesis Classic, I'm fast and accurate. This leads to less mistakes, less frustration and more time spent reading and processing code. Ergo, Happy Developer.

And that's another reason to learn touch typing!

Are you a predominantly mouse person or a keyboard person? Either way, what are your reasons for preferring one over the other?



1 Or its moral equivalent in your favourite language.
2 That typically includes us programmmers as well.

Friday, January 25, 2008

Shortcuts to Impressing Developers

If you have been wondering whether it is worth your while to learn the keyboard shortcuts on your favorite IDE*, then here's another reason apart from the obvious one of blazing fast productivity.

I often teach a course on Object Oriented Programming and Design Patterns called the Object Bootcamp. The participants are typically other developers. I'm yet to see two developers who will not disagree about at least one aspect of Object Oriented Programming. Given that the course advocates a particular style of OO which would surprise the average programmer, getting the audience to listen is crucial.

Thankfully, the course is very hands on - it involves getting the participants to write some code to solve a problem and then critiquing** their code. I also normally refactor the code that I'm critiquing. Navigating the code and refactoring, both afford excellent opportunities to show off my skills with the IDE. Being able to select a block of code, do a Ctl+Alt+M and have IntelliJ Idea or ReSharper extract that block into a well-named method, as well as highlight and replace other similar code in the file, usually impresses other developers no end. Even simpler features like hitting Ctrl+B to get to the definition of the class or method are often quite alien to most developers. It makes you, in their eyes, a person who knows where his/her towel is and hence they are more amenable to letting you have your say.

The opportunities to impress others with your keyboard shortcuts are legion. Maybe you are giving a presentation to an audience which involves showing some code. Maybe you are interviewing for a company like my employer ThoughtWorks which invites you to pair program with one of your future colleagues as part of the hiring process. Maybe you are collaborating with your boss on creating a Word doc. In each of these situations, knowing and using keyboard shortcuts can give you that aura of competence - at least for a while.

What has your experience been with keyboard shortcuts? Have you seen others react differently to people who use keyboard shortcuts?


* You do use an IDE, right?
** Critiquing = PC terminology for projecting the code for the whole class to see and tearing it to pieces, thus publicly humiliating the author. The theory is that this builds character.;-). Just kidding! Developers seem to learn very well from their mistakes.