Thursday, May 15, 2014

What causes variables to change? A Software Newbie Story.

As a newbie software developer I was always tripped up about the concept of assigning a value or reference to a variable. I'd notice that sometimes the variable value changes automatically if some events happens, while other times, it never does. I knew the basic concept of value vs reference that I had learned in school, but had never really applied it (and knew that I had applied it!). Then, I ran into a few problems where my variable would change without reason (seemingly), and questioned the basic concepts of variables.

Little did I know that a variable that is a reference type (and assigned an actual reference to an object) will change if other related objects change. For example, the value of a DataGridViewCell variable will change if you re-fill the dataset. However, a row index assigned to a value type (i.e. integer) will never change without you directly re-assigning it. It's an interesting concept that honestly still trips me up sometimes.

Anyway - A random story for ya.

No comments:

Post a Comment