Thank You Oklahoma City Developers!

Thanks to the folks that came out to the Oklahoma City CodeCamp, I had a fun time as evidenced here. (The fact that Mac OS comes with a comic-making application is just fantastic.) It was a blast hanging out with Ray, Scott, Evan, Ben and many, many other folks.

Scott Bellware graciously stepped in on the ping-pong pairing talk for a road weary JP and proved a fierce competitor. We managed to conscript some folks at the talk - Ben Schierman, Evan Hoff, and Ryan Hoegg - to help us demonstrate the pairing game. We had a chance to talk (heatedly) about pairing, TDD, and some finer points of object design in the wild. It was really quite a fun experience for me. I’ve posted the slides and code from the talk for the interested. The panel discussion was another high point for me. I have to give props to Cory Smith for making the Agilists defend and articulate their claims; he’s a great devil’s advocate! While we were dealing with serious topics there were many moments of levity. Apparently in a heated moment Ben captured me saying:

When you fire up the debugger to verify something and then click stop, the ‘test’ that you just performed goes into the ether.  Every time someone does that, God kills a kitten…

I especially want to thank Raymond Lewallen and the Oklahoma City .NET developers for making all this happen. There’s some great leadership and talent in that part of the world. Talking to other developers with different experiences really fuels my fire for taking it to the next level. I sincerely appreciate the opportunity!

The ALT.NET Conference

Scott Bellware made it happen and makes it official. There’s going to be an ALT.NET Conference in Austin, TX on October 5th-7th. So cool! The conference will be run in an Open Spaces style that closely mirrors the self-organizing and community-driven values championed by the Agile community.

Attendance is limited to 100 so be on the lookout for further announcements. I’m guessing Scott’s blog would be a good place to keep an eye on if you want to snag a seat, so go get your subscription if you don’t already have it.

My hopes for this gathering are:

  1. We favor respectful debate over back-patting and head-nodding.
  2. We keep things as visible as possible for those unable to attend.
  3. We ideate more about the tools we need than tools we have.
  4. We spend a significant time discussing what to do over how to do.
  5. We capture lightening in a bottle (as they say) for future events.

If you have any questions, comments, or suggestions get in touch with Scott, myself, or any of the other fine folks on the organizing team:

Why Regions are Fugly

I hate the #region construct with the fire of a thousand suns. I’m serious; they absolutely drive me nuts. Why? They slow me down and make me hunt through to find what I’m looking for. CTRL+I (incremental search) and CTRL+M, CTRL+O (collapse to definitions) and good design principles are all you need.

Here are common reasons you might think you need a #region, with a corresponding reason you don’t.

#1 - Group members of an interface implementation. 

Not necessary. I can see you’ve implemented the interface right after the class. I look there.

#2 - Organize a large class.

