Current Entries | Archives   RSS

 


Forgive Me Father, for I Have Singleton'ed

Saturday 14th April, 2007


(or: When Patterns meet Anti-Patterns, do they Annihilate?)

We've had a late start this morning, skipping the opening session because we needed a break after the marathon yesterday (I crashed out with a headache at 6pm yesterday, only waking up to go to the bar to eat at 8pm).

This morning we met up with a couple of other developers at breakfast and had a lively discussion about multithreading, the ideosyncrasies of development tools and network compilation techniques (as seen in Incredibuild). We found the discussion very useful - in particular it helped us to focus some ideas on future versions of Visual Lint - and in particular on the potential for integration with build and continuous integration systems. That's for the future though, and I'll write about that in due course when we've developed our ideas a little further.

The first session this morning was "Choose your poison: Exceptions or Error Codes?" with Andrei Alexandrescu. Coming from a Win32 background as we do, I suspect we tend to use the latter a little too much, so we saw this as an opportunity to learn an alternative viewpoint.

Andrei's delivery was humorous and entertaining. One early point was that in many cases it can actually makes sense to implement both schemes in a library. Utimately, the consumer is best placed to evaluate which scheme is appropriate for a given situation.

Another way is to categorise into soft errors and hard errors. The former can safely be ignored; the latte cannot. Another consideration is the state of the system - if the system is left in an undefined state, an exception is almost certainly appropriate.

The old C standard library function atoi() was used as an example of a library function designed without consideration of error conditions - neither has an error code return nor throws an exception on failure, instead returning 0 (arguably the most common return value!) on error.

Andrei presented four solutions to return error information:

  1. Set a global state (the "errno" approach). This approach (also used in Win32 as GetLastError()) is easy but has big issues with threading and makes error handling far too optional for many tastes

  2. Encode the error code as a reserved return value. A reserved value - conveys very little information, and cannot support centralised handling. It also requires error values to be reserved in the normal return code, which is not possible for atoi(), for example

  3. Encode the error information as a value of a distinct type (an error code). This approach (commonly used in Win32) works quite well but does not lend itself to centralised handling - it's success is entirely reliant on the caller checking the returned error code

  4. Exceptions (effectively "covert return values"). Exceptions are good at supporting centralised error handling. Local handling is also possible, but more longwinded. A key consideration is that only certain callers understand certain errors - the local caller may not, but a higher level method which ultimately invoked it may be better placed to understand the context of the error. The converse can often be true.

From a personal perspective, I have to say that debugging exceptions is not as easy as it could be, and furthermore if you use exceptions you must ensure that declared exceptions are caught somewhere (far too many developers don't, sadly).

The top three issues with exceptions discussed were:

Andrei then presented an intriguing proposal - an alternative approach which combines some of the better characteristics of both. I won't go into it further other than to say it was an intriguing proposal involving a template type called Likely<T>.

During the lunch break the Perforce guys were hosting a sponsor session called "Branching and Mergine without a Safety Net". We went along out of interest (SourceSafe really is showing its age now, and we're always on the lookout for new tools) and I'm very glad we did. The delegate's pack (a rather useful ACCU 2007 bag containing lots of flyers and a rather fat A4 pad) also includes a CD with a fully functional 2-user copy of Perforce, so I dare say we'll try it out when we get the chance.

After lunch the world and his dog squeezed into a far too small room for what turned out to be a highly entertaining session by Kevlin Henney entitled "Pattern Connections" (incidentally, the title of this post is a quote from the session if you didn't realise it). I can't even begin to do it justice here. Suffice it to say that if you get a chance to see him present - just go! Kevlin is apparently a brilliantly entertaining speaker at the best of times, and today he was definitely "in form".

After a brief chat with the Perforce guys Beth headed back to the room to rest, while I headed for the session "Test Driven Development with C# and NUnit", which was actually an extract from the Learning Tree 511 course ".NET Best Practices". We had a very small contingent for this session, but at least that meant we could feel the air conditioning for a change!

Encouragingly, I found that the vast majority of the content of the session covered topics and practices I was already familiar with. As a result, I didn't learn much, but it was a useful confirmation that we are heading in the right direction with TDD. Given that we only started using it back in December, that is extremely encouraging.

During the break we congregated at the Perforce stand for a brief hands on demo of their product; effectively a follow up from their sponsor presentation earlier. Suffice it to say that we were very impressed with what we saw, and we are quite likely to "jump ship" from VSS in the reasonably near future as a result.

A geek gimmick, courtesy of Perforce
A geek gimmick, courtesy of Perforce.

After the break was "Grumpy Old Programmers - The Ultimate IT Chat" or (more accurately) "We Want Beer!". This was a freeform, irreverent and very funny discussion, frequently interrupted by calls of "More beer!" from the panel..

Posted by Anna at 9:20am | Get Permalink