Saturday, April 13, 2013

Recursion in Microsoft Visual Studio

I've upgraded to Microsoft Visual Studio 2012 recently and am very happy with the new IDE.
I don't really want to get into the differences between the versions and the "whats new" list right now since you can easily find them with Google.
I would however, like to talk about Recursion.

Recursion is basically a programming technique involving the use of a function that calls itself one or more times until a specified stopping condition is met at which time the rest of each repetition is processed from the last one called to the first.

A common "bug" when you don't set your stopping condition correctly. In such a case the recursion process keeps calling itself until it uses all the processes resources and crashes.
When this happens it is clearly a programming bug and not the IDE's fault.

I made a recursion error that I believe the new IDE should have stopped me from making.
Below is the snippet, can you see the problem ?

       private int recursionInt;

        public int RecursionInt
            get { return RecursionInt; }
            set { recursionInt = value; }

        private void Form1_Load(object sender, EventArgs e)
            int tmp = RecursionInt;

The get function of the RecursionInt Property calls itself instead of recursionInt (I capitalized by mistake).
here is the screen capture of the exception
Property Recursion Exception

I would have thought the new Visual Studio IDE would detect such simple mistakes and stop the at design time just like they do when a function does not return any value.

What do you think ?

Just for fun, take a look at recursion by searching for it with Google.

Google is using the "Did you mean" feature, to illustrate the definition of recursion.
Check it out: