Wednesday, April 11, 2007

Caveat Abstractor

Keith's recent post shows off an excellent use of anonymous delegates. There is, however, the fact that this is a bit weird to debug - as you step through you wind up jumping back and forth between contexts. Nothing that an experienced developer can't deal with, but anything that adds to the cognitive load required to maintain a piece of code needs to be carefully considered. The older I get, the more I realize that maintainability is the most consistently underserved of the five design tenets I like to remember. There's something to be said for having all the code right there in your face.

 

Syntactically, this gets a bit better with C# 3.0 due to the cleaner grammar for anonymous delegates, but I think it still has some of the same maintainability problems.

 

Of course, I've done this sort of thing myself. But I always think hard before I do it, and sometimes I feel a little dirty afterwards. Overused, this is a real maintenance nightmare.

 

Before someone jumps down my throat with a "so we should just repeat all that code, then?" I'll preemptively respond with two points:

 


  1. Well, it's what we did in .NET 1.1. How bad was it then?

  2. Every decision involves tradeoffs. Sometimes the tradeoffs involved make the decision easy. Sometimes they only seem to.

5 comments:

  1. I wrote this [1] last weekend. Am I fired? :)



    [1]





    var Table = {



    Print : function( table ) {

    %>

    <table>

    <%

    top(

    table,

    function( row, table ) {

    %>

    <tr><%

    map(

    table[ row ],

    function( column, row ) {

    %><th><%= H( column ) %></th><%

    }

    );

    %></tr>

    <%

    }

    );

    map(

    table,

    function( row, table ) {

    %><tr><%

    map(

    table[ row ],

    function( column, row ) {

    %><td><%= H( row[ column ] ) %></td><%

    }

    );

    %></tr>

    <%

    }

    );

    %>

    </table>

    <%

    }

    };



    ReplyDelete
  2. Are you fired? It depends. :)

    ReplyDelete
  3. Nah, Mort gets promoted for code like that. I'm on my way to Enterprise Architect. ;)

    ReplyDelete
  4. Wow, I'm surprised people still code like that!

    For better code readability check this blog out:

    http://yummysiliconchips.blogspot.com/

    ReplyDelete