September 26, 2007
@ 07:05 PM

I have been a fan of sysinternals tools since 1997 (I think), when their debugview utility saved the bacon of some colleagues and me doing DirectX development on beta Windows 98 - when in full screen Direct3D mode, and when you hit a breakpoint in the debugger, the machine would lock up. We used debug view and liberal trace statements to diagnose a bunch of problems.

One of my favorite sysinternals tools lately (actually...for about a year or so...it's just soooo cool!) is ZoomIt. You can use it to zoom in to some detail during a presentation, to check details about icons or graphics, and I even use it to read things when I am being lazy and don't want to pick my head up and move it too close to the monitor.

Recently I found out about this blog for updates to these tools. I have to admit that I have a lot of trouble trying to keep up with the cool little features they are constantly adding to their tools. As an example, here is a brief timeline of ZoomIt's features, from my fragmented memory:

* ZoomIt introduced: Let's you zoom, mouse wheel zooms more, let's you "Madden" on the screen (draw with the mouse, etc.)

* The ability to change the pen width added

* The ability to change the pen's color added

* Timer mode added (makes the screen into a giant count down clock - great for keeping people from talking too long in a meeting.)

* The ability to make a whiteboard/blackboard with it (side note: last year we were in a meeting with a technical team from one of our indian vendors...I was getting sleepy, and all of the sudden, one of them says, "bring up notepad." I though, "Rock and Roll! Now we're going to see some code...old school style...in notepad...hmmm." I asked, "are you sure you don't want visual studio instead?" The looked at me funny and one of them made a gesture with a pen. I realized they just wanted a white surface to draw on the whiteboard I was projecting onto. Doh! Now I use zoomit for that.)

* Tuesday they added the ability to do _straight_ lines.

 

From there blog, it looks like they update this tool more than once a month. Add that to the other tools, and it's kind of a lot to keep up with...but their tools are sooo nice! I love all the little extra touches.

 


Now Listening To: Oingo Boingo - Dark At The End Of The Tunnel - Run Away
 
Categories:

September 21, 2007
@ 04:16 AM

This is one of those "I used to hate it, now I love it" things. I used to think things should only be nullable for a reason, and you should always care if something is null - always. Null is the extra state beyond all others and I used to think it was very important to keep track of this all the time, in every layer of my application.

Later, I worked on a project (at SNSC) and was exposed to the CSLA framework. The Null object pattern was used a lot and I kind of quickly grew to appreciate it (concentrating my policy on nulls in one place.)

Over the years I have gold plated the way I use this pattern and adapted it for what I am doing at the time. I've come to recognize the following as desirable features for Null Object classes:

  • There should be a "tag" interface for the null object and an implementation. That way, when nulling for a subclass of something else, I can inherit the subclass and implement multiple null object tag interfaces (see below.)
  • They should have a static accessor to a singleton instance, so you don't have to new them up all the time, and get reference equals right.
  • They should have good ToStrings, so it's really obvious when you are looking at them in a debugger.
  • For extra credit, override any mutator or method that changes state to implement your policy: either raise an exception to catch bugs, or just silently ignore.

So, here is a typical null object implementation I have:

image

Some code for EmptyManagerAssignment:

    public interface EmptyManagerAssignment : EmptyAssignment { }

    public class EmptyManagerAssignmentImpl : ManagerAssignment, EmptyManagerAssignment
    {
        private static EmptyManagerAssignmentImpl _instance;

        /// <summary>
        /// Initializes a new instance of the EmptyManagerAssignmentImpl class.
        /// </summary>
        public EmptyManagerAssignmentImpl()
            : base()
        {
        }

        public static EmptyManagerAssignmentImpl Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new EmptyManagerAssignmentImpl();

                return _instance;
            }
        }

        public override string ToString()
        {
            return "{no Manager Assignment}";
        }

        public override int GetHashCode()
        {
            return ToString().GetHashCode();
        }
    }

In this case, the defaults the base class (ManagerAssignment) sets are just fine for the null object, but if I needed say the Name property of the null objects to be different (say I wanted to display "No Assignment" wherever I had the name of a ManagerAssignment in my UI) I would do this in the null object's constructor.

I can then use it like:

        public Program()
            : this("", new EmptyStrategyImpl(), new EmptyIndexImpl(), new EmptyManagerAssignmentImpl(), "New Program")
        {
        }

or

   if (HoldingsAssignment is EmptyAssignment /* or EmptyManagerAssignment...either way */)
   { 
      ...
   }
            

The static accessor thing ("Instance" above) is something I can't decide on. I like the fact that I'm not slamming the heap with a crap load of null objects, and I really like the identity implications of using a single instance of each null object type. But the side effect is that one object could mess up the null object for everyone else:

          if (foo is EmptyAssignment)
              foo.Name = "Look at me! I just messed up the Null object for everyone!";

Because I still like the singleton, I keep waffling back and forth on is whether or not to do something special when someone tries to update the null object:

        public override string AccountNumber
        {
            get { return base.AccountNumber; }
            set { throw new NotImplementedException("Can't update an Empty Manager Assignment...jackass"); }
        }