Generally not necessary (see #5). For most classes having to resort to regions to make the class manageable is a design smell. Simply put: your class is too damn big. Break it apart by responsibility. Tiny classes people.

#3 - Organize a large method.

What stinks? Seriously if you’ve got a huge method here, break it apart. We’re not doing procedural, we’re doing OO. Maybe you need a collaborator to do some work.

#4 - Group types of members in a class.

This is, in my estimation, is the most inelegant, inhuman — as in robotic — violation of good source code aesthetic. I’m talking about the overly structured class with #region Methods, #region Properties, #region Constructors, etc. It’s just too anal retentive (even for me). Just stack them in order and you won’t need regions. Put things in plain view!

#5 - Group a huge class that’s a Ordered Fluent Interface.

Hmm… Maybe. Okay, so this is where I make a concession on #regions. If you’re going to compose a method chain that employs the IAfterSomeMethod technique I can live with that. There’s an exception to every rule, no?

The Will to Development Power

Jeremy Miller tagged me on the “Becoming a Better Developer” meme that’s been going around in the echosphere. I will say that I’m not a fan of forward-reaching statements. It’s not because I fear I won’t make those goals, in fact I doubt I’ll be held to them. My aversion to the grand proclamation comes more from a deep seeded sense of self-propriety. When it comes to honing or improving my own skill I’ve historically had better luck in gradual, quiet change in small steps. Agile self-improvement?

Sure, like any other developer, I’ll have the periodic larval stage in which I’ll tackle a new technology, method, or paradigm (Agile, OO, .NET, COM, CSS: to name a few). The thing is that it is very hard to predict where and when the need or will to pupate will arise.

Sidebar: I’m feeling an internal call to move from Ruby newb to ninja, but being pretty busy these days I need to find a reason and a way to put it in my path. Still, this larval stage is writing on the wall.

Okay, I think I’ve disclaimed enough there. Time to buck up, be a good sport, stop taking myself so seriously, and answer the question: how I will become a better developer in the next six months?

#1: I will release an open source project.

I assess the power of a will by how much resistance, pain, torture it endures and knows how to turn to its advantage. [Nietzsche]

I need to put my technique out there for criticism, input, and all around dogfooding. It’s great to have conversations and reply to mailing list posts with little fragments, but I can’t imagine anything better for soliciting ongoing critique from a variety of sources. This project will certainly be an application that I can use every day and will fill a gap I’m feeling in my development toolbox. I have an idea in mind but won’t spill the beans just yet.

I’ve been considering this for a long time and the question has been whether to create something new or to become commiter to something that already exists. I’ll say that I’ll do the former initially for reasons of creative satisfaction, though I won’t discount the possibility of the latter. Contributing to the Castle Project or NHibernate is something I definitely should do. Until then I’ll hope my evangelism helps in some small way.

#2: I will work on my coaching skills.

You can’t win, Darth. If you strike me down, I shall become more powerful than you could possibly imagine. [Obi-Wan Kenobi]

Even the most rock star developer hits a limit in terms of productivity. At a certain level of output and desired maintainability it takes a village. I firmly believe the implicit-but-pervasive Agile belief that the team is the essential unit of organization. I’ve made good strides toward this, coaching is a regular part of my job, but there’s always another level and I can improve.

An example: I saw this special about the themes in Star Wars on TV a short while back. One of the things that I remember is the section on mentorship. They talk about Obi-Wan and Yoda mentoring Luke and about how, at a certain point, both mentors knew when to withdraw for the benefit of the student. Remember when Obi Wan disengaged his Light Saber letting Darth Vader cut him down? Knowing just when to go away and challenge is sometimes hard for me but I need to find that sweet spot on this and many other points.

#3: I will improve my communication skills.

The whole course of things goes to teach us faith. We need only obey. There is guidance for each of us, and by lowly listening we shall hear the right word…. Place yourself in the middle of the stream of power and wisdom which flows into you as life, place yourself in the full center of that flood, then you are without effort impelled to truth, to right, and a perfect contentment. [Ralph Waldo Emerson]

I think I’m an OK communicator, but I have room to improve. I view communication as regards software development (and many other activities) as being composed of three main dimensions:

  1. Self-Expression - Am I clear? Precise? How efficiently am I making my point?
  2. Listening - How well do I actively listen to others?
  3. Encouraging - How can I encourage and facilitate the conversation?

Sometimes I might get a tad impatient with people and could throttle back on that or find new tactics. To be clear: I don’t want to be the kind of leader that delivers edicts or dogma from on high. People support a world they help create, and I’m actively looking for ways, without resorting to simple consensus, to support the people that would create their world.

Presenting is another area where I can expose myself to the test of my communication skills. With my blog I also started speaking at various CodeCamps and NUGs, but it’s time to take it to another level and open my horizons on topics. I can’t even express the value that speaking has on sharpening your knowledge of the subject you’re talking about. It’s the act that moves subconscious instinct to the conscious, precise knowledge. Precision is everything when you want to be heard.

#4: I will write (blog) more.

The role of a writer is not to say what we all can say, but what we are unable to say. [Anaïs Nin]

I’m relatively new to the ’sphere. I’ve really only been blogging (in earnest) since last October. Still I’ve not quite integrated it into my day-to-day. Like Jeremy, I can’t begin to convey the benefits of “joining the conversation”. That’s really what a blog is: your proxy to the larger conversation. On the belief that increasing the quality and quantity of my posts will increase the quality and quantity of exposure conversation I’ll up my average weekly posts to three.

Whether or not I post every day I need to write every day. I feel my writing is getting better, faster and more to the point, but I want to take it to the next level. To get there I need to:

  • Write every day even if I’m not posting every day.
  • Get out of the echo chamber; I feel myself sometimes getting sucked in.
  • Write when the inspiration hits, even if it’s a rough sketch in my notebook.
  • At a certain point just let it go.

True Hollywood Story: JMock

Steve Freemen left a comment pointing me to an OOPSLA ‘06 paper he coauthored that details the evolution and design elements of the JMock mock objects framework. Among other things it covers the technique of leveraging role interfaces to control the flow of method chains in an embedded DSL (see section 2.3) as described in my ordered fluency post.

Highly recommended!

Ordered Fluency

There’s been some resurgent chatter about how to put together a fluent interface, whether they qualify as DSLs, etc. I think they do qualify as a DSL just as I think that a Domain Model qualifies as a kind of DSL. Certainly there’s a spectrum of “DSL-ness” for internal DSLs where fluent interfaces and domain model fall at one end and meta-programming powered custom grammars fit a bit further up. Even so, I don’t think the distinction matters all that much as all of these techniques help the goal of clarifying intent.

Controversies aside, I’d like to share one technique for imposing grammar in a fluent interface. By grammar I mean that sometimes you’ll find it’s ideal to employ a fluent interface in a situation where the call to configuration methods need to be in some kind of set order. If you buy that, I’ll make a distinction between Ordered and Unordered Fluent Interfaces. Most examples you see of fluent interfaces in the wild are using a Factory Method on a class that hosts a variety of instance methods that configure or call behavior internally and escape by returning the instance itself. I won’t drill into this too deeply as there are plenty of good examples of how one can make this happen, but here’s a quick snapshot of what these things tend to look like:

Configuration c1 = Configuration.AddFile(“my-file.txt”)
                                .Logging(true)
                                .Tracing(false)
                                .ExceptionShield(someShield);

Configuration c2 = Configuration.ScanAssembly(someAssembly)
                                .Tracing(true);

SomeController controller1 = new SomeController(c1);
SomeController controller2 = new SomeController(c1);

Notice (or pretend to anyway) in this example it doesn’t matter in which order we call the various configuration methods and that we can get the instance of the configured object we need at any time. That is, once we call the static methods AddFile or ScanAssembly we can call Tracing (which returns this) in any order. Each of the methods on the Configuration object returns a reference to the Configuration object itself and at any point we can drop out of deep dotting in our fluent interface and return an object for use.

What this style of fluent interface presuposses is that the initial, static, Factory Method will return a valid Configuration object. Great. Very simple and workable in 99% of cases where you’re using a fluent interface to configure an object or process a series of commands on an instance, etc. But what if you want to build up an order-dependent structure? A good thought experiment for this kind of problem is the sentence.

Using Interfaces to Control Flow

You can leverage interfaces to control the order of operations on our fluent interfaces. Let’s introduce a contrived example where we have a need to model a sentence grammar with a fluent interfaces. The main requirements are that a Sentence object must produce grammatically valid English and that we’re limiting the potential structure of a sentence to the following rules:

  1. Every sentence MUST start with a person’s name, a pronoun. You, me, and they are not supported in this version.
  2. A verb must follow the person’s name. We need three verbs for our application: Run, Throw, Eat. (What a weird application this is: again, contrived.)
  3. A simile can be used after a verb: e.G. John eats like a pig.
  4. Sentence text must end with a period or question mark.
  5. A sentence can only end after a verb or adverb has been used.

In this example order matters and if so we need to control the flow, otherwise we could end up with invalid language. We can knock out requirement #1 pretty easily by using a factory method on Sentence:

public class Sentence
{
   private StringBuilder _text = new StringBuilder();

   // force creation of instance through Sentence.Subject()
   private Sentence() {}

   public static Sentence Subject(string someone)
   {
      Sentence result = new Sentence();
      result.AppendText(someone);
      return result;
   }

   public string Text
   {
      get { return this._text.ToString(); }
   }

   private void AppendText(string text, bool space)
   {
      this._text.Append(text);
      if (space) this._text.Append(” “);
   }

}

I’ve got a couple of helper methods for appending to the sentence as we dot along our API. Other than that pretty straight forward. Now let’s tackle the second requirement which states that a verb must follow our sentence subject. I’ll introduce an interface and make a few tweaks to the Sentence object:

public interface IAfterSubject
{
   IAfterVerb Runs { get; }

   IAfterVerb Throws { get; }

   IAfterVerb Eats { get; }
}
public class Sentence : IAfterSubject
{
   private StringBuilder _text = new StringBuilder();

   public static IAfterSubject Subject(string someone)
   {
      Sentence s = new Sentence();
      s.AppendText(someone);
      return s;
   }

   public IAfterVerb Runs
   {
      get
      {
         this.AppendText(“runs”);
         return this;
      }
   }

   public IAfterVerb Throws
   {
      get
      {
         this.AppendText(“throws”);
         return this;
      }
   }

   public IAfterVerb Eats
   {
      get
      {
         this.AppendText(“eats”);
         return this;
      }
   }
}

So I’ve made Sentence implement IAfterSubject. This means I can simply return “this” from the Runs, Throws, and Eats methods. Bet you can guess what comes next:

public interface IAfterVerb : IEndOfSentence
{
   IAfterSimilie LikeA(string noun);
   IAfterAdverb Adverb(string adverb);
}

Of course I implement this interface on my Sentence class. Note that IAfterVerb also implements IEndOfSentence. This is because I can do more than one category of thing after I reach the verb part of my sentence. I can choose to end the sentence right there “Bob eats” or I can employ simile “Bob eats like a pig” (no offense, Bob).

If I choose to end the sentence, per my requirements, I’ll need to finish with a period or question mark, we’ll implement like so:

public interface IEndOfSentence
{
   Sentence Period();

   Sentence QuestionMark();
}

The Period and QuestionMark methods both return the sentence. Their implementation is straightforward. They add append “.” or “?” to the text of my sentence and return a full sentence object that I can then do with as I need including calling the Text property which gives me the, well, text or using the Sentence as part of a larger Composite, say we have a Paragraph object somewhere.

A few more of these interfaces and we’re able to compose type-safe statements that look like this:

Sentence s1 = Sentence.Subject(“Bob”)
                      .Eats
                      .LikeA(“pig”)
                      .Period();

Sentence s2 = Sentence.Subject(“Jane”)
                      .Runs
                      .Adverb(“crazily”)
                      .QuestionMark();

Sentence s3 = Sentence.Subject(“John”)
                      .Throws
                      .LikeA(“girl”)
                      .Period();

Alternative Uses and Implementations

A powerful technique there, but definitely not the only way to skin a cat. If you need to provide flow in an additive sense (that is one statement on my interface will add additional methods) you can try a return a decorator instead of simply returning a role interfaced “this.” I am sure there many ways to accomplish controlling the flow. Generics spring to mind as an interesting possibility in terms of branching your choices or controlling statement input. Still, keeping it simple, I like to keep the logic in my Sentence class and can control the API very tightly with multiple, role interfaces. The possibilities are varied and many.

It’s important to remember that this technique doesn’t necessarily have to follow through the whole fluent interface. My sentence example shows a rigid extreme, but you could easily host methods on the class hosting the fluent interface that simply return a straight-up “this” instance but occasionally provide methods that lead to “flow fragments” where you enforce a particular order. The first example that springs to mind is a Query Object where you want to create some syntax like Between(”DateField”).InTwoWeeks then pop back into regular, unstructured flow. Between returns an IExpressionsAfterBetween which itself implements a bunch of IExpression interfaces (IInTwoWeeks, INextQuarter, IDateRange) where each “expression method” then returns a QueryObject (the “this”) or, even better, an IAfterExpression interface with an And method, an Or method and a Query property that returns the QueryObject itself.

To deal with all this interface madness it’s pretty easy to stuff them into a sub-namespace as you won’t need a using to work off the class that’s hosting the fluent interface. I sometimes use this technique to keep auto-complete noise to a minimum.

OK Go!

My friend Raymond Lewallen has kindly invited me, Jean Paul Boodhoo, Scott Bellware, and Jeremy Miller to Oklahoma City on July 28th for CodeCamp Oklahoma City. They’ve got two tracks: one for the hot, new .NET technologies and one with more of an Agile/ALT.NET focus.

JP and I are doing a tandem talk on Ping-Pong Pairing which should be both entertaining and informational: infotainment, if you will. Dig it:

You Got Served: Ping-Pong Pairing

Pair Programming is a central method of a high-functioning Agile team. It amplifies Test-Driven Development (TDD) and promotes Collective Code Ownership. Despite the numerous benefits, installing Pair Programming often fails with first attempts perceived as frustrating for more experienced developers and flat-out boring for the non-coding partner.

Wouldn’t it be great if pair programming was easy, engaging, and (dare to dream) fun?!

Enter Ping Pong Pairing (PPP)! Join Jean-Paul Boodhoo and Dave Laribee for a match of PPP. Serving the rules of the game, JP and Dave will start a long volley of TDD and share key tips for putting a little backspin on your solutions!

Though our main point is that pair programming can be fun, we’ll surely have opportunity to share plenty of TDD/DDD/OO/R#/Refactoring/etc. tips along the way. I’m stoked! Come share in the excitement and get yourself registered!