Set it and forget it

I was writing a post about Events in AS3 and while explaining why in my opinion one approach to passing data is preferable to another I stumbled across the phrase “Set it and forget it” when it comes to programming. I think that this is a great way of describing how I like to write code and is a pretty good way of determining when a certain functionality should be abstracted into it’s own class or sub class.

The basic concept is that as a programmer I shouldn’t need to remember anything special about the class I have just written.

Obviously I’m not referring to things like a particular method or getters/setters but rather little gotchas that you won’t remember 6 months after writing the class.

For example, I was writing an ImageLoader utility class and added some functionality to create a thumbnail dynamically using the BitmapData class. I was pretty happy with the class and it worked very easily, once the data was available an Event was fired and a Getter method was called to return the bitmap. The only issue was that I was returning a Bitmap and MouseEvents are not triggered by Bitmaps so I was having to wrap the Bitmap in a Sprite and then assign listeners. As you can see, the extra step I have to remember is tedious and so I re-approached the class and wrapped the Bitmap in a Sprite before returning it. No fuss, no muss. Now I can just use the class without having to remember anything. I can “Set it and Forget it”

Leave a Reply