An Ideal Keyboard Layout for Programming [closed]
I often hear complaints that programming languages that make heavy use of symbols for brevity, most notably C and C++ (I'm not going to touch APL), are difficult to type because they require frequent use of the shift key. A year or two ago, I got tired of it myself, downloaded Microsoft's Keyboard Layout Creator, made a few changes to my layout, and have not once looked back. The speed difference is astounding; with these few simple changes I am able to type C++ code around 30% faster, depending of course on how hairy it is; best of all, my typing speed in ordinary running text is not compromised.
My questions are these: what alternate keyboard layouts have existed for programming, which have gained popularity, are any of them still in modern use, do you personally use any altered layout, and how can my layout be further optimised?
I made the following changes to a standard QWERTY layout. (I don't use Dvorak, but there is a programmer Dvorak layout worth mentioning.)
- Swap numbers with symbols in the top row, because long or repeated literal numbers are typically replaced with named constants;
- Swap backquote with tilde, because backquotes are rare in many languages but destructors are common in C++;
- Swap minus with underscore, because underscores are common in identifiers;
- Swap curly braces with square brackets, because blocks are more common than subscripts; and
- Swap double quote with single quote, because strings are more common than character literals.
I suspect this last is probably going to be the most controversial, as it interferes the most with running text by requiring use of shift to type common contractions. This layout has significantly increased my typing speed in C++, C, Java, and Perl, and somewhat increased it in LISP and Python.
I still hold that typing speed is not the main factor in the time it takes for a project to be completed. If it is, there is a big problem (Weeks of coding saves us hours of planning).
Regarding your question I prefer using the standard layout as it means I don't have to spend the first 10 minutes looking stupid when presented with a standard keyboard layout.
Some of the replacements you have suggested, e.g. the top row with the special characters doesn't make a ounce of difference as the outside finger on the other hand should be moving to shift at the same time.
IMHO One thing that helps above chaining layouts is using only keyboard shortcuts. Vim and Emacs are recommended. It makes moving text around far faster.
I would approach your question in the following way. The task is to organise a keyboard in such way as to minimise key strokes and hand movement for given text.
Steps toward a possible solution. Make a program that:
- Takes a text file with source code. (The bigger the better and from various sources!)
- Counts the frequency of use of each symbol (its presence in the text).
- (optional) Based on step 2: The program generates key stroke count for each symbol plus how far the hand has to go from central position. As a result you will have a measure how effective your keyboard layout is.
Now manually or by writing a program Redefine your layout in the following way. Put most frequently used symbol in a central position closer to your strong hand. The second symbol goes to your weak hand in central position. The third symbol goes back to your strong hand...and so on. Then you gradually move from central position of the hands into more "distant" areas of the keyboard. When all keyboard is full then you continue the process of assigning keys but this time with Shift key pressed. The other difference would be that you do not rotate strong and weak hand for each symbol when the Shift is down. With shift key down first you would fill in central positions on the keyboard and then move to more distant positions.
When you do all that perform step 3 again for the new layout to see how the layout was improved.
You may have to carry your keyboard with you at all times. On the bright side nobody will touch your computer. It will make you look like a Pro.
Finally, don't forget to share your findings.
I'm playing with a variant of the Colemak layout at the moment with heavy changes of symbols:
without SHIFT:
` - { } [ ] ; < > ( ) _ =
q w f p g j l u y * / # \
a r s t d h n e i o '
z x c v b k m , . !
with SHIFT:
~ 1 2 3 4 5 6 7 8 9 0 & +
Q W F P G J L U Y @ ^ $ |
A R S T D H N E I O "
Z X C V B K M % : ?
Maybe I'll restore the / key...
But this is not based on any sound research, and I'd also love to see a layout optimized (Optimization including stuff like hand alteration etc, also ZXCV preservation, ...) with a sourcecode based corpus, because all these layouts seem to be optimized for prose only. For example, 'f' is a very common letter in C (if, for).
Update: I'm currently using
` - { } [ ] @ < > ( ) _ =
q w k r g y u l p * ; #
a s f t d h n e i o ' \
\ z x c v b j m , . /
with SHIFT:
~ 1 2 3 4 5 6 7 8 9 0 ^ +
Q W K R G Y U L P & ! $
A S F T D H N E I O " |
| Z X C V B J M % : ?
This is based on a 6-key-swap partial optimization taken from Carpalx with preservation of the usual Cut/Copy/Paste/Undo shortcuts and modified to give a better access to the usual programming characters.
Make a simple key logger, then count the number of times each key is pressed. Run it for a day or two, then save the output to a text file. Do this every once and a while. It doesn't matter what layout you are using, as you are just seeing which keys are being used the most.
If you want to make a good layout, you can't be afraid to go away from the norm. I'd suggest putting the top 11 keys along the home row, then the next top 11 keys as the top row (leave the 2 keys above the return key as the least used keys), then the 3rd top 11 keys as the bottom row. There should be 4 keys left over now. Take those and put them in the -= and ]\ slots. Congrats! You have now made a great keyboard layout for your purposes! =D
Overall, I think having a good text editor and knowing how to use it is better than trying to improve your typing speed. Being able to record and replay macros is sometimes a lifesaver, and a selection of shortcut-assigned code snippets can be handy because there's normally language-imposed limits on what can be turned into a library.
More generally, I think the real productivity enhancers are all about knowledge...
- Knowing what tools and libraries are available and how to use them.
- Knowing the overall structure of the code you're working on, not just your little bit.
- Knowing key algorithms, design patterns and idioms so you don't have to reinvent them.
- Knowing the rules well enough that you can be flexible - you know when to break them.
- Knowing your co-workers and their strengths, weaknesses etc - ie knowing when to figure something out yourself, but also when and who to ask.
FWIW, I'm not claiming to be strong on all those. I've always been too biassed towards solving problems myself, and with too strong a tendency towards reinventing the wheel and grand architectural schemes.
Anyway, I just have this suspicion that time spent changing and learning keyboard layouts would be a distraction from more important issues.