Friday, May 22, 2009

They Write the Right Stuff

A few days ago someone on Reddit linked to this fastcompany article about the team responsible for building the space shuttle's on-board software. The main focus of the article is how this team of 260 people consistently releases virtually bug-free software.

This article was really timely for me given some of the Code Camp sessions I attended last weekend. Many of the key points from those sessions were reiterated for me.

Although most of us don't write software that is not only used in but also controls life and death situations, we as a practitioners of a maturing industry could really benefit by studying and incorporating their practices. The article is a bit long but really worth the read.

Indy Code Camp Notes, Part 4

This is part of a four part series of notes I took at Indy Code Camp on May 16, 2009. This year’s Code Camp consisted of five tracks each with five sessions. Track topics were SharePoint, SilverLight and WPF, Data Access, MIX highlights, and best practices. These notes are from the sessions I attended.

These notes are in no way intended to replace attending one of these talks if you have the chance.

Test Driven is Driving Me Insane!

Presented By: Dennis Burton

Dennis's talk focused on road-blocks to effective Test Driven Development and some common, practical test patterns. My notes are a little sparse on this one since it was the last session of the day and my mind was wandering a bit ;) He had a lot of good examples that I wish I could remember a bit better.

Road-blocks To Effective Up-front Testing

  • Management push-back
    • "Double the code? Are you kidding?!"
    • Project timeline impact due to code changes taking longer while tests are updated
  • Test design issues
    • Long-running tests - ideally each test should run in less than a second
    • Long-setup time
    • Fragile tests - more work is required to keep tests running when changes are made
    • Data dependency issues - tests rely heavily on data specific data, often from a production environment

Common Patterns

  • Dummy Pattern - use when an object is needed only to help construct another object
  • Stub Pattern - use when an object is needed to help construct another object and its state must be verified
  • Mock Pattern - use when testing functionality functionality instead of specific data
  • Spy Pattern - use to add validation to an object that does not implement the required validation. This is typically implemented as a wrapper class that passes values into the type being tested

Recommendations

Thursday, May 21, 2009

Indy Code Camp Notes, Part 3

This is part of a four part series of notes I took at Indy Code Camp on May 16, 2009. This year’s Code Camp consisted of five tracks each with five sessions. Track topics were SharePoint, SilverLight and WPF, Data Access, MIX highlights, and best practices. These notes are from the sessions I attended.

These notes are in no way intended to replace attending one of these talks if you have the chance.

Being More Than a Code Monkey: Practicing Beautiful Code

Presented By: Michael Wood - Strategic Data Systems

In this session Michael described some common traits of "ugly" code and presented some guidelines as to what makes code beautiful. Clean Code by Bob Martin is recommended reading for more information on this topic.

Beautiful Code is NOT

  • Hard to follow
  • Hard to extend
  • Something you have to slog through
  • Done with brute force (If it's really hard to do you're probably doing it wrong)
  • Code that people run from

Why Should I Care?

  • Working with ugly code can negatively impact project timelines. If code is difficult to understand it will take subsequent developers longer to get to a position to maintain that code. It can also potentially have cross-project impact if previous developers need to be brought in to help explain the code.
  • Code that is difficult to extend will likely require additional refactoring which can possibly seep into additional areas.
  • Like broken windows bad code tends to beget bad code. High quality standards need to be maintained consistently across the application in order to be effective.

Traits of Beautiful Code

  • Self documenting - types and their members should be named according to their purpose. Comments are nice but need to be maintained to be effective as code is changed. By writing self-documenting code the need for comments is significantly reduced if not eliminated.
  • Avoids using magic numbers - anything that could be a magic number should be defined as constant or enum member. Similarly, consider using an abstract class with constant strings to simulate an enum to avoid having hard-coded strings inline.
  • Exceptions carry additional information - the Exception class has a Message property and an InnerException property...USE THEM!

Code Monkey Song by Jonathan Coulton

Michael mentioned this song and video in his presentation so I thought I'd include it. Enjoy!

Tuesday, May 19, 2009

Indy Code Camp Notes, Part 2

