How I Debug things

I like insights and this covers a good one

Mike's Tech Blog

One day, while I was writing some C#, a coworker commented on a line I wrote:

var foo = getFoo();

“Don’t use var!” he exclaimed. “Use a concrete type. Otherwise, how would I know what foo is?”

I was willing to accommodate him, so I updated the selection:

Object foo = getFoo();

He was not amused, however, if the only way I’m using foo is:

Object foo = getFoo();
foo.toString();

Then what is the problem? My code will compile, after all.

Two different modes of thought

His basic issue came down to trying to debug my use of foo. Let’s say foo.toString() wasn’t doing what it supposed to, here is how he would look at the code before testing it:

  1. Determine the specific instance of foo by inspecting getFoo
  2. From this, project what state foo would be in at runtime (variables, fields, and whatnot)
  3. Trace out how the…

View original post 397 more words

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s