I was in Southampton recently for a talk titled “An Introduction to CQRS, Event Sourcing and their Benefits”. I’ve got some nice feedback suggesting people generally liked it. I also got some nice criticism – some to do with the focus of the talk (which I’ll cover in another post) but one particular one that brought up the issue of my coding in a text editor -

“Dropping out many times to a text editor to write code that was never compiled let alone executed. What was that about? Why not use Visual Studio so you can compile and execute the code?”

It is definitely an interesting point and well worth addressing. Hence this blog post.

A Brief Description of the Content

The talk was about CQRS, Event Sourcing and the various benefits they can bring. It was about introducing the concepts and see how the orthogonal concepts can be useful from various angles – in implementing a bounded context in domain driven design, in conforming to SOLID principles and good OO practices, in achieving high scalability when needed, in writing good and stable tests etc. It covered a lot of ideas. And time was obviously limited.

Why the Text Editor

The focus of the talk was propagating the ideas. And showing how simple it is to implement those ideas. While simple, that still takes time. I could have pre-coded 15 samples and hit ctrl+F5 or CTRL+U, L and be done with it. However, I doubt that would have been useful in transferring the ideas. A running demo in certain cases is very useful. But it is not really that great in conveying the simplicity of implementing something.

I find Notepad++ to be an excellent tool to convey ideas related to coding. I’m not distracted by Visual Studio or Resharper constantly badgering me to fix my syntax or type in everything to make the code compilable. The freedom it gives (while maintaining nice indenting) means that I can focus on the idea I’m trying to express, rather than create an application in Visual Studio and do “code slides”. For example, the following code:

class LoggingHandle
     ctor(Logger logger, Action<object> next);
     public void Handle(object cmd)

_bus.Register<SomeCommand>(x=> new LoggingHandler(_log, new SomeHandler().Handle));

That is enough to show how we can compose handlers. Does it compile? No. Does it need a bit more work to make it compile? Yes. Does it convey the idea? Yes. Then why do I need to take focus away from the main idea I’m trying to express and create running projects in Visual Studio? Typing that live takes about a minute. Going through VS project with all the implemented classes takes more than that.

It’s not only for Demos

Here’s a secret – I don’t use Notepad just for demos. I use it for real projects as well. If I’m faced with a particularly complicated problem that may have different approaches, I try them out in notepad. If I’m about to write a class that other classes may be using, I will sometimes start writing the method signatures in notepad to see how it looks, how much information is being appropriately hidden and what it “smells” like. In some cases, I even resort to pen and paper. Yes, tests are usually involved as well but this is at a pre-test-just-thinking phase. And I find it infinitely valuable. If I find it so, why would I not use the same thing to convey ideas during demoes?

Perhaps I’m a bit dumb but sometimes I find I need a buffer between my ideas and Visual Studio. And I find notepad to be a great one.

So, yes – dropping into a text editor to write the code that exists only to convey ideas and never gets compiled or executed? This is what that’s about.