What I’m Reading

I’m always reading something: blogs, magazines in the bathroom, books. The frequency of each ebbs and flows. Right now I’m amid a dearth of books half read:

The Blank Slate by Steven Pinker The Blank Slate by Steven Pinker – This book is an argument against the theory that humans are born without any innate knowledge or skills. He already convinced me in How the Mind Works, so it’s been slow going.
Data Binding with Windows Forms 2.0 by Brian Noyes Data Binding with Windows Forms 2.0 by Brian Noyes – This book is about exactly what you’d think it is. This is a fantastic technology that will save tons of lines of code. It’s part of the always excellent Addison-Wesley .NET Development Series. I’d recommend any book from the series; this one is no exception. I’m about half-way through it.
The New Rules of Lifting by Lou Schuler and Alwyn Cosgrove The New Rules of Lifting by Lou Schuler and Alwyn Cosgrove – This is the first training book I’ve bought in a long time. It emphasizes just six movements that we use in daily lift as the basis of a strength conditioning program. It’s a great book for anyone who’s just starting or has been doing the same, damn thing for years and ain’t gettin’ no results. Great pictures of all the movements. I just started this one.
Naked Conversations by Robert Scoble and Shel Israel Naked Conversations by Robert Scoble and Shel Israel – This book is about – surprise! – blogging. It’s for businesspeople, trying to convince them that blogging is a good thing for their business. Duh! I’m reading it to bone up for some plans I have. Muhahahaha!

 What’s curious to note is the approach and the language in each of the books. They are written to very different audiences and by authors with very different backgrounds. Pinker’s book is definitely from academia; I used to read books like that frequently, but I haven’t in a while. The text is small and dense, the words are big. And this is from a very readable author. It’s a what a journal article would be like if there weren’t so many rules that academics must follow for journal articles.

The computer book is what you would expect; the language is very plain and boring. There tables and diagrams, the font is big. It’s an extended MSDN article.

The lifting book is written in a conversational tone, the author’s joke around often. The language is light and it’s very readable. There are frequent pictures. It gives the impression that this guy is talking to a group of guys in the middle of the gym.

Scoble’s book is written for businesspeople, as I said above. I’m not half way and I’ve already noticed a pattern: blogging is great for business, here are some examples: yadda, yadda, yadda. Every chapter. Like the only way these suits are going to get it is if it’s repeated ad nauseum. Businesspeople are idiots.

Now playing: Headstones – Coffee Cup

Creating Professional Documentation with NDoc and GhostDoc

At work we use NDoc 1.3 for all of our documentation needs. It’s a pretty good tool for the price. I was playing around with the options on an NDoc file and found that some of the default values for some settings aren’t the optimal ones. Here are some that you should change from the default to make your documentation better and your life easier:

  • Set CleanIntermediates to True: this will delete the ndoc_msdn_temp folder after the chm has been created;
  • Set AutoDocumentConstructors to False: if your constructor throws exceptions, say, which you document in the file, they will be missed if this is set to true;
  • Set IncludeAssemblyVersion to True: this one is obvious and you may already be doing it;
  • Set DocumentAttributes to True: this will output the attributes attached to the member in the syntax portion;
  • Set DocumentProtectedInternalAsProtected to True: again, obvious; you don’t want to give away implementation details;
  • Don’t EVER set DocumentExplicitInterfaceImplementations to True; NDoc barfs on that.

Depending on what release you are working on, you may want to set Preliminary to True. This will add “This documentation is preliminary and subject to change.” in red text to every page.

There’s a handy-dandy list of supported tags for NDoc that can be found here: http://ndoc.sourceforge.net/content/tags.htm

They support more than the ones supplied in the IDE for .NET 1.1 and it will make the docs look more like MSDN docs with very little effort on your part.

Also, an awesome tool that takes some of the drudgery out of documentation is GhostDoc. It’s an addin for VS and it’s free; right-click on a method or property and it will parse the name and figure out the proper summary for you. It’s pretty smart when it comes to inheritance documentation and the override methods for things like Object.Equals(). It’s a real time saver. And you can add your own. I’ve added some for BeginXxx and EndXxx methods among others.

One thing it doesn’t do is parse through the method to find Exceptions that are thrown. I’ve added some ReSharper templates to take most of the drudgery out of that task. I’ve found that I don’t throw very many crazy, custom exceptions; I use the standard ones that the framework provides which just beg for templated documentation: any ArgumentException and InvalidOperationException.

Now playing: Odds – Eat My Brain

Cyclomatic Complexity

Cyclomatic complexity refers to the number of paths through a piece of code. If you want to impress people with fancy science talk, you can refer to this page at Carnegie-Mellon Software Institute. Suppose you had the following method on a class:

1   public bool IsSomeValue(bool foo, bool bar)
2   {
3     int i = 0;
4     if(foo)
5       i += 1;
6     if(bar)
7       i += -1;
8     return i += 2;
9   }