or

        public override string AccountNumber
        {
            get { return base.AccountNumber; }
            set { /* nop */ }
        }

It helps catch bugs, but most of those types of bugs I catch with unit tests anyway. Besides, it's a heck of a lot of work to implement overrides for everything. I could use a code generator, then regenerate all the time. Been there. Done that. Sux.

Therefore, laziness wins. I have a singleton null object. I don't check every mutator. I have a nice simple code rush template.

One final thing I will add: When using this pattern with NHibernate, I don't want NHibernate storing these null objects in the database, so I currently like to do it like this:

  • Have a field that is nullable. Tell NH about that, not the property:
    <many-to-one name="_holdingsAssignment" column="HoldingsAssignmentID" 
             access="field" cascade="save-update" />
  • Have a property that hides this nullable field from the rest of my classes:
        public virtual ManagerAssignment HoldingsAssignment
        {
            get
            {
                if (_holdingsAssignment == null)
                    return EmptyManagerAssignmentImpl.Instance;

                return _holdingsAssignment;
            }
            set
            {
                if (value is EmptyAssignment)
                    _holdingsAssignment = null;
                else 
                    _holdingsAssignment = value;
            }
        }

 

For a long time I've been meaning to check and see if there is some way to specify a surrogate for null in NHibernate, for reference types (I know how to do it with scalars.)

Does anyone else use this pattern like this? Any tricks? Does this make me look like I have too much time on my hands?


 
Categories:

September 19, 2007
@ 06:17 AM

Scott Hanselman has a series of posts about source code he's reading to become a better developer. I think this is seriously cool and have been inspired to pay more attention to other people's code as well (recently: Quantlib, NHibernate.)

This morning I happened on a video demonstrating a Seam Carving plugin for Gimp. This gets me really excited.

A long time ago, I used to do graphics-y (games and educational software) programming. We had time to work on stuff we liked. I remember working with a library Intel developed for analyzing images and using it to develop a video sketch demo - turning a video into a simulated pencil-sketchy style animation. I had seen this at SIGGRAPH in 1998 and felt this same sense of inspiration I feel now - I just want to know it / do it / be it. I was able to kind of fake my way through it without any code sample, just a video showing a demo and giving an explanation of the underlying theory.

I am reading the source to the gimp plugin now, but it is hard to follow. I might just try half-assing this myself first to get a better idea of the problem, then comparing my code to theirs. That worked for me in 1998, why not now?

Wish me luck!


 
Categories:

September 18, 2007
@ 07:31 AM

My friend Michael shared a great tool link the other day and I learned they have both a portableapps format and a U3 format portable version. This is a great alternative to putty, which is what I used to use (until yesterday) for ssh and FileZilla which I used to use for sftp. Thanks Michael!


 
Categories: tool

September 5, 2007
@ 06:05 AM

I can't be the fist person to notice this, but Powershell is immensely powerful as a code generator. Here-docs  plus the lack of a need for print statements make the process soo painless. Here's my function for generating audit tables:

 

function Output-CreateTableBlock(
    [string] $auditTableName, 
    [Microsoft.SqlServer.Management.Smo.TableViewBase] $baseTable) {
@"
print 'Creating table $auditTableName'
go

CREATE TABLE [dbo].[$auditTableName] (
    AuditID                int identity not null,
"@
    $baseTable.Columns | ForEach-Object { Output-ColumnDeclaration($_) }    
@"
    AuditAction                varchar(12) not null,
    AuditDate                datetime not null,
    AuditApplicationUser    varchar(200) not null,
    AuditDatabaseUser        varchar(200) not null,
    AuditApplication        varchar(100) not null,
    AuditFromHost            varchar(100) not null
    CONSTRAINT [PK_$auditTableName] PRIMARY KEY  CLUSTERED 
    (
        [AuditID]
    )  
)
GO

"@
}

 

This is inside a bigger script that enumerates all the user tables in the database and generates the drop, create, and trigger blocks to hook up our audit tables.

The conundrum I am facing now is: Is it better to have good code or an easy to read template. I started with one giant function that looked up a bunch of stuff then a giant here-doc with the template, then refactored that into functions with one specific purpose each.

I'm not a big fan of code generation anyway (except in special cases such as this - where I am literally just making a easily computable transformation to some other data/metadata that I don't want to be part of my application) so I think I am going to stick with the well-factored approach. I wish code generation was just built into the language like macros in lisp or boo. Then I would just use that language to build everything.


Now Listening To: Curtis Mayfield - Superfly - Little Child Runnin' Wild
 
Categories: PowerShell

September 4, 2007
@ 07:49 PM

My friend Keith is living out my dream: He and his family moved from Seattle to Taiwan last year. He is a developer and working for a US company, but has effectively outsourced himself.

He started a web site where he and others post photos. Subscribed.

The most recent photo of the day has a funny sign, the kind of thing you often see in other countries:

image

There are also lots of beautiful pictures of Taiwan on fotozon. Check it out.


 
Categories: humor