This is part of a four part series of notes I took at Indy Code Camp on May 16, 2009. This year’s Code Camp consisted of five tracks each with five sessions. Track topics were SharePoint, SilverLight and WPF, Data Access, MIX highlights, and best practices. These notes are from the sessions I attended.

These notes are in no way intended to replace attending one of these talks if you have the chance.

Improving Our Craft: A Discussion on Software Estimation

Presented By: Michael Eaton - Validus Solutions

Michael started his talk by tossing out some statistics about project success rates and defining some terms. He then moved on to discussing why we're so bad at giving good estimates and wrapped up with some ideas for how to improve the estimates we do give. Unfortunately I wasn't able to capture the exact stats but they were eye-opening to say the least in that in 2006, only 32% of projects were considered to be successful.

Terms

  • Estimate
    • Tentative evaluation or rough calculation
    • Preliminary calculation of cost
    • Initial judgement
  • Target
    • Statement of desirable objective
  • Commitment
    • A promise to deliver

Understanding Estimates

  • The challenge is to determine whether we are supposed to be estimating or projecting to hit a target. If we're projecting to hit a target do we produce what was expected?
  • Estimates will by their nature, be wrong. We're providing estimates not exactimates.
  • A good estimate is one that provides a clear enough view of the project reality to allow the project leadership to make good decisions regarding targets.

Why Are We So Bad?

  • Unknown problem domain
  • Vague, missing, or large requirements
  • We forget stuff
  • Overconfidence
  • Insufficient education or practice making estimates
  • Never given a chance to succeed (set-up for failure)

The Cone of Uncertainty

The Cone of Uncertainty states that the actual duration of a project can take up to four times as long or 1/4 as long as expected.

What Can We Do?

  • Stop giving off-the-cuff estimates
  • Communicate
  • Incorporate Agile practices
    • Iterations
    • Daily Stand-ups
  • Decompose the problem into smaller chunks and estimate the chunks
  • Let developers estimate their own tasks rather than having a manager or lead developer provide estimates for the team
  • Estimate end-to-end tasks
  • Learn from your mistakes
  • Keep a log of estimates and periodically review it

Monday, May 18, 2009

Indy Code Camp Notes, Part 1

This is part of a four part series of notes I took at Indy Code Camp on May 16, 2009. This year’s Code Camp consisted of five tracks each with five sessions. Track topics were SharePoint, SilverLight and WPF, Data Access, MIX highlights, and best practices. These notes are from the sessions I attended.

These notes are in no way intended to replace attending one of these talks if you have the chance.

Care About Your Craft: Adventures in the Art of Software Development

Presented by: Tim Wingfield – Quick Solutions

Tim’s talk focused on how to get better results out of each phase of the SDLC. Included here are key points from each section.

Design

  • TDD should not be thought of only as Test Driven Development but also as Test Driven Design
  • Design with the SOLID Principles in mind
    • Single Responsibility Principle
    • Open/Closed Principle
    • Liskov Substitution Principle
    • Interface Segregation Principle
    • Dependency Inversion Principle
  • Design by Contract – TDD can actually force us to do this
  • Avoid programming by coincidence - Understand how and why something works
  • Don’t be a plumber - Chances are good that someone else has had to save the same technical problem so there might already be a framework that can be used and let you focus on the actual business problem at hand
  • Justify technology use – Don’t use a technology just because it’s new, use it because it better solves the problem
  • You Ain’t Gonna Need It (YAGNI)
    • Don’t waste time building features that might be used

Development

  • Quality is not an accident – build it into everything starting with requirements
  • Don’t Repeat Yourself (DRY)
    • Reuse code and avoid copy/paste programming
  • Automate where ever possible
    • Build servers are a great for automation
    • Use code generators to speed up development by automating common coding tasks such as creating properties, creating method stubs, and refactoring.
  • Avoid finger pointing by taking collective ownership – We’re all in it together
    • OUR build broke
    • OUR defect
  • Don’t live with broken windows
    • Bad code begets bad code
    • Fix problems when they’re found (time permitting) rather than letting them propagate
  • Know when enough is enough
    • Perfect is nice but software has to ship sometime

