I like insights and this covers a good one
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:
- Determine the specific instance of
foo
by inspectinggetFoo
- From this, project what state
foo
would be in at runtime (variables, fields, and whatnot) - Trace out how the…
View original post 397 more words