Tuesday, October 25, 2011

Are comments always necessary?

I was reminded of a conversation Marshall and I had about comments when I read this post by Jesse Liberty.

The post gives an example of the reason your comments should explain why you're doing something, rather than how you're doing it.

At the end, Jesse argues that if your reader knows the language, your comments will be reduntant if you use descritptive names for methods and variables.

Lately I've been thingking a lot about how much I should be commenting. And whether or not I'm just stating the obvious.

Take this method for example.

public string GetRunTimeForAllCars()
{
  IEnumerable<Car> listOfCars = listOfVehicles.FindAll(c => c is Car).Cast<Car>();
  double totalRunTime = listOfCars.Select(t => t.RunTime).Sum();
  return totalRunTime.ToString("f2");
}


I experimented with a few ways or writing the method out before I decided on this one.
I think it's pretty clear and doesn't need any comments to tell you what's going on.

What do you guys think?
Are comments always neccessary?
If somebody doesn't know linq, can they still understand what that code is doing?

Monday, October 17, 2011

Being a better developer

Scott Hanselman lists some things to "sharpen the saw" on his website.

I listened to the podcast he links on his page, he mentions several things I found interesting.

Reading books is a great way to learn, but Scott warns about becoming "too academic". A great way to improve your own code is to read other's code. Of course, you want to make sure the code you're reading is "good code". One way to do this is to read code from successful open source projects.

Scott mentions several by name:
CastleProject, Microsoft's Patterns & Practices, SubText and he puts in a plug for dasBlog as well.

Other things he talks about doing are:
Talking with other developers about how they do things.
Teaching a class on a topic and joining a developer's users group.

I'm guilty of being too academic. I do a lot of reading, mostly books.
Since March I've read: Programming Entity Frameworks, Refactoring to Patterns, Pragmatic Testing in C# with nUnit, C# in depth, and I'm halfway through CLR via C#. These are on my list for the next 6 - 12 months: The Pragmatic Programmer, Clean Code and Code Complete 2, they've arrived at my house and I'm really excited to read them!

I also listen to podcasts, mostly Scott Hanselman's, and I read blogs from the same, as well as, Scott Guthrie, Jeffrey Palermo, Eric Lippert, Julie Lerman and John Papa.

I've watched quite a few videos on SilverlightTV and Channel9.
There are some really great videos on that site.

I really like watching the videos and downloading the code from the show, it's really great to be able to go through the code to see how they've done what they're talking about on the show.
That makes me think that checking out code from some of those open source projects is going to be really good for me.

Scott briefly mentions that learning a new language to get out of your comfort zone is a good idea.
I've heard this idea on other podcasts and read about it as well. The idea being that if you're a Windows guy working in .Net you should try running Linux and play around with Python, Perl, Ruby on Rails, etc. To that end, I set up my home computer to dual boot Windows and Ubuntu. I installed MonoDevelop and eventually plan on learning IronPython (since it works with .Net in Visual Studio) and F#. I'm also considering eventually taking a look at Ruby on Rails, Lisp and Smalltalk.

I'm going to start by downloading and reading code from one of those projects, it sounds like that's where it's at.

What do you guys think?

Saturday, October 15, 2011

Good Taste

In episode #222 "Art is Shipping", Scott Hanselman interviews Jin Yang, the lead designer for StackOverflow.
In this podcast Jin Yang mentions a couple things that I found really interesting:
The first was that a well designed site should evoke a feeling from it's users.
I had never considered this, but it makes a lot of sense. Imagine you have a site where you want your users to donate money for some worthy cause, you might design the site to evoke a feeling of compassion so that your visitors will be inclined to donate more.
The second was that good taste can be developed.
This got me to thinking "what is good taste?".  According to Immanuel Kant, it comes down to a judgement based on a subjective feeling. Well, if that's the case, how do you get better at it?

Scott links a number of design blogs in the notes for the show, perhaps the anwer is to check out the blogs, see what others are doing, and take from that the things that appeal to you.
I've found that I'm a big fan of minimalist art, a style that Apple has been really good at.

What do you guys think? What is good taste and how do you recognize it?

Tuesday, January 18, 2011

Are you a Cargo Cult Programmer?

Jesper and I have been doing a lot of learning lately. We're both learning C#, and in doing so, reading a lot of books,  blog posts, and other resources.

Specifically, we've had several discussions about the book CLR Via C#. This book goes into great depth about how C# works, and some depth on how best to use C#. This is the type of book to read when you want to know why to solve a problem a certain way, instead of just solving it that way because, you found some code online, and it seems to work. The goal is to really understand why, not just how. There is a reason they teach math in school. They could have just given us a calculator our first day of first grade. Why didn't they? Its important to know the why.

Anyway, while reading a book review on Jon Skeet's website, I ran across the concept of a "Cargo Cult Programmer." I was intrigued. I followed Jon's link to the  original blog post which explained the concept. A Cargo Cult Programmer is someone who just cares about how, and not why. I have been guilty of this in my career but I strive to improve and this is one place I'm working hardest.

Anyway, I thought that Cargo Cult Programmer blog post was a good read so I thought I'd share.

Tuesday, January 11, 2011

More Helpful .NET Websites

I'm still learning .NET while working on my current project at work. I'm using Silverlight and learning .NET and specifically C# and XAML to support that end. I've recently run across two really helpful sites and thought I'd share them here.

A colleague showed me  101 LINQ Examples which is a nice site from Microsoft that shows LINQ examples from simple to hard. I have found this useful.

The next link, Parameter Passing in C#, is an excellent article on how parameters work in C#. This information explains details about passing value or reference types by reference or value. It was here that I learned about the ref keyword which is pretty damn cool.

I hope you find this usefull.
-Marshall

Wednesday, December 15, 2010

Why don't reference types go on the stack?

When I was in school I was taught that heap allocation was expensive and stack allocation was cheap.
I was learning C / C++ at the time and that was (and is) true for C / C++.
This is not the case for C#...allocation to the stack and heap is about the same, thanks to the magic sauce of garbage collection.

Check out this 2 part post by Eric Lippert on his blog for an interesting read about what you thought you knew about value and reference types.
http://blogs.msdn.com/b/ericlippert/archive/2009/04/27/the-stack-is-an-implementation-detail.aspx

Friday, November 5, 2010

Understanding .NET Delegates

Recently, Jesper and I have been trying to understand the concept of Delegates in C# (or .NET in general). Both of us are learing the Microsoft stack and feel this concept is vital. We've found a few useful resources that have helped explain this concept.

For some high level overview action, check out these MSDN articles:
http://msdn.microsoft.com/en-us/library/17sde2xt.aspx
http://msdn.microsoft.com/en-us/library/9aackb16.aspx

But, then I ran across this article which REALLY helped with my understanding. Big thanks to the author for such a great resource:

http://www.codeproject.com/KB/cs/NETDelegatesAndEvents.aspx