This would have a cyclomatic complexity of four because there are four paths through the code: in this case it is because of the possible combinations of the booleans, but it’s just a little example. We’ve all seen methods way more complex than this. What’s this metric for?

Well, the more paths through the code, the more difficult it is to debug and to test. The harder it is to debug and test, the higher likelihood of bugs. So measuring cyclomatic complexity is a way to find the methods that could potentially be the buggiest in a class. Note, it’s a potential for bugginess, no metric for software is absolute; computer science isn’t a science, you know. For example, suppose you had a giant enum of 20 values that you switched on. That method would have at least a cyclomatic complexity of 20, but is it necessarily that complex? Well, not really. However, if it had a cyclomatic complexity of 20 and there wasn’t a switch statement, alarms should be going off.

Measuring Cyclomatic Complexity is another tool in the toolbox to show you methods that might be troublesome and may require refactoring. This an especially good tool if you have a high code coverage of unit tests. If you’re around 95% percent, complex methods may not jump out at you because of every case is covered by a test. Just because it’s being tested doesn’t mean that the code is as good as it could be.

So what tools are there for measuring Cyclomatic Complexity? I’ve looked at a couple for C#:

  • CCMetrics – This one is good for measuring overall complexity of an assembly. It says right on the site that it ain’t ready for primetime, but it’s just a command line tool, so it’s really easy to get started and it generates an xml file for studying problems in detail. It works on the compiled assembly. The two measurements that I like is code reuse and complexity reuse. The price? Free.
  • devMetrics – This tool integrates into Visual Studio and works on the source code. I’ve only used the free edition, but with the one you pay for, you can make up your own metrics. The output is an html table containing stats on your solution. One of them is Cyclomatic Complexity including max complexity and average complexity for each class. It’s great for quickly identifying problem areas.

There are others that are included in larger toolsets, but for the money, the two above work well for me.

Hanselman owned tonight. I want to have his baby

Scott Hanselman gave a talk at the Victoria .NET Nerds Developer Association tonight. It was very good. I’d heard that he was a great speaker and my hearing was right. He was all over the map, and since I read his blog, a lot of his technical asides (showing tools, etc.)  weren’t news to me.

Still I picked up a few things and he almost convinced me to switch to dasBlog with his presentation. Officially, his talk was about ASP.NET Software Architecture using dasBlog as an example. There are lots of cool things in that project.

The second coolest thing was something he showed in passing: the Call Stack Window in VS that Microsoft does by default is to repress the stack for all non-user code. Apparently, you can right click and choose to show that. I had no idea aobut this, but I’ll be sure to turn that setting on at work tomorrow. He called it the switch that means “I prefer the Matrix.” Hilarious.

The coolest thing was when he was deep in the bowels of generated XmlSerializer code and someone asked why the object properties had the ‘@’ character in front of them. He didn’t know (actually, he couldn’t remember); but I did. That’s the syntax used when the property name could be a reserved word of C# (My google skills aren’t with me tonight; I can’t find a reference to that piece of C# lore). Yes!

It was a great talk. Hopefully, he can come back soon.

This Isn’t Working Out

When I first started lifting, I thought I stumbled on some magic that I had to tell everyone about. If you do this and this and this, you’ll have the a body of Adonis and you’ll feel great too. Well, it didn’t take long for me to realize that while people wanted the latter, they didn’t like being told to do a bunch of things. I realized that there is a difference between interest and accomplishment. (People also have a hard time not realizing they’re being a smug asshole giving unsolicitied advice. ;)) I was interested in accomplishment, so I just carried on with lifting and stopped telling others how to do it.

After a while, hard-to-answer questions were asked elsewhere. Then after a longer while, I turned into the geek trapped in a fat man’s body that you so enjoy reading about. When I decided that enough was enough and I had to get back in the gym, I thought that blogging about it — to re-teach myself the things that I had so enthusiastically wanted to pass on to others –would help me motivate myself. It turns out I have no problem motivating myself to train and re-learn everything I forgot; I do have a problem blogging about it, though.

So this post is the final, official post on getting back in shape again. I can’t justify giving my advice on training and eating, when there is much better stated advice elsewhere. And if you’re motivated to get in shape, you’ll go and learn it yourself. I started this blog to be part of the group of blogging developers, not bodybuilders. And to force myself to stay current with development. So expect more technical posts.

However, lifting is still something I’m interested in, so from time to time, I’ll post links to great stuff on fat loss, muscle gain and what not. Hey, it’s my blog.

For those interested in my progress, I’ve had a personal trainer assess me for squats and then he offered to make a routine for me: it’s hard as hell; I can’t remember a harder routine. And, people have started to notice a change. Two staff at the gym asked me if I lost weight and I can now wear jeans that are “easy” in the thigh, instead of “loose.” I’ve lost between 10 and 15 pounds, which is on target for my ultimate goal.