Free tools that every .Net developer should use

wrenches

There are several tools that my team has grown accustom to using on our .Net projects. Having used them on several projects now, I can’t imagine doing work without them. They are all free, and I think that every .Net developer should give them a shot and try to incorporate them into their own work. They will increase the quality and maintainability of the code that you are producing.

NUnit

Creating unit tests is the best way I have found to make sure you code accomplishes the task that it is supposed to. I don’t care if you do full test driven development or not, but you need to be writing unit tests for every piece of code you produce. A big benefit to unit testing comes when you need to refactor something. You can make your changes and then run your suite of unit tests to make sure everything is still working correctly.

NCover

If all of your unit tests pass, but only 10% of your code is covered by those tests, you code may not be in the shape that you think it is in. That is where ncover comes in. It analyzes the tests you have run against your code and tells you what percentage of the code is tested. There will always be pieces of code that are untestable, but you can normally get coverage of 80% – 90%. NCover is no longer free, but if you follow the link above you can download an older version that is free.

FX Cop

FX Cop is a tool that runs static code analysis against your code to make sure you aren’t violating any commonly accepted rules. When you first run this against your code, you are probably going to get a ton of violations. From there you need to decide what rules are important to you, and only enforce those at the beginning. As times goes you can enforce more and more rules.

SourceMonitor

SourceMonitor measures the cyclomatic complexity of your code. This is the number of linearly independent paths through your code. Pieces of code that are more complex are harder to test thoroughly and harder to maintain.

CruiseControl.net

CruiseControl.Net is the tool that pulls all of the above ones together. It is a Continuous Integration server. This builds the application after every check in and runs analysis on the code to make sure it adheres to our standards. It executes NUnit, NCover, FX Cop, and Source Monitor. This way you are always aware of the state of your source code.

I would encourage every .Net developer to take a look at the tools listed above and try to incorporate them into your development process. I believe that by using them, you will produce higher quality code that is easier to test and easier to maintain.

Advertisements

My weight loss plan

apple

A couple of months ago I finally became so frustrated with my weight that I decided to take drastic action.  So, I developed my own weight loss plan and so far it has been very successful.  Overall, I had 26 pounds that I wanted to lose.  As of today, I have lost 16.5 of them.  10 of those pounds came off in the first 2 weeks.  Since then, it has been about a pound a week.  Here are the keys to my plan.

  1. No sweets, no pop. I completely cut out sweets and pop.  I was really bad about chocolate.  If I tasted a little of it, I had to keep eating and eating.  It was easier for me to eat none than a little.  So, I completely cut it out.  Before, I had been convinced that I needed the caffeine in the pop to get through the day.  I knew this was not good for me, so I decided to cut it out completely as well.  What surprised me was the fact that with no pop, I actually ended up having more energy than I did before.
  2. Smaller portions. I’m really bad about going back for seconds and thirds if I like a meal a lot.  I’m trying to eliminate that as well.  This is hardest when I go out to eat, but I try to always leave enough that I need a to-go box.
  3. No eating after 7pm. I had a teacher in college talk about how it was not good to eat after 7pm because your body didn’t have time to burn any of it before you went to bed.  So, I made this rule.
  4. Embrace hunger. I am now glad when I feel a little hungry.  That means this is working.  I try to keep my food intake such that I feel very hungry before a meal.  If I’m feeling a little hungry, that means I’m losing weight.  To combat feeling hungry I try to drink more water.
  5. Lots and lots of water. I’m not sure exactly how much water I’m drinking.  But it’s a ton.  If I go an hour now without a glass of water I start feeling very thirsty.
  6. Weigh every day. Some people weigh in only weekly, but that’s not enough for me.  If I’m doing something wrong, I want to know as soon as possible so I can correct it.  So, I weigh every morning.  My scales have a memory of the last 10 weights.  My goal is to reach a new low weight every week.  So far I have been able to achieve this.  If it’s getting late in the week and I have not reach a new low, I know I need to do something drastic, like having only a Jamba Juice for dinner, or something like that.
  7. Cheat day. This is my favorite part.  From 6pm on Friday to 6pm on Saturday is my cheat day.  I can violate any of the above rules.  In fact, I try my hardest to violate all of the as much as I can.  I got this tip from Tim Ferris.  This keeps your metabolism up so it keeps burning fat during the week.  Without doing this your metabolism will slowly get to the point where all it expects is your new level of eating and it won’t burn any more.

Notice, I haven’t increased my level of exercise at all.  I plan to get into running again, but things have been so busy I have not been able to fit that in yet.  But that is the next phase of my plan.  I think I’m probably about to the point where I will not go too much lower until I do this.

So, that is my current plan. I’ll try to keep post about the success of it as I go along.

Trouble setting SelectedDate on the ASP.Net Calendar Control

Ok, I just discovered this. After searching the internet for the solution I didn’t find anything, so I thought I should blog it so people don’t waste as much time as I just did trying to figure it out.

I have an ASP.Net Calendar control. I needed to set the SelectedDate in the code behind to the current date. My first instinct was to use MyCalendar.SelectedDate = DateTime.Now. Should work, right? Wrong!

Apparently the Calendar control gets confused because DateTime.Now contains the time portion as well as the date portion. So, you have to do DateTime.Today instead.

But, even that doesn’t work completely. That sets the data binding for the control, but doesn’t actually set the value. You then have to do Page.DoBinding() in order for it all to work.

So, in the end, this was the code that I had to use:

       protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {
                    BeginCalendar.SelectedDate = DateTime.Today.AddDays(-1);
                    EndCalendar.SelectedDate = DateTime.Today;
                    Page.DataBind();
                }
            }
            catch (Exception ex)
            {
                Utilities.LogError(ex);
                throw;
            }
        }

As a side note, the ASP.Net Calendar control is terrible for more reasons than just this. Every click on the control results in a post back in order to redraw the control with the new selected date. A much better solution is to find a good Javascript calendar control. But, this is an internal web app that needs to be done quickly, so I supposed I’m sticking with this one.

mattpeters.net

For years I have wanted to get mattpeters.com, mattpeters.net, or mattpeters.org.  But, the curse of having a very common name is that it is very hard to obtain these.  Well, I did the search again yesterday.  I found that I could buy mattpeters.com for $2,500, which was way out of my price range!  But, I was able to get mattpeters.net!  So, this blog now has it’s own domain.  Surely this means that I’m now cool.. right? 🙂

The old address matt3281.wordpress.com will still work, but it now redirects to mattpeters.net.

Ok, I guarantee that is the most that I will ever type my own name in a single blog post…