views:

57

answers:

3

QUESTION OBSOLETE: This question has been re-asked, in a much more condensed form, on programmers.stackexchange. Please vote to have this question closed.

Programmers' trade is essentially to write code. Yes, there is a lot more involved than that, but when you really boil down to it, at the end of the day, programmers will have produced lines and lines of code. How to come up with this code is one matter, and that's what we learn through practice and teaching; an entirely different matter is transferring that code from your mind down on file.

The easiest way of doing it is simply typing it, one character at a time for the entire code. This brings to mind the ubiquitous keyboard, and for some also this SO question which covers keyboards for programmers. This is the most intuitive approach, which is most likely why it has been so successful. But are there other, better solutions? I suspect not, at least not at the moment, but I'm asking about miniziming the mind-to-file time, so this is the first part of it. It may also be the most crucial part, since the keyboard is our main interface to computers, and should we not all strive to make that as efficient as possible?

When dealing with keyboards, the character layout (i.e. the mapping of characters to keys, not the layout of the keys themselves) is also essential. I once tried Dvorak since I heard it would allow faster typing than Qwerty. Although it did reduce my rate of typing errors, it didn't necessarily increase the rate of typing. Also, as I "replaced" Qwerty with Dvorak in my head, I was completely handicapped when sitting in front of someone else's computer. Also, the keyboard shortcuts were all screwed up. But I find using regular Qwerty to be a bit inefficient for programming. On my Swedish keyboard, very often used character such as (), {} and [] all require at least a SHIFT or an ALT GR combination. What can be done to minimize the effort of typing such characters?

The one-char-at-a-time approach can be augmented with an IDE, which allows you to type a few initial characters of the field or method you want and then let the IDE fill in the rest. Assuming that the IDE is able to input the rest of the name faster than you can, this should have a great improvement in reducing the time of writing. Or is it? Can the time of executing the shortcut be longer than just manually typing in the rest? Do you prefer just typing it all, or do you let the IDE do it for you? Of course this is highly IDE specific, but it should be asked nevertheless.

Writing code is not all about typing: it requires you to move around code that has already been written. You need to rewrite sections, delete a few chars here, add chars there, copy that snippet, etc. So being able to efficiently navigating your code is crucial for minimizing the writing effort. The easiest again is simply to use the mouse and move the curser, but I for one find that much too slow and cumbersome. Also, it takes your hand away from the keyboard and increases hand movements (As the almighty Yoda once said: "Using mouse leads to hand movements, hand movements lead to RSI, RSI... lead to suffering!"). Another way of navigation is to use keyboard shortcuts such as in Emacs. Another yet again is to utilize an IDE which allows you to quickly jump between for example functions and bookmarks. For the moment I've been able to stick with Emacs since that allows keyboard navigation but without any IDE; the projects have been small enough to keep track of everything in my head. But on larger projects I suspect I would need to use an IDE, but then I fear I will lose the handy keyboard navigations and have to resort to the mouse. Or do I? Is keyboard navigations supported in most common IDEs? Or can editors such as Emacs be augmented to support fully-fledged IDE tools? Or is there yet another approached not mentioned here for efficiently navigating code?

Obviously, there is much which can be done, and I have most likely missed some parts of code writing in this question.

+1  A: 

Don't try to type "faster". Try to type "less". It will not only help your fingers, but also your readers :-)

Thomas Mueller
+1  A: 

As @Thomas-Mueller said, type less, not faster. In addition, try to follow DRY (Don't repeat yourself). I used to hear people raving about "cookie cutter code", where you could supposedly get a lot done quickly by cutting and pasting large amounts of code. The reason that's a problem is if there's a need to change the original code, now you have to change N copies.

Programmers are like noisy channels. If they have to make 10 changes to the code, if they're really good, they'll get 8 of them right. The ones they don't get right are new bugs.

That's why short code and DRY matter.

That's also why compiler languages are better than assembler, and why domain specific languages (DSL) are better yet, when they apply.

Mike Dunlavey
+1  A: 

Typing is such a small part of coding. My most productive days result in a reduction in lines and complexity in code.

But there are many things that speed up development. Auto-generated code for things like web service interfaces and such.

Tools like Resharper that make refactorings much simpler, often with a couple clicks of the mouse you can save 10 minutes of work.

Chad