Debugging

  • Someone (QA or a customer) will find a defect
  • When a defect is found, don’t panic
  • Think about the solution before rushing to action
  • Avoid placing the blame and work toward the best solution

Continuous Improvement

  • Always keep learning
  • Maintain a positive attitude
  • Be a mentor
  • Create a culture geared toward continuous improvement
    • Schedule lunch 'n' learns
    • Have book reviews

Saturday, October 18, 2008

Adobe Camera RAW vs Nikon Capture NX2

I've been using Adobe Camera RAW (ACR) ever since I started shooting RAW with my D40 in mid-2007.  I've always been pretty happy with the results, particularly after bouncing into Photoshop CS3 and doing some additional adjustments such as some changes in LAB mode but recently I've been wondering what other software is available for manipulating the NEFs that come off of the D300.  Without too much effort I found a ton of sites talking about how Capture NX2 from Nikon is the best editor for NEFs hands down.  Nikon even has a 60-day free trial of the software so I decided to give it a shot.

I've spent a few hours each night for the past few days experimenting with NX2 and found myself seriously disappointed with the software each time.  The problem isn't the quality of the output.  After seeing the results of the various adjustments such as white balance, noise reduction, Active D-Lighting, and a ton of other features I dare not question the capabilities of the software.  It really is great at adjusting NEFs.  Where it really gets me is that it extends my workflow, it results in more used disk space, and it's REALLY SLOW!

With few exceptions I always load the processed NEFs into Photoshop so at a minimum I can add a copyright watermark and a border treatment.  In order for me to fit NX2 into my workflow I'd need to do the processing in NX2, save the image as a TIFF, and open the TIFF in Photoshop, do the appropriate processing, save the PSD, and then export the JPEG that will end up on flickr or a CD/DVD.  With my current workflow I just open ACR via Adobe Bridge, do my processing, let ACR generate a 5-10K xmp sidecar file, and proceed into Photoshop.  Generally speaking, the results with this process are (IMHO) fantastic and I don't have a 70+MB TIFF sitting along side a 90+MB PSD.  Granted I could delete the TIFF when I'm done with it but that would be adding yet another step into the process.  The real deal breaker for me though is how insanely slow NX2 really is!

I've seen some posts that discuss how NX2's UI is a bit cumbersome.  I really didn't think the UI was the problem.  After a bit of poking around I found most of the basic adjustments to be fairly intuitive.  The UI wasn't what slowed me down.  What really slowed me down was how long it took NX2 to complete ANY operation.  Changing white balance?  Wait a few minutes.  Setting the black point?  Wait a few minutes.  Zooming in?  Wait a few minutes.  Applying noise reduction?  Go watch TV.

Maybe the slowness of this application would be more tolerable to me if I wasn't already used to the speed of ACR.  I'll admit that my laptop is a few years old but these same adjustments in ACR are nearly instantaneous!  I obviously don't know what's going on under the hood of these two apps but if Adobe's generic RAW editor can be as good as it is I would think that Nikon could create a specialized NEF editor that would be much better.

My experience this past week with Capture NX2 has left me thinking that Nikon needs to release the full details of the NEF format, get out of the desktop software market, and let the companies like Adobe that have proven their ability handle making the desktop utilities.  It was bad enough when I opened the box for my D300 and pulled out the software suite CD.  I paid $1700 for a D300 and all Nikon is going to give me are View NX and Kodak EasyShare?  How am I supposed to do anything with 14-bit NEFs with those???  And then they want $180 for software that would eat more of my time and storage space?  W...T...F???

In the mean time, I think I'm going to download the trial version of Adobe Lightroom 2.0.  I've seen demos for Lightroom 1 and have liked everything I've seen.  I'm thinking it could streamline my workflow a bit.  That, and I hate Bridge too...but that's another topic for another time.

Friday, July 11, 2008

T-Bird Tail Light

Today was another good day for my photography.  One of my photos won the June 2008 Assignment: Indiana contest!  The topic for June was Vintage Vehicles and I snapped a shot of the tail light of a 1956 Ford Thunderbird while Esther and I were at the 1st annual Carmel Artomobilia event in Carmel's Arts and Design District.

