I like pair programming, just not with you (know your text editor)

Posted Friday, August 04, 2006 8:16 AM by mhodnick

Pair programming is an important part of modern-day, agile software development processes. It helps developers write better software. Pair programming is a good thing.

However, I usually can't stand watching someone else write code, or watch someone else do anything on a keyboard for that matter. It's like getting teeth pulled. No, it's like getting teeth pulled while walking on hot coals and self-inflicting paper cuts.

Book A few of us at work are reading The Pragmatic Programmer, which stresses knowing how to squeeze every drop of coding power out of a text editor. A developer's text editor (or IDE) is to code as a woodworker's saw is to wood. I couldn't agree more. The better you know how to work the keyboard the faster (and easier) you will be able to write code. And I'm not even talking about editors like VI and Emacs - I'm even just talking about basic Notepad operations (although I hope you're not using Notepad to write your apps).

So, here are some basics (at least on a Windows OS) that will leave your mouse-wielding co-workers in the dust, and will make me pleased to pair-program with you:

  • Ctrl+X, Ctrl+C, Ctrl+V Cut, Copy and Paste
    95% of developer already know these, but they save you the hassle of choosing the cut, copy, and paste commands from a toolbar or menu.
  • Ctrl+[right/left arrow] Move word to word
    This will move your cursor to the next "non-alphanumeric" character in a file. Meaning, if you have spaces between words it will stop at each space. Handy for moving quickly down a line of text rather than just the arrow keys alone.
  • Shift+[arrow keys] Select text
    Allows you to select (e.g. highlight) text without using the mouse. Use the left and right arrows to select adjacent text, or the up and down arrows to select entire lines of text.
  • Ctrl+Shift+[right/left arrow] Select text word to word
    This is like the Ctrl+[right/left arrow] and Shift+[arrow keys] commands combined together. You can select words while moving your cursor rather than single characters at a time.
  • Home and End keys Go to the beginning or the end of a line
    These are arguably two of the least-utilized keys by developers.
  • Ctrl+Home and Ctrl+End Go to the beginning or the end of a document
    It's like the Home and End key behavior on steroids.
  • Ctrl+s Saves the file
    I'm surprised at how many people still use the mouse to move their pointer to the Save button a toolbar. This shortcut will prolong carpal tunnel syndrome by 0.01% each time you use it. All major Windows text editors support this.
  • Alt, with arrows Navigates menu bars
    You should know keyboard bindings for commands specific to your favorite text editor. For example: closing the text editor, code indenting/formatting, etc. But if you don't, you can use alt key to enable keyboard command of the menu bar and then use the arrow keys to navigate it.

Once you've gotten the hang of these, using them in combination with each other gives you more power. For example, if you want to delete the line that your cursor is on, use the End key, then Shift+[down arrow] to select the line, then delete.

As I already mentioned, you'll need to go beyond the basic text editing commands to harness all the power of your text editor. Get to know the keyboard bindings that your editor supports to complete certain tasks and operations. You should also be able to set up custom bindings to perform commands. For example, if you really want to use the Ctrl+U, Shift+X sequence to auto-indent and format your code, then you should be able to set up that binding in your editor. If you can't do that with your text editor or IDE, then you might want to try a different one. Being able to set up a Rebuild All command in Visual Studio .Net from the keyboard is one of my first tasks after a fresh install.

Take all this only as a suggestion. I don't think you have to use keyboard shortcuts to be a good developer, and there's probably somebody out there who is faster than me by using a mouse. However I've never met such a person, and their right wrist is probably throbbing right about now. You need to do what is comfortable to you so that you like your development environment and can get your job done. But if I'm pair programming with you and you see me falling asleep as you use the mouse to select some text, now you'll know why.

Filed under:

Comments

# re: I like pair programming, just not with you (know your text editor)

Friday, August 04, 2006 12:14 PM by mhodnick

A friend suggested to me that pair programming can also be a problem when a) the other developer smells and b) the other developer is stupid.

# re: I like pair programming, just not with you (know your text editor)

Friday, August 04, 2006 2:03 PM by bvandervoort

One I find myself using a lot after I found out about it is Ctrl backspace/delete.  It will delete backward/forward to the beginning/end of the word.  So if you have let's say  someObject.somelongwordMethod(), get the cursor in front of the M, hit ctrl backspace, and somelongword is gone.  Much faster than using the mouse to try to highlight what you want to delete.

One that bugs me is when people don't realize shift-tab will go backwards through a tab order.

# re: I like pair programming, just not with you (know your text editor)

Monday, August 07, 2006 3:47 PM by vbullinger

A couple I like:

Alt + Tab: switch applications (code to IE, for example).  I use this all the time.  Then you don't have to scroll your mouse down to the bottom of the screen to switch applications.

In VS:
Ctrl + Space: pull up Intellisense
Shift + Alt + F10 (2005 only): insert a "using" statement when you haven't included something that is required or to create a method stub for a method you just typed that isn't defined.  I.e., you type "bool printed = PrintSomething(int numChars, String stringToPrint);" and you'll see a red mark underlining the last character in what you just typed, indicating that it didn't recognize that method, but is ready to create the stub for you if you press shift + alt + F10.  If you do press that, you'll get a little drop-down.  Press the "generate method stub" option and it will just plop down what is needed.  In this case, it knows that you're setting a boolean to the return value of this method that it's writing the method stub for, so it will know to declare it as "private boolean PrintSomething."  It also knows that you are sending it an integer and a String, in that order, so it will put that in the method declaration, as well.  I.e. "private boolean PrintSomething(int blah, String blah)."  It usually picks odd names for the parameters, though.  It will then put the squiggly brackets - { } - and put one line in the method... which is basically a line that throws an exception saying that the method is not defined.  Can be a decent time saver.  And you won't have to scroll up to put "using System.IO;" at the top if you realize you need to use the FileInfo object or something.

# re: I like pair programming, just not with you (know your text editor)

Wednesday, October 25, 2006 3:26 PM by Tim

This may not be a keyboard shortcut, but it's helpful nonetheless, and apparently not that realized since most people here don't know about it.  If you want to open a file rather than relying on the editor's open dialog if you have the folder open in Explorer, just start dragging the icon for it, alt-tab to the editor, and drop it in the editor.  I normally keep Explorer open and navigate my files with it so it's usually open to whatever project I'm working on.  It's way faster to just drag and drop than deal with the open dialog.  Plus, I did this while some people were watching me solve some problem and they were like, "How'd you open that file so fast!"  Yes, you can double-click a file too in Explorer, but depending on your file associatons the file may not open in the program you want.