An Ideal Keyboard Layout for Programming [closed]
Asked Answered
S

6

101

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.

Splashy answered 21/2, 2010 at 15:57 Comment(18)
Maybe it's just that I am thinking too slow - but raw typing speed is usually not my limiting factor when developing software. If it was, I'd probably think that I'm doing something wrong.Aviv
@Lucero: Overall, no, but when I've (finally!) figured out what I should be doing, the faster and more comfortably I can type it, the better. Once you've done all your hard thinking, sometimes there's just a lot of code grinding to do... :-)Adim
@Jon: Strongly recommend making this a CW before it gets closed as subjective (which, after all, it is).Adim
I agree with Lucero on this if you can type at around 70 wpm on a qwerty keyboard that should not be your limiting factor when coding.Sigil
@T.J.: made CW. A good layout isn't an issue of raw performance so much as it is one of comfort—but comfort is very important to performance.Splashy
I like the "swap numbers with symbols" idea - but not for the stated reason. After all, you still need to define the named symbols and their values. But where there's lots of numbers to type, the numeric keypad works better than the top row anyway. My worry is one particular digit - zero.Level
It's funny how you got slammed by quite a few people, I'd suggest ignoring them. It's not only typing speed (which is a factor if you can type enough to be able to "program as you think"), ergonomy trumps that. But speed and ergonomy go together: moves that strain your hands are slow to perform, fatigue leads to errors and fixing those taxes your hands even more. And in the long term, tweaking your keyboard layout to match your needs may be the difference between RSI or no RSI.Candlenut
"Type as you think" is, in my estimation, a generally bad thing to do if you're solving a problem any more complex that "how should this method be implemented?" Most programming tasks I've dealt with are not so small in scope. Therefore, typing speed hasn't been a limiting factor for me. Those who find it such may be a) geniuses, b) junior level programmers with remarkably narrowly focused responsibilities c) forgetting to think things through.Konopka
@Steve314: Dang! Forgot to mention the number pad. But do you really type 0 nearly as often as you type )? @Jason: d) people who have had entirely way too much caffeine. ;)Splashy
@Jon - I doubt it, but I just know I'd end up with source code full of '0' instead of ')' and visa versa.Level
I would also address the arrow keys, it takes too much time to move my hand over arrow keys when navigation around code.Arturoartus
@Kugel: In Emacs, left, right, up, and down are C-b, C-f, C-p, and C-n respectively, where C- is the Emacs notation for “Control”. Similarly, in Vim you have h, j, k, and l when not in insert mode.Splashy
The most straightforward way to reason about this appears to first ask not which symbols we'd like to promote, but which current symbols can be painlessly demoted? For me this is the backtick, the semi-colon and the backslash. Of these, the backtick key is the least accessible. I'd like to promote the parentheses and the underscore, with the underscore being slightly less important. Also, to facilitate learning the change efficiently, it's best to swap pairs, rather than permute them some other way. So I swapped _ with backtick, ( with ;, and ) with \, using MSKLC.Beagle
Initially, swapping the digits with their symbols seemed like a good idea, but I use a laptop more than half the time (no numpad), and type a lot of numerical calculations, so it doesn't suit me. Also, apart from the parens, most of those symbols occur not particularly more often than digits.Beagle
Note that the number keys must be pretty easily accessible for optimal Vim usage, since numbers are arguments for all the normal-mode operations.Pythian
I am using my own design, which features: 1) Like you said, non-shift states for upper row: symbols, and shift for numbers; 2) symmetrical layout for paired symbols, e.g., {} [] () <> /\ are typed by both hands with same finger; 3) move symbols to the center part instead of around Enter keys, so that they are both pressable by index finger of both hands. 4), switch Shift with Capslock and Enter key. (This is possible with MSKLC, yes, by editing .klc file manually.)Julenejulep
In a java project (counted xml and java only), some results: {/} is 14.67 times of [/], " is 113.22 times of ', * is 9.57 times of 8, ( is 4.31 times of 9, _ is 3.47 times of -.Shackelford
Arensito: pvv.org/~hakonhal/main.cgi/keyboard Made for programming by a programmer. Uses thumb keys (on standard keyboard, by shifting home row up), and AltGr layer.Briggs
R
32

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.