Thanks to everyone that voted for this shot in June.  I'm looking forward to the July contest.

T-Bird Tail Light

This shot was taken at f/8 for 1/160.  Only the usual color adjustments were applied in Photoshop.

Tuesday, July 08, 2008

Streaks in the Sky

For the first time in a long time I tried my hand at capturing some lightning.  I've tried very unsuccessfully in the past to get a lightning shot that I could be proud of but tonight was another story.

We had yet another not so insignificant storm pass through the area tonight.  At first I tried shooting through one of the west windows in our sunroom but by the time I got my camera set up most of the lightning had moved to the other side of the house.  I moved my gear to an east facing dining room window but the screen and trees were causing other troubles.  I was about to put everything away when I decided to move into the garage (also east facing).

At first I wasn't having much luck.  I had been trying to limit my scope to one of the houses across the street (and the sky above it obviously) since I had been seeing a fair amount of activity in that general direction.  After several unsuccessful attempts I changed my approach and zoomed back out to 18mm and widened my field to nearly the entire cul-de-sac.  Immediately after repositioning and opening the shutter I was presented with a perfect flash that I knew was right across the top third of my frame.  I left the shutter open for a few more seconds before closing it.  When the review came up I took one look at it and said to myself "this is the shot I've been waiting for," packed up my gear, and headed inside satisfied that I FINALLY got the lightning shot I've wanted since I got my D40.

Streaks in the Sky

For anyone interested in the technical information about this shot, this was taken at f/8 for 23. seconds.

Thursday, February 21, 2008

Eclipse Photos

Wow! First off, I didn't realize that it has been since the end of September that I posted anything here. So much for keeping this updated!

As many people know, there was a full lunar eclipse last night. For some reason I decided to brave the cold to watch it. I set up the tripod and managed to snap off several great shots of various stages of the eclipse. What really amazed me though was how quickly the photos were hit on flickr after I posted them!

In all of the time I have been posting images to flickr I have never seen a response like this. Up until last night my most viewed photo was a shot I titled 'Round and 'Round We Go that I uploaded back in August. That shot had 67 views as of last night. Four of the eclipse shots approached or exceeded that number in less than 24 hours!

The four eclipse shots that gave my view counts such a great boost are included here for your viewing pleasure. Each photo is linked to the flickr page if you'd like to see a higher resolution version or comment on any of them.

Blood Moon (46 views)
Blood Moon

Take a Bite out of the Moon
(48 views)
Take a Bite out of the Moon

Flared Moon
(49 views)
Flared Moon

Eclipse in HDR
(76 views)
Eclipse in HDR

Friday, September 21, 2007

And The Winner Is...

I entered four photos into the novice division of the September 2007 Photo Venture Camera Club competition. My two on-topic (self-portrait) entries didn't fare too well since the judge didn't like the inclusion of the camera in the shot but I swept the off-topic color category. Here are my winning entries:

Leafscape - Second Place

Leafscape


Bored Dog - First Place

Bored Dog

Friday, September 14, 2007

Great Purchase

So now that I've taken on photography as a hobby I've found myself spending money on all sorts of things. I love my camera (a Nikon D40), lens (a Nikkor 18-200mm VR lens), Photoshop CS3 (particularly the RAW editor), and my flickr account but I have to say that one of my favorite purchases so far was the Wacom Graphire4 6"x8" tablet!

I have been eyeing the Wacom tablets for quite some time but until getting into photography and having software that would actually benefit from the pen I could never justify the purchase. Now that I have Photoshop justifying the purchase was easy. All I can say now is that I'm glad I bought the tablet and honestly wish I had done so sooner.

Using the pen interface instead of the mouse just feels right. Sure, it took a little getting used to but the adjustment time was minimal. I've only had the tablet for a day and I already find myself using it more effectively than a mouse. Everything just seems easier and more natural with the pen.

I've noticed that I don't just get the benefit from using applications like Photoshop but all applications. Choosing cells in Excel is easier, scrolling web pages or Word documents is easier. Dragging files and folders seems more natural. In general, work just seems easier with the pen.

