Wednesday, August 27, 2008

Uri quirks..

Got bitten by this as this i was using the Uri class to combine some parent child resources. Msdn states that Uri(uri, string) combines the base and relative uri's w/o giving details of what that means. The following examples show that combining two uri's is not obvious :).
(http://www.xyz.com/p1/p2, c1) => http://www.xyz.com/p1/c1
(http://www.xyz.com/p1/p2/, c1) => http://www.xyz.com/p1/p2/c1
(http://www.xyz.com/p1/p2, /c1) => http://www.xyz.com/c1
(http://www.xyz.com/p1/p2/, /c1) => http://www.xyz.com/c1
(http://www.xyz.com/p1/p2, ./c1) => http://www.xyz.com/p1/c1
(http://www.xyz.com/p1/p2/, ./c1) => http://www.xyz.com/p1/p2/c1

 
The gory details of the combination algorithm can be found at http://www.apps.ietf.org/rfc/rfc3986.html#sec-5.2.

Thursday, July 31, 2008

Understanding legacy code.

Most of the time in a software job is about understanding legacy code (any code which survived a few months is legacy :) ). Since this comes up everytime you move to a new team, I sat down to take notes. Surprising how often I forget to do few of the things that worked in the past. Hope you find these useful as well:
  1. Talk to the someone who already knows the codebase and walk through the main components on the board
  2. Play with the final product to get an idea of its features (becomes easy to correlate when you go through the code)
  3. Figure out how logging works in that product. Enable verbose logging (if available :)) and keep watching the tail of log as you play with the product
  4. Attach a debugger and step through the code while you use the product
  5. Run the unit tests under a debugger
  6. Go through the tests for a feature
  7. Go through the bug database by feature. This quickly gives a sense of what you are going to run into :) and a lot more.
  8. <>

Monday, June 09, 2008

Concurrency and coordination runtime

Anyone who has done any amount of async programming knows that it gets out of hand pretty easily. We are good at reasoning about sequential things and async code with its callbacks within callbacks approach breaks this view and makes it hard to reason about things like correctness and boundary cases.

MSR has come up with a different programming model intended to make async i/o based programming dramatically simpler (almost feels like sequential code). It is a library on top of .net and ships as part of robotic studio. For any serious async work, this is worth investigation:
  1. MSDN article
  2. Videos

Thursday, June 05, 2008

Thread local storage leak in Compact CLR

Its pretty easy to use thread local storage on the CLR using the LocalDataStoreSlot and the Thread.Get/SetData methods. The unfortunate part is that the LocalDataStore is not freed after the thread dies .(LocalDataStore is essentially the per-thread data store which is created the first time something is set in the thread storage).

This is a big issue as memory is short on devices and apps which use threadpool to process their work items (using TLS) will end up leaking a lot as thread pool keeps spawning/exiting threads based on load.

Update: this is an issue only with netcf 2.0, it has been fixed in netcf 3.5

Monday, June 02, 2008

Generators in python

Once in a while I used generators as a simpler way of writing an iterator. I did not realize how cool and powerful generators and generator expressions they were till I read this : http://www.dabeaz.com/generators/Generators.pdf - do read it, it will be worth your time.