Only check parameters on public interface methods

This was not obvious but should make some sense. Of course, it can break if you have “friends” or some other weirdness going on in your code. Let’s say that you have a class like this:

If I create an instance of this class, I have a little nice and neat package. The only way to access the data or modify the data in the class is through the public interface, like such:

As long as you verify the data coming into these public function methods that are exposed, the state of the object should be valid. You don’t need to do parameter checking on the internal function methods.

Of course, you may want to do checking on the internal methods simply because you don’t trust your calculations, but in general, the state of the object should always be sane. But you don’t know what’s going to enter the public interface, so you should always check that. Alternatively, you can use “if” statements and “throw” while validating the contract on the public interfaces, but maybe just use “assert”s on the private methods to make sure your code is internally stable while developing. When unit testing, of course, you probably only test the interface.

VsVim for Visual Studio 2012

Since I started using visual studio 2012 in April, I have discovered that the vsVim plugin extension is very very good. I highly recommend it if you want to swing that way. It’s not perfect, but it’s much more functional than it used to be and it’s frequently updated, which is great. I use it at work and I find that using vsVim, and visual studio hotkeys allows me to work without ever having to touch the mouse. These are the commonly used hotkeys that I use to navigate around:

Ctrl+S (I installed the “switch” extension) – navigates between .h and .cpp files
Ctrl+Tab – Navigates between sources files. Just pressing once goes to the last file used. Pressing multiple times allows you to navigate.
Ctrl+; – Searches for the name of a file in the project.
Ctrl+Alt+F – standard file search.
F5, Ctrl+F5, F7, Ctrl+F7 – Build commands.
F12, Ctrl+F12 (go to definition/declaration)