After having used the pen and tablet interface I'd recommend it to anyone.

Thursday, September 13, 2007

I'm Back!

After a long time away I've decided to use Blogger again. I'm in the process of revamping my main site to be focused on my photography and am going to move much of the blog content I had there over to blogger.

Moving forward, I'll use this space to post new technical resources and journal some of my explorations of photography. Hopefully I can get myself to be a little more consistent with posting since I don't have to do anything to maintain this site!

I think it will take a little time to get re-adjusted to using Blogger again. It has been over two years since my last post here. I can't believe I remembered my password!

Wednesday, June 08, 2005

Site Moved

This past weekend I decided to buy my own domain and move my blog to the new site. From now on, all of my blog posts will be found on http://www.davefancher.com. Thanks for visiting and be sure to check out my new "home".

Friday, April 08, 2005

InformationWeek Article

For those that read InformationWeek, you know that articles regarding the auto industry appear regularly. In this week's issue, five auto industry executives are profiled including International Truck & Engine's VP of IT. I was suprised when he used my group (Supply Chain) for one of his examples.

The article can be found at http://www.informationweek.com/story/showArticle.jhtml?articleID=160401450&pgno=3.

Tuesday, March 29, 2005

Kudos

This post is a bit off topic from the usual technical nature of this site but all too often those that deserve praise for a job well done go unnoticed.

This past weekend my wife, in-laws, and I were travelling on a Sunday afternoon road-trip between Crawfordsville, Indiana and Greencastle, Indiana. As we returned to Crawfordsville around 4:00 PM, we were caught off-guard as a Crawfordsville Police officer drove south on US 231 and pointed and indicated to the motorists heading northbound to pull over and stay off the road. Within a minute after the officer passed, a green SUV passed at an extremely high speed and was being pursued by several Indiana State Police squad cars.

After the chase passed, we continued travelling toward Crawfordsville and witnessed another Crawfordsville trooper pulling in some spike strips. Not too far ahead, the police had the SUV stopped and surrounded.

The coordinated effort between the Crawfordsville and Indiana State Police was able to stop the vehicle and prevent anyone from being injured during the chase.

According to the linked article the driver was travelling at speeds of up to 110 mph. At that speed, these agencies had approximately six minutes to coordinate and execute a plan for stopping the driver before she reached Crawfordsville!

As a traveller in the vicinity of this pursuit I must commend all of the departments that were involved. It was their training and quick thinking that prevented anyone from being injured this Easter Sunday.

On behalf of my family, I sincerely thank all of the officers involved for their service.

Thursday, March 24, 2005

Oracle, DB2, and ASP.NET

In my ASP.NET applications, I typically use SQL Server 2000 but lately I have had the need to connect to Oracle and DB2. The Oracle and DB2 providers do not work with ASP.NET out of the box so I thought I'd share some of my experiences along with best practices for resolving the issues. Documentation for resolving these issues seems to be lacking, particularly in the area of DB2.

As you may know, ASP.NET applications execute in the user context of the ASPNET account on the server computer. By default, this account does not have access to the installation folders of the two providers. This lack of permissions will cause an ASP.NET application attempting to utilize either provider to incorrectly report that the corresponding provider has not been installed.

General Issues
Table 1: Default Folders
ClientFolder
OracleC:\Orant\
DB2C:\Program Files\IBM\SQLLIB
One solution to this is to make the ASPNET account a member of the server Administrators group. This approach should be avoided. Instead, grant the ASPNET account Read & Execute permission on the folder where the provider is installed. These permissions should be inherited to lower levels of the directory structure. Refer to Table 1 for the standard installation paths for the two providers. Note that your installation may vary depending on the version installed on your server.

The DB2 Installer does simplify this process a bit. A group named DB2USERS is created during installation and the appropriate permissions have been granted to the group. To give the ASPNET account the appropriate access to the folder, add it to the DB2USERS group. This will require restarting IIS which can be easily accomplished by running IISRESET from the run dialog box.