Repress answered 21/2, 2010 at 15:57 Comment(11)
Oh, no, typing speed isn't a bottleneck by any means, but at the same time, why let something as silly as a keyboard get in your way? I've had no trouble switching back and forth between my layout and others, because I use both frequently; I simply prefer mine. And I must admit, emacs makes programming fast as can be—when I don't have to look up a key sequence.Splashy
Oh, and the simultaneity of left and right hand movements also doesn't make a difference: the modifier still has to be depressed before the key is struck. A difference of milliseconds, surely, but again, why hinder yourself? Programming with a layout that doesn't work for you is like programming on a sticky keyboard.Splashy
I maintain that by keeping several keyboard layouts in memory you are sabotaging your muscle-memory and thereby making your typing slower.Shlomo
The other issue with the shift key is sequences where you are alternating, so both hands are jumping from the top row to their shift key and back. I'm not saying it's common enough to worry about, though, but things like "(!*x)" might qualify as irritating.Level
-1: Doesn't contribute anything to the discussion (the "looking stupid" argument isn't backed up by even one datum from experience, it's a forward-looking worry) and can't be fixed.Beagle
My wrists are starting to crack every time I reach for the curly braces... If you're just starting, I recommend looking into proper typing ergonomics, and also learning a Programming DVORAK. It's healthier, and you won't be getting arthritis at 23.Erda
i'm not really sure about the benefits of this answer...? it's not really a question about fastest development trick, but good layout for developer which can be about speed, ease or even just finger cramp...Lagasse
I agree. i even tried some dvorak and programmer's dvorak. The main issue is that your skills are not portable.Potluck
it's not the speed it's the mental drag.Mor
-1. I don't change my keyboard layout to speed up my typing. I just think the current QWERTY is only for English, and I want to be able to type three languages and their punctuations and special characters, in the meanwhile, programming, without switching keyboard layout. So I maintained my letters keys same as QWERTY, but changed the symbol keys.Julenejulep
Actually I think that would be a pretty funny situation, if you type with the speed of a small-child, they ask you "nah, not a tech-guy huh?" and you tell them you actually are a programmer. I want to see that face :DCorrespond
C
22

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:

  1. Takes a text file with source code. (The bigger the better and from various sources!)
  2. Counts the frequency of use of each symbol (its presence in the text).
  3. (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.

Cytochrome answered 21/2, 2010 at 15:57 Comment(3)
I really like this answer, :PWinfordwinfred
If one wanted to make things more complicated, one could factor in character combinations and try to make the hands alternate or avoid same-finger strokes (like "kilo" on QWERTY)Truthvalue
Would change the source code text file to a keylogger to get also shortcuts you press and optimize them.Category
C
18

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.

Cultrate answered 21/2, 2010 at 15:57 Comment(1)
I like the idea of making the characters default over the numbers. ie: shift+1 to get one, and pressing 1 gives you !Cordite
O
17

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

Oecology answered 21/2, 2010 at 15:57 Comment(3)
Very good answer: keyboard should be taylored to ownerBrindisi
For keyboard usage statistics, there are already good programs that can show a heatmap, like this one: WhatPulsePriestridden
[Visiting old post comments] That is actually a really cool (or heated ;]) idea. I'll have to check into that myself!Oecology
L
11

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.

Level answered 21/2, 2010 at 15:57 Comment(3)
I agree with you on all counts! Making good use of tools and idioms is just good programming. But this is a question about one very specific thing, and hey, fifteen minutes two years ago has saved me a reasonable amount of frustration since.Splashy
@Jon - I get the point, but I think my typing habits are pretty strongly programmed by now - change would be hard work.Level
-1: Doesn't sound like it's based on experience with alternative keyboard layouts; goes against my experience with them. Digresses way beyond the topic. Doesn't provide concrete action items. Can't be fixed.Beagle
S
-5

Changing the keyboard layout is a bad idea since it would (perhaps) boost your typing speed on one keyboard, but severely damage your typing speed on other keyboards or on computers where you don't have your special keyboard layout. I've found that it is often better to adjust yourself to the defaults, that having to change them everywhere. (Personally, my fingers are heavily Emacs-biased, which causes lots of typing friction everywhere else.)

Shlomo answered 21/2, 2010 at 15:57 Comment(7)
I happily switch between two layouts. Jon reports it's been "a year or two" and he has no trouble going back and forth. YMMV, basically.Adim
I find changing between keyboards and keyboard layouts as easy/difficult as changing between speaking in different languages -- if you know them well, after few minutes you regain full speed of thought.Dentilingual
@liori: well said, though whether it's on the order of minutes or seconds is entirely dependent on how tired I am. :PSplashy
@Dentilingual "after a few minutes..." It seems that (multinational) companies and nations standardize on languages for a couple of purposes. 1) Speed of communication. 2) accuracy of communication. I suspect standardize keyboard layouts see similar benefits.Konopka
@Jason D: Valid points, but I am glad they're not applicable to me... I rarely use other people's computers.Dentilingual
@Liori. A good lot of companies have conference rooms with shared computers. And a good lot of developers will let someone else "drive" their computer when tag teaming a difficult issue. If others REFUSE to touch your computer due to your non-standard layout, you could be hampering cooperative problem solving. And for your employer, that eliminates the bulk of the personal benefits you reap with the chosen layout. Remember, development isn't usually one man against the world. It's usually done as a team.Konopka
@Jason D: Oh, that's not a problem. Switching between keyboard layouts is as simple as clicking one button on screen... at least on my computer; especially that I still do use standard layout for games :-)Dentilingual

© 2022 - 2024 — McMap. All rights reserved.