WF Naming Convention

Now that I've used WF 4.0 for some time, I can start to see some gotchas that easily crop up.

One important convention easily overlooked in WF 4.0 is using the DisplayName property on objects that you bring into the activity designer.  Of course, everyone starts off using WF saying, hey let's be sure to use proper activity names and plenty of commenting so that we know what each piece is doing.  Then we realize, there are NO comments in WF 4.0!  And most of your "Activities" you pull off of the tool bar are not your custom activities that you so carefully named, but are simple things like Assign, If, ForEach, etc.

Use the DisplayName!

Take a primitive "Assign" activity.  Probably all I want to do is assign some variable to the result of a convenient function, perhaps parsing xml into an XElement, or simply forcing the case on a string to remove case sensitivity.  Although I know very well what that Assign is doing, anyone who comes behind me and see's my activity (that's now full of nifty Assigns) will be rather annoyed to have to click on each one, go to the properties and click on it's ellipses to get a view large enough to see the entire content of the Assign.  So, simply putting something descriptive in the DisplayName of the Assign will give the next guy a glancing view at all the properties I'm manipulating in the activity.

More complex types are even more important.  If, ForEach, Throw and others require that you double click on it to be able to see it's contents.  Even the handy "Expand All" link does nothing for these kinds.  So putting something short and descriptive in the DisplayName just might keep the next guy who looks at your activity from pulling his hair out.

Easiest to forget, I think, is that object at the very top level.  Remember that blank screen when you first started that said "Drop activity here"? Yeah, you probably pulled in a FlowChart or a Sequence and forgot all about it, didn't you.  If so, you're probably the kind of developer that has several FlowCharts and Sequences inside that one, too.  And if that's the case, you probably have some variables that are scoped to only one of those FlowCharts or Sequences, don't you?  Now then, which FlowChart is the variable scoped to?  Yeah, that's what I thought!  You have no idea do you!?  That's where using the DisplayName becomes your best friend.  Set the one at the very top to something obvious.

I'm quite fond of using "TopLevel" in the DisplayName of whatever object is at the top.  That makes it real obvious what the scope of each variable is. It's also convenient when you're several layers deep into nested activities, to be able to click on the "TopLevel" link at the top of the page to get back to the top of the activity.

Popular Posts