March 2008 Blog Posts

NDepend - Analyze Your Code

NDepend is a tool you can use to analyze your .NET code and find problem areas. It's exceptionally helpful when working with a large codebase so you can see what's going on - which components rely on which other components, which classes might not be single responsibility... that sort of thing. It gives you a lot of information. So much, you might be overwhelmed by the sheer volume at first until you start really understanding what you're looking at. Let's walk through it a little.

Install is easy - unzip and you're done. Fire it up and you'll find yourself at the Start Page.

NDepend Start Page

This is where you can create a new project, open an existing project, or watch some getting started videos. The interesting thing I liked about the Start Page (aside from the video links) was that you can install some add-ins for Visual Studio and Reflector right from there.

Install Visual Studio and Reflector add-ins right from the start page.

I'll talk about what the add-ins do in a bit, but the ability to install add-ins right from the Start Page makes it nice and convenient. You can also get to this from the Options menu, but this gets it right up in front of you.

At the bottom of the Start Page you'll see tabs for an Error List and a Help window. The Help window has some links to additional videos to help you get started. You will want to watch these Help videos before getting too far into NDepend so you have an idea about what you will need to do. NDepend is big and can be intimidating. The videos help with that.

A couple of things I noticed about the Error List and Help windows: First, there's no way to "pin" them on the Start Page, so as soon as your cursor leaves, they auto-hide. That can get frustrating as you're navigating around. (Once you're past the Start Page, they're pinnable, but on the Start Page they're not.) Second, the Help window arranges the available videos in a giant accordion control. This isn't immediately apparent (at least, it wasn't to me), so once you've expanded one of the sections of videos, you'll wonder where the rest went. The scroll bar at the side of the accordion control (not the window, but the control) will help you out there.

Before you go any further, go to the Options menu (Tools -> Options) and under "Menu\Bar\Ribbon Preference," select the ribbon interface. The ribbon felt to me like it was easier to figure out than the standard menu/toolbar interface. The ribbon also felt like it gave more "guidance" on what my available options were at any given time, and you'll want that.

Select the Ribbon interface from the Options menu.

Using NDepend is covered fairly well by the screencasts you can access in the Help menu, so I won't cover every detail of usage. I recommend you watch the Help videos because it makes all the difference.

An NDepend project is what contains of the list of assemblies you want to analyze. Creating a new NDepend project is a very flexible process. You can do it based on a Visual Studio solution, you can drag and drop assemblies, you can browse for assemblies, or do a combination of several of these.

The project saves paths to each assembly you want to analyze. There is an option to let you save paths in the project as relative paths (relative to the location of the NDepend project). The relative path option is not the default and it's not obvious how to change your project to save relative paths. If you're going to use this project on any machine but your own, you'll want the relative path option set. You need to expand the folder view and select the "Relative path mode" checkbox.

Use the relative path mode for your project.

Unfortunately, relative path mode seems to be "all or nothing." While .NET framework assemblies always get an absolute path, all of the other assemblies in your project, including dependencies, are all either relative or absolute. You can't save some assemblies with relative paths and some without, and that can be a problem when you're looking at projects like Visual Studio add-ins that use some assemblies like EnvDTE - they get saved with relative paths. You can fix this by manually modifying the project file (it's XML), but NDepend won't automatically pick up your changes if you do that - you'll need to manually reload the project. This is probably an edge case, but the first project I analyzed was a VS add-in because that's what I happened to be working on at the time.

Once you've created a project and run the analysis for the first time, that's where the fun starts, but that's also where it can get overwhelming. For the first time user, you'll do the analysis, you'll see the report come up, and then you'll sit there for a bit wondering, "Now what? What do I do with all this information?" I think that's my only real complaint with the product. With a tool like FxCop, you know you've broken some rules and it tells you what to do about it. With NDepend, the "what to do about it" is very subjective - whether or not you need to do anything at all is entirely up to you, and then what you do based on your decision is also entirely up to you. Granted, the two tools perform very different analysis, but the idea stands: There's nothing that takes you from "I just ran analysis" to "Here's a list of actions to take." I think if that gap could somehow be bridged, it would make this a more accessible tool.

Once you run the analysis, you'll be presented with a report and the GUI will update with the data.

Note: If you run the analysis again, the report will again pop up, but the GUI won't automatically update - instead, you'll get a dialog letting you know there's new analysis available and asking if you want to update. That's a little confusing - I just ran the thing; why wouldn't I want to update?

New analysis available - Do you want to load it?

Anyway, once you've got the analysis run, you're going to get a pretty busy interface that comes up with a lot of information. If you've watched the videos, you have an idea of what all this means. If you haven't watched the videos, now is the time to do that. NDepend is not a tool you can just wander around randomly and "figure out."

Analysis loaded in the NDepend GUI.

Using the ribbon interface, you can pretty easily switch between views to analyze dependencies, look at various metrics, compare two sets of analysis to see what's changed, and do some ad-hoc querying against the analysis to dig deeper and learn more about your code. Use the tabs at the top to switch the ribbon to a different mode, and the "Reset Views" button will set the various information windows up to help you better visualize what you want. You'll use "Reset Views" a lot. The only problem with "Reset Views" is there is no way to customize the "default view" for a given "mode," so if you set the view up slightly differently, switch to a different view (say, from "Dependencies" to "Metrics"), and you'll never get your customized view back again. That can get frustrating, but I've learned to just live with the default views. I'm hoping a future version of the product lets me customize those views.

The Metrics window is the most visually striking part of any of the views, but it's also the most confusing. This is that gray-block looking window:

NDepend Metrics window.

This is an interesting visualization of the makeup of your assemblies. What the blocks represent is based on what you have the view set to at the time, but in the above example, each block is one method. The relative size of each block illustrates the relative size of the method in lines of code - larger blocks mean longer methods. Hovering your mouse over a block will let you know what that block represents, and as you query your code, this view lights up to show you which bits match the query you just entered. In all, a pretty cool way to visualize the makeup of your code.

That said, I've never been a big fan of the grayscale gradient boxes. The gradient makes it hard for me to see the edges of each block and when you're looking at a really large project, this blends together to become more of a "texture" than a visualization. Throw the text on top of that and it gets a little overwhelming. I wonder if alternative visualization mechanisms might be available in the future, like a red-to-blue hot-to-cold sort of thing, or maybe just solid colors with hard lines around the edge of each block.

The major feature of NDepend is really the CQL (Code Query Language) ad-hoc querying you can do. For example, if you want to find all of the protected methods that start with "C" that have over 10 lines of code, you can do that:

SELECT METHODS WHERE IsProtected AND NbLinesOfCode > 10 AND NameLike "^C"

Pretty cool, eh? When you do that, you'll see a query result window that lists the items that match your query, and the Metrics window will highlight the items so you can see the results visually. Oh, and don't worry too much about the trouble of learning CQL - it's a lot like SQL, and there's some great IntelliSense in the query window:

CQL IntelliSense in NDepend.

Once you've gotten your queries set up (and there are lots of good ones that come out-of-the-box when you create your project), you'll probably want to integrate this into your continuous integration build. NDepend comes with both NAnt and MSBuild tasks to help you get this going in CI. It's not hard to get going, but the documentation on the tasks is light (almost non-existent) so you may need to use Reflector to see what parameters the tasks allow you to pass in. It'd be nice to see a little more robust doc on these.

The reports that NDepend generates are very robust and fully customizable. You can either select some out-of-the-box options (recommended, particularly at the start) or you can customize everything down to the look and feel using XSL. The report itself takes the form of an HTML page with lots of charts and graphs. My favorite part of the report is the Abstractness vs. Instability graph (which is also the easiest to understand) where you can see which assemblies you have may need some refactoring to get them out of the "Zone of Pain" or the "Zone of Uselessness."

Abstractness vs. Instability - analyze your assemblies.

The only issue I really had with the reports was, when viewing them with IE, I got the "security warning" telling me the HTML could be harmful to my computer. That could be fixed pretty easily with a Mark of the Web, so if you want to customize your report, you can probably get rid of that.

Finally, the Visual Studio and Reflector add-ins bring all this full circle. As you're working on your code, you may be interested in doing some analysis on that code. You might wonder, for example, "Who's using this method?" Rather than having to write that CQL yourself, you can right-click your way to freedom and leisure.

NDepend Visual Studio add-in context menu.

You can do this same right-click action in Reflector. Again, very easy, and very cool.

I love NDepend, and I highly recommend it. It tells you all sorts of things that you really do need to know about your code. It's a little tough to get started, so you have to be patient, but once you're in, you're flying. Learn about your code and make it better. It'll be well worth your time, I promise.

posted @ Friday, March 28, 2008 10:15 AM | Feedback (0) | Filed Under [ .NET ]

Painting Is Like Twizzlers

We painted the master bathroom this weekend and I realized that painting, for me, is a lot like Twizzlers. Stick with me.

I love red licorice. It's so tasty and chewy and wonderful that I'm sure it's got to be good for me. Twizzlers, on the other hand... Twizzlers looks like red licorice, it smells like red licorice, but it is not, by any stretch of the imagination, red licorice. It's waxy and nasty and probably contains petrochemicals of some sort. Twizzlers is like processed cheese food compared to the Brie de Meaux of red licorice.

The problem is that Twizzlers so convincingly resembles red licorice from the outside that I forget how nasty it is. I'll be craving red licorice, see a Twizzler, grab it, eat it, want to die, and remember how bad it is. I might remember it for like six months or so, until one day my red licorice craving gets the better of me and I see a Twizzler, take a bite, then smack myself repeatedly in the forehead Rain Man style screaming, "STUPID! STUPID! STUPID! Twizzlers is not red licorice!" And another six months will go by before I forget how bad it is again. Rinse and repeat.

I hate painting. Hate it. It's messy and it takes a long time and I always underestimate the amount of effort it's going to take to get the job done. My attitude over the course of a painting job changes for the worse, too. I'll start out sort of cheerful, singing my Happy Working Song, and six hours later I'm ready to kill.

But, like Twizzlers, after about six to nine months, I always forget.

This time, we were looking at the master bathroom, thinking how drab it was. It was painted in the color "Arbor White," which is a special off-white color that Arbor Custom Homes uses when it builds houses. (If you want touch-up paint, if you go to Home Depot and ask for "Arbor White," they know. There's no paint chip or anything, they just know.) The problem is, if you hold real white up to it, you would probably want to call it "Arbor Brown" because it's not remotely white.

Anyway, we were gazing into the gaping Arbor Brown maw that was our master bathroom, thinking how drab it was, when we decided it needed a coat of paint. It having been probably a year or more since I last painted, I forgot that I vowed not to paint again, so we ran down to the Home Depot and picked up some paint. We ended up with a scheme similar to the following, with "Drowsy Lavender" as the main color. (This isn't exactly it, but I don't remember the exact colors. It doesn't really matter.)

Paint scheme: drowsy lavender, cotton whisper, river valley, and white.

We started painting on Saturday and we got about halfway done in five hours or so. Some primer and a first coat on the walls and the ceiling. At the end of Saturday I was in Twizzlers-land: "STUPID! STUPID! STUPID! Painting sucks!" Of course, we were sort of committed by then, so we had to finish.

We spent several more hours on Sunday trying desperately to finish but failing miserably. We got the second coat on the walls and the ceiling and we started on the trim.

It was about this time where we really started noticing that the door and the blinds were Arbor White but the ceiling was true white and... hmmm. Screw it. We're SO NOT painting the door and the blinds.

So we've got to finish the trim this week and do some touch-ups. Probably another couple of hours' worth of work. I wondered how people on Trading Spaces did all of this in two days, but then Jenn reminded me that it's not just two people - there's a team of people behind the scenes. Maybe if Laurie showed up it would be better, but probably not.

I swear I'm going to remember this time: Hire someone to paint. Painting sucks. It's always more work than you anticipate and it makes you grumpy.

Eh. That'll last, what, six months?

Two Minute WF: Activities

In this Two Minute WF, we'll talk about Activities.

When you create a workflow in WF, the actions that it can take are referred to as "Activities." Think of all the things you might want to do in a workflow:

  • Flow control (while loops, if/else decisions, etc.).
  • Executing code.
  • Handling events.
  • Calling external services.

...and so on. Each of these things is an activity. In a state machine workflow, each state the workflow can be in is an activity. Even workflows proper are activities - they're "composite activities" that contain other activities. Which activities get used in your workflow will depend on the type of workflow you're using and your specific needs.

Simple sequential workflow showing various activities.

This simple sequential workflow shows what it might be like to do division in a workflow. Some inputs come into the workflow and are looked at to see if the user is trying to divide by zero. If so, an exception is thrown; if not, the division is done and the results are returned. Looking at the diagram, each of the "boxes" is an activity:

  • The workflow itself.
  • The if/else branching activity.
  • Each branch inside the if/else branching activity.
  • The exception-throwing activity ("divideByZeroFault").
  • The code activity that performs the division.

Windows Workflow Foundation comes with a lot of activities, found in the System.Workflow.Activities assembly, but if you don't like the ones that come with WF, or if you have a special business need, you can create your own custom activities to reuse in your own workflows.

posted @ Friday, March 21, 2008 9:24 AM | Feedback (0) | Filed Under [ .NET ]

Xbox 360 HDMI Conversion Kit

I've got the original Xbox 360 (not the Elite) so I don't have an HDMI port on it. I'd upgrade to the Elite (maybe) except it would bring on the whole DRM problem all over again because I'd be switching consoles. No good.

Mad Catz HDMI conversion kit for Xbox 360Turns out Mad Catz released an HDMI conversion kit for Xbox 360 so you can just buy this adapter and still get the full 1080p goodness you'd get from the Elite.

I saw this bad boy the other day in the Buy More and thought it looked interesting, so I mentioned it to my dad, who is also interested in stuff like this. It's $90 so it's a little more expensive than an impulse buy.

Dad promptly went out and bought it and says it is awesome. He says he and my mom both can see a very obvious visual difference from using the VGA cable and that it's so clear it almost hurts.

Obviously, your mileage may vary, but I think I'm putting this on my list of things to get.

Two Minute WF: Workflow Types

In this Two Minute WF, I'll tell you about the types of workflows you can run in Windows Workflow Foundation.

Out of the box, you get two types of workflow:

  • Sequential workflow
  • State machine workflow

A sequential workflow runs a lot like a flow chart and its design-time experience reflects that. (Yes, I realize that's technically inaccurate, but from a conceptual perspective, that's pretty much it.) Usually sequential workflows run in services or other automated processes that don't require user interaction.

A state machine workflow is exactly what it sounds like - a state machine. You define the set of states the workflow can be in and the valid set of transitions between the states. The actions that occur in each state determine which transition to take to move to the next state. When integrating with ASP.NET, you'll be looking at state machine workflows.

Both workflow types can be modified (within certain limits) on the fly to be dynamic and both can communicate with external services, listen for events, or evaluate rules to determine their flows. Both use the same set of activities (actions - like "if/else," "execute code," etc.) to perform their internal work. (I'll do a different Two Minute WF post on activities.)

Visual Studio 2008 comes with templates that let you very easily create console applications that host either of these workflow types so you can experiment with them and decide which type is right for your application.

posted @ Thursday, March 20, 2008 9:53 AM | Feedback (0) | Filed Under [ .NET ]

Two Minute WF

I've been working a lot with Windows Workflow Foundation (WF) lately, getting it to integrate with ASP.NET, and I found that while understanding the concept of a workflow was pretty easy, getting over the technical hump of what workflow means with respect to WF and how to use it was pretty difficult.

What I really found while searching for resources was that there's a lot out there about "how to use XYZ in situation ABC" but there's nothing that explains to me what XYZ is or what its significance is in relation to the stack.

To that end, I decided to start writing some short posts that just explain what each of the major pieces of WF are and what their significance is. Maybe helpful, maybe not. I'm calling it "Two Minute WF" because I want to give a pretty high-level, easy to understand explanation that you can read through in a couple of minutes, get it, and move on. No major code samples, no in-depth discussions of the bare-metal tech, just a quick hit on what these things are. Maybe if I get through the major components I'll continue the series by adding more examples. Maybe it'll get to that "in-depth" level at some point, but I'd wager you can already find that content out on the web if you search.

Available Two Minute WF topics:

posted @ Thursday, March 20, 2008 9:34 AM | Feedback (0) | Filed Under [ .NET ]

Bird Exclusion

A couple of weeks back we had some birds move into the walls of the house.

See, we've got two dormers on the front of the house and just under the eave overhang on each side of the dormers where the dormer meets the main roof (so four places), the builder didn't actually finish the siding... so there were four places wide open for small creatures to move in. Apparently this is very common, at least in this area.

Anyway, I was working in one of the rooms upstairs and I heard this scratching noise. Going outside and looking up, I could see all sorts of nest-makings coming down the roof out of the hole in the siding.

I ended up having to call a guy and he came in, got all the bird stuff out of the walls, and blocked up all the holes with metal screen. I'd have done it myself, but our roof has a really steep pitch and, frankly, I am not a handy person and have no idea what I'm doing. I'll pay someone else to risk their neck and do it right any day of the week.

If you ever get in that situation and you're in the Portland, OR area, well... first, I'm sorry, because that sucks. Second, the guy I called was Ed Belding from Evergreen Pest Management - (503) 925-9752. Great service, reasonable prices, and he does more than just birds. Give him a call, he'll hook you up.

Now to address the bathtub that's started a spiderweb crack upstairs...

Bookmarks are Worthless

I've been going over my RSS feeds this morning and I found a bunch of cool things that I've been forwarding to my team. Helpful tools, articles that explain tough concepts... good stuff. As I was doing that, I kept thinking, "Oooo, I should bookmark this so I can find it again later."

That's when it hit me, and I'm sure I'm not the first to arrive at this one:

Bookmarks are worthless.

I was thinking about it and with some very small exceptions I can't actually remember the last time I visited a site based on bookmarks. Generally speaking, Google is my bookmark anymore (and not in a "Google Bookmarks" way). If I need to find something, I just search for it. Chances are the resource I would have bookmarked before has been superceded by some better, newer resource anyway. If it's really good, I might blog it so I can tell people about it, but even by doing that, I'm contributing to the PageRank of the resource so if I go search for it again, it's still on Google. Or, barring that, I can search my own site for the link I posted and get it there.

The only real exceptions to this are internal sites - stuff like the expense report system or the PTO request form that I might use a lot but aren't in Google and aren't right on the intranet home page. Other than that, I think I'm going to clean out my bookmarks - I don't need 'em.

Titanium, Tungsten Carbide, and "The One Ring"

Titanium "One Ring"My wedding ring is a titanium version of the One Ring from Lord of the Rings. I like it quite a bit, but it was a real pain to get - the only place you could find them was this German web site which seems to have disappeared since we bought it. Plus, the black finish is beautiful but it scratches given a little effort so you have to be careful. (Metal doorknobs can be problematic if they turn hard, for example, so you have to be pretty mindful of what you're doing.) Sort of lame considering I was going for nigh-indestructible.

Anyway, in the event I have to re-order, I found a couple of options. Boone Titanium Rings has a good general selection and will let you submit custom artwork to create your own laser-etched titanium ring. Now, that's cool and all, but I think the one I'll go with will be a tungsten carbide diamond-etched "One Ring" from Forever Metals.

Tungsten carbide "One Ring" from Forever Metals.

I admit a lot of ignorance when it comes to jewelery and metals and such, so I didn't really fully understand the differences between hardness and durability between titanium and tungsten carbide. There's an educational page on the Forever Metals site that explains tungsten carbide and its benefits. Things like "scratch-proof" and "four times harder than titanium" show up there, which makes it perfect for me.

Of course, Jenn got all worried about what happens in an emergency and the doctors can't get the ring off your finger so they have to cut off the finger instead. I thought I was already hosed with the titanium ring, but apparently you can cut titanium with almost any tool that will cut steel, including a Dremel. As for tungsten carbide, Forever Metals claims:

Tungsten carbide ring can be removed by a medical professional. Rings made of extremely hard materials, like tungsten carbide or ceramic, can only be removed by cracking them into pieces with standard vice grip style locking pliers. Standard ring cutters will not work.

So I'm not screwed and shouldn't lose a finger as long as the medical professional helping me has a pair of vice grips. I have to assume the medical field has figured this one out. Or maybe I should get one of those MedicAlert bracelets that says, "Don't cut off my finger, just get some channel locks."

Corteo

Corteo [Soundtrack]On Friday, Jenn and I went to see the new traveling Cirque du Soleil show, Corteo.

Wow.

I've seen several of the Cirque shows:

Each show has its own feel and I have liked all of them. Mystère holds a special place in my heart for being the first Cirque show I ever saw.  struck me with its size and story. Dralion had a very original style. All of that given, across shows you will generally see some acts reused. The hand-to-hand, amazing as it is, shows up a couple of times. The aerial straps, beautiful to watch, also show up in a few places. Not so in Corteo.

Corteo felt so fresh, so new, that I couldn't help but leave the show feeling happy and invigorated. Everything was so amazing, so crazy, so cool, I'd have to say Corteo is my favorite of all the shows I've seen. It was easily worth the price of admission and I'd see it again in a heartbeat.

I had never seen any of the acts before (with the exception of the aerial straps, which still felt very new) and it included one of my favorite acts, "Crystal Glasses and Tibetan Bowls," a sampling of which you can catch on the Cirque TV show, Solstrom. I liked them all, but if I had to choose, I think I liked the chandeliers and the helium dance the best.

If Corteo comes to your city, go, and feel alive again.

Windows Workflow Foundation Wiki

While working on some Windows Workflow projects I was having some trouble getting ExternalDataExchangeServices to raise events. In searching for an answer, I came across this wiki that has the beginnings of some good material. I think the Windows Workflow community might want to contribute to efforts like this because, frankly, WF can be hard.

Incidentally, the reason my events weren't getting raised was found right on the wiki: I was raising an event from a service where the event arguments were serializable but the sender was not. Everything has to be marked [Serializable], even the sender. Sounds obvious now, but let me tell you what a pain that was to try and track down.

Miserably Ill

I started feeling the onset of getting sick toward the end of last week, but it wasn't really bothering me until Friday night when I started getting a pretty fierce fever. By Saturday morning, I had a full blown case of whatever has been going around work the last few weeks. Upper respiratory issues, stuffy head, fever, headache... ugh.

I spent Saturday in bed most of the day, and barely upright on the couch the rest of the day. Sunday was only different in the proportion of bed-time to couch-time: I made it out of bed a little earlier. I didn't even really do much but watch TV. I tried to play some video games but my need to shut my eyes every few minutes sort of blew that out of the water and having to track all that movement on the screen made my head hurt.

I went to the doctor on Monday and told him all my symptoms.

Me: ...fever, too. And I've got this headache behind my right eye that sort of hurts if I -
Dr: Let me see your glasses.
Me: [Handing over my glasses...] My prescription hasn't really changed in years. I just had my eyes checked in -
Dr: They're crooked.
Me: My glasses?
Dr: Yeah, they're crooked. See how this arm isn't straight and the lenses aren't even?
Me: Oh, wow, yeah... I didn't even notice that. I wonder how long it's been. Would that cause my headache?
Dr: No, but it makes you look funny. Take those in and get 'em fixed.

So, you can see, that was helpful. Actually, he confessed that there really wasn't much they could do for what I've got, that it's common, and basically I just get to wait it out. I got some Tylenol with Codeine to manage my cough and was sent on my way.

I felt a lot better Tuesday - no fever, not much cough - but worked from home to ensure I wasn't bringing this thing back to work to perpetuate the vicious cycle.

I'm feeling way better even today, but my back is sore from sitting on my not-remotely-ergonomic couch all day yesterday so I'm glad to be in my chair... even though my work chair is also not really my favorite. Looking forward to getting rid of this cough - it's getting old.