Oracle Specific Issues
This issue seems to be specific to the Oracle 8i client and the MDAC (Microsoft ODBC driver and the Microsoft Oracle Provider) and is addressed in http://support.microsoft.com/default.aspx?scid=kb;en-us;264012. Essentially, a useless error message is displayed:
SQL State: "NA000
Native error code: 0
Driver Message: [Microsoft][ODBC Driver for Oracle][Oracle]
Do you need any suggestions to avoid the error?"
What is causing this is that some registry entries are incorrect or missing. Follow the instructions in the KB article linked above to solve the problem. Of course, the obligatory warning about incorrect modification of the registry can cause the computer to cease functioning applies.

DB2 Specific Issues
In trying to resolve the connectivity issue with DB2, a DB2 DBA suggested examining the registry to verify that the entries in HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI and HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INT for DB2Connect refer to the appropriate folder. The DBA said that the issue seems to be limited to systems where the client software was upgraded from version 7 to version 8.

My server did not fall into this category and the registry entries were referencing the correct path but I thought I should include it for completeness.

Summary
Whenever a new database connectivity provider is installed and needs to be used by ASP.NET, permissions on the installation folder should be checked to ensure that the ASPNET account can access the files. For security reasons, never set the ASPNET account as a member of the Administrators group although doing so would typically solve the problem.

If the new provider still doesn't work through ASP.NET, determine if connections to the database server can be made using the provided software (SQL+ for example) and query Google for your symptoms. As a personal preference, I typically check Google Groups before trying standard Google.

Tuesday, March 08, 2005

SQL Server 2005 Book Reviews

Now that my SQL Server 2005 presentation is over, I have time to write reviews of the books I used to gather my material! My two primary resources were:

As you have probably noticed, both books have a developer focus. The reason for this is twofold. First, the presentation was for the Fort Wayne .NET user group, a group consisting primarily of developers. The other reason is that they were all I could find on the subject!

Both of these books were fabulous, particularly considering the unpredictable nature of beta software. The books provide excellent preliminary documentation for the new features of SQL Server 2005 including the .NET Runtime Host extensions and Broker Services.

In addition to being well written and full of examples, these books are a great compliment of each other. The Addison-Wesley book shines in the area of defining the syntax of the new T-SQL extensions and providing examples. The MS Press book does not lay out the syntax but provides better examples and often includes a diagram to accompany a discussion.

As is expected with any literature based on a beta product, there are a few issues with the books. Foremost, the books make reference of the System.Data.SqlServer namespace. As of December of 2004, this namespace has been removed and its functionality has been moved back into System.Data.SqlClient. Additionally, The MS Press book makes use of a ":" syntax for creating an object based off of a member of an assembly. For consistency, the ":" syntax has been replaced with a "." syntax.

If I had to suggest one of these books, my vote would immediately go to the MS Press book. The Addison-Wesley book tends to be wordy and drawn out. The MS press book is half the length of the Addison-Wesley book and covers the same information almost in the same level of detail. The MS Press book is also an easy read and its use of diagrams makes scanning for information simple. For anyone serious about getting involved with SQL Server 2005 development though, I would recommend reading these books together to get a better view of the overall picture.

Friday, February 04, 2005

<SUBJECT>At a Loss</SUBJECT>

As I indirectly mentioned in my previous post, I will be giving a presentation on SQL Server 2005 at the March .NUFW meeting. I have been spending a great deal of time preparing for this presentation and have most recently been studying the new XML capabilities including extensions to the FOR XML clause, the inclusion of the XML data type, and the native support for XQuery.

All of these enhancements seem exciting but I am at a loss as to why much of this is being natively supported in an RDBMS, especially one that allows for embedded CLR assemblies. Don't get me wrong, I think that XML is a great technology and have used it many times but like everything else, it is a tool and needs to be used appropriately.

I fully understand wanting to manipulate XML as close to the database as possible to reduce the amount of network traffic typically required to build a dynamic XML document. As I mentioned above, SQL Server 2005 supports embedded CLR assemblies. One of the new features includes in version 2.0 of the .NET Framework is the SqlServer namespace that provides classes for querying and manipulating data against the context connection. This provides an easy and familiar mechanism for building and parsing XML documents inside of the database because the classes defined in the System.Xml namespace are accessible!

