Friday, October 31, 2014

Two things that make me hate visual studio less

After many years of doing only theory, I joined a large C++ programming project 4 months ago,
working in Microsoft visual studio. The frustration I had from the difficultyof the most basic tasks - e.g. adding a class to the project,  (just use add new Item *don't dare using add class or the class wizard or you'll never see the end of it!*)
lead me to write this facebook post:

 think Microsoft was cursed by a witch. Maybe she was once in love will Bill Gates and he broke her heart. She cursed him like this: "Although you will have a multi-billion Dollar software company, with the smartest people in the world working for you, you will only be able to make one program that works well - and it will be called `notepad'". I had these thoughts before, but thought maybe I was wrong cause I did not know Microsoft's more serious software. But recently starting to write C++ on Microsoft Visual Studio, I see how bad it is. Join me in installing ubuntu

 Well , I did install Ubuntu, but not really using it. I guess when you are spoiled and used to an IDE that takes care of everything for you, it's hard to start dealing with makefiles and stuff..
I owe a big thanks to Idan Elad for helping me out with doing things the `right way' in Visual studio after seeing my facebook post.

Anyway here are two really cool features that made me think life isn't so bad at Microsoft:

Peek Definition:

You are browsing in your code and want to see a function definition - answerConsistencyChecks_p0p1 in the picture below.
Everybody seems to know that pressing F12 with the cursor on the function name
will take you to the file with the definition.

But at least I didn't know for a while that pressing Alt-F12 instead will just `peek'
the definition as in the picture below.

This way you can just see the definition without getting out of the workflow you were in at the current file.

Seeing the stack-hierarchy - especially when error\exception has occurred.

Say you're running your program...

and then an error occurs:

Till recently, I would try to put breakpoints in a `binary search' way, and keep
rerunning until I pinpointed the precise line where the bug occurred.
Here is the smart way, that saves the time of this search and multiple reruns:
Instead of pressing `Abort' above, press `Retry'.

Now MSVS will ask you if you want to Break or Continue:

Press `Break'. Good chance the breaking point is somewhere that doesn't tell you much:

Now press Ctrl + Shift + ` , (or right click and select Show Call Stack on Code Map)

You will see on the right the entire stack of calls that lead to the error!.
More than that if you double click one of the methods on this stack,
you see on the left by the green arrow precisely the place, or just the place after, where the run is
at this stack level.

And even better: If you go to `locals' you can see the value of all variables at this level of the stack,
so a lot of rerunning and couts for debugging purposes are saved.

No comments:

Blog Archive

About Me

My photo

Hi! I am a computer science postdoc. For some reason google is not finding my new homepage so I added a link from this profile