Chris Donnan : Programming – Brooklyn Style
software, trading, family, fun
Posted way off topic on Thursday, July 31st, 2008.
In or yard, we have the hugest spider web I have ever seen – by far. Now perhaps I have not spent enough time in the wilds of the wold, but this web starts AT THE PHONE LINE up some… 15 feet at least up. It runs across the stairs up to the outside – this stairway is likely 3-4 feet across. The ‘core’ of the web must be around 3-4 feet across, and the extensions run way up to the phone lines. Anyhow – here is a semi-good shot of the spider web.

It made for an interesting camera exercise. It is really the 1st time I was able to USE the manual focus WELL to achieve a purpose. I was able to lower the F down a bit to get the background blurred out a bit. I was able to use a prime lens (although I DID get some good shots with my Sigma zoom) and creep up to see it out a window. Cameras are cool – but I am SUCH an amateur, trying to use my prosumer Canon XTi. I also noticed that the image stabilizer for my Sigma zoom lens has been OFF… Lessons…
-Chris-
Responses are currently closed, but you can trackback from your own site.
Posted .net, c# on Thursday, July 31st, 2008.
In this segment, we will discuss pushing in singletons that you have already created and adding a simple generic hook point.
Here is our starting test. We want to create something outside the container, then add it as a singleton.

This is trivial, we simple give it a delegate that returns that instance when it is called.