I even understand the need for an XML data type so that XML documents may be passed into or returned by stored procedures or user defined functions for parsing or building, respectively. What I do not understand is storing XML in a relational database!

All of the arguments I have read or heard for storing XML in a relational database fall into a couple of categories:
  • XML is universal because it uses UNICODE.
  • XML allows for native mapping of properties to objects, thus, it provides a simple mechanism for persisting and recovering the data related to an object.
These arguments have not convinced me that storing XML in a relational database is a good practice. The UNICODE argument falls apart immediately in that if UNICODE is needed, values can [typically] be stored natively in the database through the use of an NCHAR or NVARCHAR data type (SQL Server and Oracle support this). If natively storing the value as UNICODE is not an option, it can be converted later.

As for the second argument, I will agree that XML does allow for an easy mechanism for persisting and recovering object related data. This is also known as laziness! I would even argue that this approach is lazy even when the data is "guaranteed" (is anything ever certain?) not to change.

I have never seen an XML document that wasn't able to be easily represented in a relational format. It is true that many documents require many tables but the point is that it can still be done. In many aspects, it is also more efficient to store data values individually spread across multiple tables than it is to store a single XML document (or fragment) in a single column.

Parsing the data values into individual columns across an appropriate number of tables provides many advantages to storing an entire XML document in a single column.
  • When storing raw XML, a great deal of space is wasted just to store tags and attribute names. Depending on the structure of the XML, this can quickly add up since it will be extended across all of the rows in the table storing the XML.
  • What if a single value needs to be changed? How about adding a new Item? If the XML document is large, this can be an expensive operation since the entire column value will need to be replaced. (It should be noted here that SQL Server 2005 does support a proprietary XML Data Manipulation Language (DML) but the XQuery specification does not currently support this functionality so it is likely to change in future versions.)
  • What if a different view of the data is needed? Suppose the XML represents an article and only the title is needed? The entire document would need to be read and parsed to extract a single value. The title itself could be broken out into its own column but then other problems may exist:
    1. Multiple copies of the same data if the title is left in the XML. This is wasting space and adding complexity because the values need to be kept in sync.
    2. The title could be removed from the XML and stored in its own column. This is eliminating the purpose of storing the XML in the database in the first place because the title will either need to be added back into the XML for delivery to the client or two queries will need to be run!
  • Another gripe about storing raw XML in a database is that it is difficult to query against. An example is if the XML column stores documents that describe books and a user wants to find all of the books written by "Bob", either every column needs to be returned and searched using XPath or XQuery (SQL Server 2005 provides native support for XQuery but the syntax is an awkward combination of T-SQL and FLWOR)
  • The XML specification does not require values to be strongly typed. Strongly typed data ensures consistency. Storing the values in individual columns that are appropriately typed will add an extra layer of protection to the data.
  • Finally, a "typical" XML document does not represent a scalar value but rather, a complex type.
It is for these reasons that I do not support storing XML in a relational database even for document-centric type applications. As I mentioned earlier, I have no issue with XML itself. I believe that it is a great tool and deserves a place in every developer's toolkit. Like all tools though, it needs to be used appropriately in order to be effective. If my logic is flawed or I have missed something, please feel free to try to change my mind.

Tuesday, February 01, 2005

.NUFW Plug

The .NET User Group of Fort Wayne (.NUFW) meets on the second Tuesday of every month. Meetings are free and open to the public so if you are in the area and wish to attend, please stop by.

Upcoming Events
 2/8/20053/8/2005
TopicMessage Oriented
Architecture
SQL Server 2005 (Yukon)
Overview
SpeakerMike Amundsen [INETA]Dave Fancher


Please refer to the .NUFW Web site for meeting time and location.

Wednesday, January 12, 2005

GMail

I have four GMail invites if anyone is interested. Offer some constructive comments to one of my technical posts and an invite is yours! [First come, first serve but the invites will only be given if a relevant, thought provoking comment is posted]