# Friday, April 08, 2005

Last night, I completed my STDF file parser that I started over the weekend.  I'm pretty happy with it.  I now fully support all of the version 4 spec.  It's written with the Feb. 2005 CTP of Whidbey.  It was primarily a good example of a "real world" application, so I wanted to use it to try out some of the spiffy new features and see how they might fit into an application that was not built for the sole purpose of showing them off.

I'm not entirely sure what I should do with it now that I've built it.  There's not much non-commercial demand for something like that that I am aware of. I might be persuaded to license it for use commercially once there is a "go live" license for Whidbey.  I'm sure it will need some testing to work out issues.  I'll probably build a viewer using it and use it at work to get the kinks out of it.  Anyway, I thought it might be useful to capture how some of these features played out in a real scenario.

Lightweight Code Generation

I used attributes to annotate my record classes in order to define the "on disk" layout of the record.  I originally put the attributes on the properties of the record, but decided to move them to the class level so that I could define the fields that are only used for parsing, and not useful after that.  At runtime, I register the record types with the parser, which uses lightweight code generation to generate converters from unknown records to the concrete records.  If you're not familiar with LCG, it is essentially Reflection.Emit without the overhead of a dynamic assembly, module, or type.  If you're unfamiliar with Reflection.Emit, it is essentially generating executable IL code on the fly, which has may benefits over generating C# or some other language and running it through the compiler with CodeDOM or soemthing else. (If you're not familiar with IL, then this entry is somewhat irrelevant) Having dealt with assembly on lots of different instruction sets from 68000 to x86 to DSPs and microcontrollers, I must say that working in IL is wonderful.  I was a bit worried about the startup time for the parser, but it seems to happen very quickly.  I'll need to experiment more to come up with the overhead of the dynamic code.  Again, I was disappointed in the lack of debugging support in LCG.

Generics

Unfortunately, generics did not work into the equation near as much as I had hoped.  I did find them very useful in places where I would normally pass a Type.  Now I can have a much stronger contract on such methods using generic methods with constraints.  I must say that I love the generic collections.  Working with strongly-typed data without having to generate the classes is very nice.  I also like being able to do a custom sort with an inline anonymous delegate with closure-type semantics rather than have the overhead of a separate class with the code in a different place.

Iterators

Iterators came into play in several places.  In the pull-based record parser, it was simple to implement IEnumerable.  I believe it only took 3 or 4 lines of code.

Delegate type inference

I don't remember what the official name of this feature is, but instead of having to do something like SomeEvent += new EventHandler(SomeMethod), you can just do SomeEvent += SomeMethod.  This seems small, but I appreciated it quite a bit.

Visual Studio Enhancements

These were a very pleasant surprise.  I hadn't thought about the exercise as testing the VS enhancements.  The snippets were the most useful improvement in this project.  Implementing properties didn't make me want to rip my hair out. Just type 'prop' and hit tab and fill in the blanks.  The built-in snippets for things like exceptions, attributes, indexers, etc. all work really well.  The one for implementing an indexer/iterator as a nested class was very interesting as well. It was also easy to create my own snippets.  I also found the strongly-typed resources to be very handy.

The debugging stuff is awesome.  I love being able to mouse over variables and drill into them dynamically.  The little popup windows for exceptions are cool, but don't really give you any good information that you couldn't get before.

I found the refactoring support to be extremely useful, although it was a little hard to shift into the mode of making sure everything compiled all the time.  Before, I would jump around alot in the code, so I would leave things in a state where it didn't compile.  It worked great once I got used to it.

posted on Friday, April 08, 2005 11:22:28 AM (Pacific Daylight Time, UTC-07:00)  #    Comments [3]
Related posts:
Writing a CLR host that uses v4 MetaHost APIs, but can run without v4 installed
What is useLegacyV2RuntimeActivationPolicy for?
Happy Birthday Landon!
Happy Birthday, Jenna!
Random fun book thing and CLR In-Proc SxS
9-year Anniversary (yesterday)
Tracked by:
"nfl bowling bags" (nfl bowling bags) [Trackback]
"candle set spa gift basket" (candle set spa gift basket) [Trackback]
"Discover Card Services" (Discover Card Services) [Trackback]
"virginia pilot" (virginia pilot) [Trackback]
"money money money" (money money money) [Trackback]
"viking ships" (viking ships) [Trackback]
"Will Smith switch" (Will Smith switch) [Trackback]
"Hamster Care" (Hamster Care) [Trackback]
"distance learning missouri university" (distance learning missouri university) [Trackback]
"Vinyl Stone Siding" (Vinyl Stone Siding) [Trackback]
"sONGWRITER AND PERFORMER" (sONGWRITER AND PERFORMER) [Trackback]
"What Does Crab Grass Look like" (What Does Crab Grass Look like) [Trackback]
"sunshine key rv resort florida camping" (sunshine key rv resort florida camping... [Trackback]
"Hostel Scotland" (Hostel Scotland) [Trackback]
"strategies for teaching listening" (strategies for teaching listening) [Trackback]
"dunhill cufflinks" (dunhill cufflinks) [Trackback]
"Back seat bangers" (Back seat bangers) [Trackback]
"diflucan and gas" (diflucan and gas) [Trackback]
"oklahoma fraud examiner" (oklahoma fraud examiner) [Trackback]
"Kawasaki Concours" (Kawasaki Concours) [Trackback]
"ultram" (ultram) [Trackback]
"lodging in sedona arizona" (lodging in sedona arizona) [Trackback]
"wifi hotspot locations" (wifi hotspot locations) [Trackback]
"Francisco Goya" (Francisco Goya) [Trackback]
"Mercedes Benz parts" (Mercedes Benz parts) [Trackback]