Ed Clarke’s In a Nutshell

And He Needs Help Getting Out

Archive for July, 2008

Use of c# var – Lazy or Flexible?

Posted by edc73 on July 25, 2008

A code review today raised concerns about the use of var such as:

var results = new List<LabResultSummary>();

as opposed to

List<LabResultSummary> results = new List<LabResultSummary>();

Specifically, the question was “Why is type inference needed or even useful in the below? I gotta say, it smells of a lazy developer to me. :)

And then my response:

—————————————————————–

My first inclination to “var” was similar to yours, but I’ve converted.

1. For small methods (which all methods “should” be), what the variable is is obvious from how it’s instantiated (You can only use var when it’s instantiated in the same statement as it’s declaration)

2. It’s still strongly typed (it’s not a vb6 dim object/variant)

3. You can only use on private method variables, so no “leakage” of intent.

4. And damn, when I’m writing a lot of code that’s in flux, it’s saved me lots of work to just change the variable type. For example, refactor a method to return the interface instead of the concrete type. I don’t have to go and touch every single variable that ever called that function.

There’s probably others, but that’s off the top of my head. Again, when I first read about them, I got the “smell” too. But decided to give it a shot and have become a fan. Makes my coding agile :)

————————————————————

Thoughts?

Posted in Uncategorized | 1 Comment »

Unit Test Presentation

Posted by edc73 on July 10, 2008

So I did my presentation yesterday. The focus morphed a bit from the initial concept. It ended up focusing more on refactoring legacy code to make it testable. While the examples I gave still had some mocking in them, that was not the focus. I really tried to impress upon people the need for small, cohesive methods and classes. We discussed Test Specific Subclasses, Dependency Injection, and some design patterns. We also touched on some general unit test concepts. Overall I was happy with the material I was able to present within the hour time limit. If you were there, what did you think? Did it help or was it information overload?

Posted in IoC, mocks, refactor | Leave a Comment »

#Region issues

Posted by edc73 on July 8, 2008

Good points made by Jeff Atwood concerning issues with #Regions in the Visual Studio editor. I admit that when I first started doing .NET, I fell into the trap very easily. Now it’s just a pain. Pain to keep the organization straight, pain to read/scan the code. Just the other day I was having trouble searching for text, finally realized it was part of a collapsed section and therefore being ignored. Grrr..

Posted in visual studio | Leave a Comment »

Unit Test Presentation

Posted by edc73 on July 8, 2008

Worked a good bit on my unit test presentation over the weekend. It’s amazing how little material can be covered in an hour. When I started this, I had all these ideas about what it could be, but reality set in pretty quick. Not just time constraints either. What initially seemed like simple refactorings got a lot more complicated once they go up on the screen.

On the positive side, PowerPoint is the first Office 2007 app that seems more intuitive than its predecessors. Most likely due to my lack of familiarity with its previous version.

Posted in Uncategorized | Leave a Comment »