Knowing .NET Sometimes a coder who writes, sometimes a writer who codes. Formerly, a coder who edited magazines.

December 14, 2010

Meteor Shower Movie from Atop Mauna Kea

Filed under: Uncategorized — larry @ 11:54 am

Mauna Kea Geminids

This is a movie of last night’s sky from Mauna Kea and is well worth downloading. If you’re wondering “Why is the sky blue but I can see the stars?” that’s because for the first half of the night, the moon was up! At around midnight, it sets, creating a second dramatic mountain-shadow. After moonset, the sky becomes dramatically darker as the meteor activity picks up.

The lights in the distance are Hilo.

December 11, 2010

Hawai’i no ka oi

Filed under: Uncategorized — larry @ 4:23 pm

I was looking at Poliahu’s white cloak covering the peak of Mauna Kea, and then I put my face in the water and looked down at the coral reef 40′ below me and what should I see swimming below me but a manta ray with a 12’+ wingspan?

December 9, 2010

Programming Challenge: Deep Copy, Overriding Some…

Filed under: Uncategorized — larry @ 10:28 am
  • Imagine that you have a hierarchical object graph:


And you want to merge two instances. Some elements should combine elements from both, some must take their value from the master. My example scenario is artificial, so please don’t say ‘well, if all you have to do is number pages…’

This is my first take:

You can see my pattern:

  • shallow copy
  • combine
  • override
  • recurse

I have two problems with this code:

  1. It’s tedious
  2. The biz rules are spread out to individual classes, but they are more naturally expressed in a single place, e.g., “Merge these two, but use this one as the ‘master’ and use it’s values for Foo.Bar, Bar.Bat, and Baz.Fizz”

(Something I’m not bothered about is the explicit call to GetSomeMergeableElement().DeepCopyDeferringToMaster() — I could use reflection to iterate over the IMergeable fields and call


but I would have to cut-and-paste that loop into each subclass, so no real gain.)

I have a strong hunch that this could be done better in a functional language, but I can’t put it together. Can you?

Update: Here’s my FP-inspired implementation — what do you think?

Here’s the test code:

Powered by WordPress