Here our lambda is just going to return that instance. (PS – this is a C# lambda expression, google it.).
But wait, what is wrong here… was it so trivial? Well, how about disposal? Do we want to dispose this thing when our container is disposed? I do not think so… So we can create a policy that does not dispose.
Here is a test:

Let us split our SingletonCreationPolicy into 2 parts – 1 that is the same in both cases – the creation bit, and 2 – the disposal bit we can ‘add on’ in only the case we want it in. This results in:
In our Kontainer class:

the basic singleton creation policy is broken out (back to):

And finally, the Disposable version of the policy for ‘container managed’ singletons:

OK, so that code allows us to push singletons into the Kontainer and allows them to be disposed correctly. (Note the use of protected auto-properties. Less code - I like it).
Hook points
Many 3rd party vendors have used events as hook points for some time. I think grid control products like DevExpress’s XtraGrid have gone far and wide using events as the primary ‘hook points’ to their APIs.
In order to give similar behavior to SpringFramework’s IObjectPostProcessor, we can add an event for a similar effect. Let us start with a test:

We want to hook onto the point when a user is ‘getting’ an object. and ‘do something’ before they actually get it. In this case, we are getting drastic; we are completely replacing what the container has internally. Most usages would be more benign most likely.
We change our Get method, add a GettingObject event and allow callee’s to each have a go at the returning object. So our Kontainer class changes like:

This will happily allow callers to modify the created object and return to the ultimate caller of Get the result. It id the event listener’s perogative to elect to process the created object based either on the object itself or on the label.
So; there you have a nice way to push instances of objects into the container and a cheap hook point to ‘do stuff’ when the user calls to Get.
More soon;
Chris
Responses are currently closed, but you can trackback from your own site.
Posted Family on Thursday, July 31st, 2008.
I love being a dad. I have always been a self proclaimed ‘child monger’; making faces at kids on the subway and such. Kids generally like me and I like them. Kids generally smile at me, respond to me – and mostly they give me an excuse to act like a 3 year old myself.
Having just spent a few weeks with my kids; Gabe (who turned 6 yesterday) and Micah (3.5) and I have been thinking about them a lot. I aspire to be a good daddy. Gabe has told me on a few occasions that I am a ‘good daddy’ so I wanted to write up a quick retrospective of a few weeks with the kids – where am I doing well as a dad, where do I need to work, what do they respond to, etc.
My goals as a dad
- To make my boys know they are loved and valued
- To make my boys respect themselves and others
- To prepare my boys to be flexible to lives that change
- To instill in my boys the passion for whatever they find in their lives to care about
- To instill a love of learning in my boys
- To help prepare them to have healthy, meaningful, rewarding relationships with others
- To help them love and respect each other as brothers, people, and friends
My mechanisms for achieving these goals
- Listen to them, be attentive
- Give them boundaries and let them know where they are
- Talk to them at their level
- Put them in good schools
- Cooperate with my wife, align our expectations, talk about the kids
- Spend time with them one-on-one and with the whole family
- Use an even tone when speaking to them
- Think about parenting
- Read about parenting
Where can I improve?
After a few weeks of being with the kids all day, every day – here is what I think I can improve on:
- Micah is still ‘the baby’ a bit. I need to align myself with Gabe as much as Micah when there are arguments, battles, etc. Little boys fight – it is important to make them both know they are respected and have a voice when they get in a tussle.
- Patience. There is no end to the amount of patience that you need to have as a parent. My wife is more patient than I. I have patience, I could use more.
- Evenness of speech. I simply need to keep an even tone when speaking to the boys, when they are in a fight, when they are being nutty, when they are doing anything – I need to have an even tone. This is a ’subclass of’ patience I think.
Divisiveness/ Togetherness
Whenever you have greater than 1 child, it is important to drive them together. My wife Shannon and I work hard at driving our sons together and are very cognizant of ‘not driving wedges’ between our sons. It is very easy to be divisive or cause dynamics that make kids resent one another. “Why is HE getting all the attention?”, “Why am I always getting in trouble?”, etc. This is one of those areas that I think Shannon and I are doing well, but only because we are ALWAYS really thinking of how to avoid driving wedges between our boys, and focusing on how to coerce them into brotherly love.
Boundaries
I thought that the idea of boundaries and their importance needed a quick comment. I think that the concept of boundaries is one of the most central and critical concepts in parenting. Kids thrive on strucuture and expectations. Kids need to know where the ‘edges’ of their lives are. It is SO important (IMHO) to let kids know where their bounds are in their lives. How do you do this? Well, mostly by telling kids where the boundaries are, offering a penalty for violating (and the hard bit) following through with the penalty WHENEVER the violate the boundary. CONSISTENCY is KING with kids.
I read in some book about parenting once; (psuedo-quote) “Kids do not hear what you say, they hear the actions”. So if you say something like “if you color on the wall; then you will go to bed early”, then the child colors on the wall and they DO NOT go to bed early, then the kids learn they DO NOT REALLY HAVE A BOUNDARY.
A general concept in my life that I try to adhere to is; having a STRICT match between my word and my actions. Child rearing is one area of life where the benefits of this mantra are clear. It is clear that this is an important concept to live by in other relationships, work, etc – but in parenting – it is just in your face. When you violate your word, you kids learn that their boundary is NOT where you SAID, but where you acted. They learn you are malleable, and they try to push you and cajole you to sort out where that actual boundary is.
Anyhow – there is my humble 2 cents on being a good daddy. I am not saying I AM a good daddy, just that I want to be
I will ALWAYS be improving in this, and I will ALWAYS need to improve here.
-Chris-
Responses are currently closed, but you can trackback from your own site.
Posted .net, c# on Thursday, July 31st, 2008.
In this segment, we will make our stuff dispose nicely.
1st – let us look @ our creation policies in a bit more detail:
Here is the simplest possible one – a prototype creation policy. It will simply call the user’s func each time it is called, passing in the calling container for possible child dependency resolution :

The singleton creation policy is a bit more:

This policy uses the user supplied func to create a value 1x, then returns the value for all subsequent calls.
Now – why is this relevant? Well in order to dispose properly, we need to make our container disposable and implement that so – in normal form – here is a test and a little class to help test:


All we want to do is to dispose our container and ensure that any disposable items are disposed – for creation policies that want it as such.
So – we will add a dispose method to our container:

Our container has a field that is a dictionary of string to Definition. The list of values is a list of definition. If our definition has a disposable creation policy, we dispose it. This is using LINQ to select the values in an orderly fasion and a functional-esque call to dispose each in the ToList().ForEach(lambda) call.
We updated our singleton creation policy to look like this:

So – now our singleton creation policy will dispose singletons when the container disposes. If a caller supplies any disposable custom creation policy – it will also dispose as per their mechanism.
Now – I need to make sure that I throw exceptions ‘at the door’ when users provide bad data, or use the container incorrectly. After that, I need to make a pass at thread safety for the container…
Responses are currently closed, but you can trackback from your own site.
Posted .net, c# on Wednesday, July 30th, 2008.
In Part 1 of this short series, we outlined the basic behavior for the simplest possible DI container; what I’ll call Kontainer.
In this segment, we will write some code to make those tests pass. In order to allow us to make those tests pass, I wound up doing the following:
- Keep a list of definitions that are registered with the container
- Abstract the idea of an object definition
- Abstract the idea of a creation policy such that singleton and prototype are instantiations of a creation policy, but we could add other creation policies externally if we want.
This led to the following basic code:
The basic class to hold the definition:

The policy used to govern the creation of the objects in the user provided Function

A slightly modified version of the registry part of the container

and the basic bits of the core container


In order to test sub-property resolution, I also added the following test:

What is that all about? Well, the Function signature takes an argument for the calling container so that the class being built can resolve its own dependencies via the container.
This code was sufficient to make our basic round of tests pass. In addition, it was a little bit of relatively simple code. Furthermore, we can handle other creation policies aside from singleton and prototype. In order to prove that out, I added the following test:

And the other test creation policy:

This is a ’singleton per thread creation policy’. This creation policy allows there to be a singleton created per thread. It uses primative locking style that we may change when we make the ‘whole shebang’ thread safe. Essentially – this will allow us to just prove out that we can supply alternate creation policies.
In the next part – we will sort our the disposal needs…
Responses are currently closed, but you can trackback from your own site.
Posted .net, programming on Wednesday, July 30th, 2008.
It is no secret to people who know me that am a HUGE DI proponent. When using a language like C# or Java certainly – you must do it to maintain a degree of flexibility, separation and manageability in their software.
I have used most of the DI containers. Last- I wrote one @ home over the weekend and brought it in to my last employer. In this series of posts – I am going to write a simple DI container, then go and make it threadsafe using some of Jeff Richter’s ’stuff’.
So how do I want this simple container to be?
- JUST DI, (not broad like Spring)
- Code based (no xml)
- Label based (not just type based)
- As little code as possible
Why those things??
Just DI
I want it really, really simple. I have explained DI to people for some time and it is often obfuscated by whatever tool we are using. My ‘dumb simple’ explaination is usually something like:
When you are writing a class, and you need some other thing to help you carry out your behavior, in stead of newing it alive, depend on the appropriate abstraction and allow it to be injected. What do I mean by injected? I mean make a constructor arg or allow a settable property
Code based
I just want code – no XML, etc. It is a pain to debug etc.
Label based (below)
As little code as possible
I want AS LITTLE CODE AS POSSIBLE. I want to maintain NO CODE.
Constructor args or settable properties
Well – constructor args give you a ‘guaranteed fully baked class’ (as long as your arguments are ‘valid’ eg; not null, in the proper state, range etc). Changing constructor args can sometimes be a pain. They are also less amenable to odd circular dependencies (admittedly to be avoided anyhow). While I appreciate the value of constructor args – my general experience is that sometimes settable properties are more flexable. Take for example the case where you need to inject dependencies POST construction (in WinForms for example often the designer will ‘new’ your types).
Type based injection or label based injection?
Some friends of mine prefer type based injection. Some of the other current containers prefer type injection as well. Essentially the idea is that you ‘bind’ some abstraction to some single concrete implementation. For example:
// registration
diContainer.Bind(typeof(FooImpl))
// usage
IFoo f = diContainer.Resolve()
What I don’t like about this is that it forces you to have 1 implementation of IFoo in the system. This is OK in many cases, but it fights the ability to have N different implementations of a common interface. Take for example IPresenter or IView or something general like this. Binding a single implementation to something like this is prohibitive.
So – I prefer to have label based lookups. This has its own downside, mainly that you have to look for string names. With string based lookup – it is something like:
// registration
diContainer.Register("A", typeof(FooImpl)) // or some variation
// usage
IFoo f = diContainer.Resolve("A")
.. or something like that. The salient bit is the fact that you are asking for something by name, as opposed to just by type.
So I am comfortable using settable properties sometimes and names/ labels because:
- With tests, you can be a bit more dynamic
- It is generally a bit more flexable IMO
- With autoproperties, it is little code
So – what do I want the simple container to do?
- Allow me to register definitions for singletons using lambdas/ delegates
- Allow me to register definitions for prototypes (factory behavior)using lambdas/ delegates
- Allow me to register singletons that are already created
- Allow me to inject properties on instances of objects that already exist
- Allow me to get objects from the container by name
- Allow me to dispose objects when the container disposes
- Allow me to dispose objects when the container disposes
- Allow me to add behaviors externally via some hook points
Here are the basic starter tests then of Kontainer, my simple container:


With this set of tests, we get the following interfaces:


Responses are currently closed, but you can trackback from your own site.
Posted Family on Wednesday, July 30th, 2008.
Well, here are some pics (we took ~1000 pics, this is a small ‘best of’ selection).
We went to:
- Saratoga (near Cupertino, Mountain View, etc.) to visit some friends that moved from NY (their lovely daughters are the ones with our boys in the photos – their best friends).
- Yosemite
- San Francisco
![]()
We stayed with our friends in their lovely place in Saratoga. We then stayed in Oakhurst (too far from Yosemite – but we reserved TOO LATE for a good hotel). I DO NOT recommend, the Oakhurst lodge – but at least it was clean and had a small fridge in the room. In San Fran we stayed at the Hotel Nikko – which I DO recommend – it was great.
=Chris=
Responses are currently closed, but you can trackback from your own site.
Posted .net, wpf on Thursday, July 17th, 2008.
Composite Application Guidance for WPF aka PRISM
is out! This is essentially CAB for WPF. CAB had some significant shortcomings. I have been following Acropolis, Prisim, CAB etc for as long as they have been around. I think that this release is pretty useful/ meaningful and I would bet that some real applications will be built on this.
I have been waiting for a really full featured grid to be ‘ready’ to consider WPF ‘ready’. Infragistics still has the most mature offering – but their grid still pales in comparison to DevExpress’s Windows Forms grid. DevExpress’s WPF DXGrid is around now- but it is still eons behind their WinForms grid…. Sad…
I guess we will have to just go about our business and soon enough there will be a real WPF grid. Don’t get me wrong – they LOOK nice and they ARE rich and functional – just not the same as the WinForms versions. It was the same for a while with the MFC controls and the WinForms controls -I think it is just a matter of time.
-Chris
Responses are currently closed, but you can trackback from your own site.
Posted Finance on Wednesday, July 16th, 2008.
Merrill to sell Bloomberg stake for $4.5 bln: report
Raise 4.5 so you can write down… 6?
Ugh.
Responses are currently closed, but you can trackback from your own site.
Posted .net, books, c#, wpf on Wednesday, July 16th, 2008.
I am not sure if I have posted on this yet – but just in case I have not…
Charles Petzold’s 3D Programming for Windows Book
is excellent. When Charles was kind enough to send me a copy of his book, I was not ready to dig deep into 3d WPF. I have been reading more and more of this book – and I have really been enjoying it.
Charles also posted recently how important bloggers can be in the world of book sales. Now – I am no Jeff Atwood in the blogosphere, but I wanted to at least do my part to give some credit where due to Charles.
There you have it – go get the 3d WPF book. Not only is there ‘wpf’ stuff in there – but there is ‘how to really do 3d programming’ in there. If you have ever needed to sort out how to scale, bend, morph and manipulate 3d objects – WPF will help – but technique will help just as much.
-Chris

Responses are currently closed, but you can trackback from your own site.
Posted Family, pics on Monday, July 14th, 2008.
Gabe’s 6th Birthday (and some park photos)
Responses are currently closed, but you can trackback from your own site.
Posted economy on Monday, July 14th, 2008.
Responses are currently closed, but you can trackback from your own site.
