« Practise with Visual Studio : ACM ICPC '97 1: Duck PinsEta reduction »

Practise With Visual Studio : Staying Sane

25/05/09

Permalink 10:16:35 am, 942 words
Categories: Code

Practise With Visual Studio : Staying Sane

So I am practising a bit for the Microsoft internship to make sure that I am not totally clumsy with Visual Studio when I start in August. (Note to self: I should also set up Emacs on Windows some time, too, in case I start missing it too much, or want to prototype in Haskell instead of F#. The interviewers said that people are allowed to use Emacs at Microsoft :) First off, I’ve collected some links for things that I need to stay sane. Next, I’ll post at least one program for all those .NET/JVM gurus that read this blog to comment on.

Actually…who am I kidding? .NET/JVM gurus wouldn’t stand for the normal contents of this blog. I’ll just have to get comments from the people who actually read it.

One thing I had forgot is how MUCH typing there is. Stevey says that typing is crucial to being a good programmer, but I understood him to be talking about the things peripheral to programming: documenting yourself and communicating online. No, it’s all coming back to me, my days in undergrad where I could shuffle and tweak Java code faster than anybody else in the CS lab. And I didn’t even know Emacs back then!

Part of it is the long names, which is why IDEs have advanced completion these days. Another part is all the punctuation. My favourite languages are all very light on punctuation, but C-languages** have lots of it, all the time. Braces, brackets and parentheses! (That’s curly brackets, square brackets and round brackets for the Europeans in the room.)

Swap parentheses and brackets

First is to swap parentheses and brackets. Parentheses are far more common than brackets in almost any language I know (including English). This is least true for C-languages—braces, brackets and parentheses are in about equal supply, but modern Java* and C# probably have the most parentheses because of the high number of method calls and Linq’s surprisingly spare punctuation. Anyway, it’s something you should Just Do.

You can make the swap fairly easily using Microsoft Keyboard Layout Creator (MSKLC), or you could skip the five confusing steps and Windows Genuine Advantage check and just download the installers from me. MSKLC produces three installers, one each for AMD64, i386 and ia64. I have no idea what instruction set Windows XP is using on a Core 2 Duo, so I just used the i386 one. The installer adds Parenswitch to the list of English (US) languages.

Then go to Control Panel | Regional and Language Options | Languages | Details. You should see two keyboards installed: US and US - Programmer (Parenswitch). In the top drop-down, change from English (United States) to English (United States) Parenswitch. After a short period of retraining, your life will now be better.

Parenswitch (US - Programmer)

Switch to Consolas

I haven’t decided whether I want to turn off anti-aliasing for Visual Studio yet, and in any case I don’t know how, so I switched from the default Courier New to Consolas (Monaco is my favourite pixel font, but is Mac-only in any case). Consolas ships with Visual Studio 2005 and 2008, but isn’t the default. I don’t know why: it could that programmers are so traditional, Microsoft feared a widespread revolt. Or it could be that Microsoft is continuing their own tradition of providing bad defaults. (You decide.)

If you want to try Consolas in some other editor, and do not own Visual Studio, you might try googling for it. I found a Microsoft download page with a Very Stern Warning that Consolas is only intended for VS owners. But I don’t know if it’s enforced.

Switch to Emacs keys

I am still surprised at how good Visual Studio’s Emacs keys are. C-l works. They are totally serious about this. Well, C-r does conflict with the refactoring shortcuts, but I’ve learned to substitute the sequence “right-click-key r".

In Visual Studio, go to Options | Keyboard and change the top drop-down to Emacs. You can add other shortcuts below; I added C-h = backward-delete and M-h = backward-delete-word.

Switch to Vi keys

I haven’t put money down on ViEmu ($99), but Microsoft has a site licence so I will probably ask for it when I get there. Unlike the built-in Emacs keys, ViEmu also provides an inline regex search/replace (:s/this/that/g) and highlights all incremental search matches.

Anyway, the vi keys are just easier on your hands. Well, I don’t know about *your* hands, but they’re definitely easier on *my* hands.

Swap Ctrl and Caps Lock

If you skip Emacs keys and only use Vi keys, you might get away without swapping Ctrl and Caps Lock. But, like swapping parentheses, you use Ctrl so much more than Caps Lock that it’s a good idea for everybody.

Here is an old page that describes how to do it. I’ve used this successfully in the past for at least Windows and Mac; I can’t remember whether I’ve used the Linux instructions. Alternatively, if you only trust Vim users, you might try these instructions on the Vim wikia.


So that wraps up the first instalment of Getting Comfortable with Visual Studio. The next post will have actual code.

*Java has no such amenities, but you can’t use square brackets to index into Lists or Maps either. So you get parentheses there, with things like List.get, Map.put and String.charAt.
**C-language, like P-language, is a social rather than a technical classification. It includes all the usual suspects, namely C, C++, Java, C# and sometimes Javascript, but crazy people are making new C-languages all the time, like D. (P-languages are, eg, Perl, Python, PHP, Ruby and sometimes Javascript.)

1 comment

Comment from: Edward [Visitor]
My fingers would like to thank you for the parentswitch keyboard bindings.
10/12/09 @ 13:47

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)
blogging tool