It is still about CodeMash

Richard Hale Shaw at the Ann Arbor Computer Society meeting on Wednesday gave a good, detailed overview of the C# 2.0 features that are getting used to build interesting things in C# 3.0.

Everything came back to CodeMash. The topic reminded me of Bill Wagner’s CodeMash talk, and the talk he gave at Ann Arbor Dot Net Developers back in December. I had just converted my application from log4net to NLog and ran into a case where I didn’t want to execute some code unless I was logging it. NLog and log4net recommend putting your logger statement in an if block like

if (logger.IsLogErrorEnabled)
log.Error( "oh no!"+ SomeLongRunningFunctionWhichReturnsString() );

I prefer to have my log statements on one line, I find it clutters my source code less. Afterall, logging is NOT the primary concern of my code. I want to focus on the task and hand and obey single responsibility as much as I can.

It turns out C# 2.0 anonymous delegates provide a nice solution (and of course C# 3.0 lambdas make it more readable).

Lets assume our logger has an override with a signature of

public void Error( Func<string> function );

Where Func is straight out of System.Query or Rhino.Commons or wherever.

public delegate TR Func<TR>();

Now the overriden Error method on the Logger class accepts a method as input. If we turn logging off, this method never needs to be executed. Using it is not too ugly.


logger.Error(delegate() {return "oh no! " + SomeLongRunningFunctionWhichReturnsString(); } );

C# 3.0 brings lambdas to the syntax of the language and makes this a whole lot easier to write.


logger.Error( () => "oh no!" + SomeLongRunningFunctionWhichReturnsString() );

And that was only WEDNESDAY!!! WOW.

Thursday followed up strongly with a Michipug meeting where we talked python templating libraries. The format was awesome. We broke into little groups and each group explored the template library. I took a look at twiddler and it is very simple and elegant. I really feel like I grasp the whole thing and I only looked at it for a very short period of time. I don’t use enough python to really comment on any of the libraries we looked at. After looking at them, each group presented an overview of the template library. I think everyone enjoyed the format and learned a lot.

At both of these meetings everyone talked about CodeMash. All of the comments were positive. What a great event. I mentioned that my favorite thing was the presentations on Selenium and Niel Ford’s Productive Programmer presentation. These topics really transcend the CodeMash language barriers. The concepts being The Productive Programmer are really things that EVERY programmer should know. It doesn’t matter if you do Java, Ruby, C, C++, Python, Perl, C#, PHP, whatever. I found it so valuable because at any other language or technology specific conference you wouldn’t get panels like that. It simply wouldn’t fit. It fit perfectly at CodeMash.