Archive for January, 2008

From the Unmanageable to the Manageable

Introduction


Photo courtesy of Leo Reynolds

A while back I ranted about one of the amazingly crappy projects I inherited when a developer left the company. I'm not going to beat a dead horse and tell you how sucky the old app was. I already did that once. Bitching about it wasn't going to do anything, so I fixed it.  It's been running along merrily for a month now, so my confidence is starting to build with it (Yes, I absolutely realized I just jinxed myself).  Instead I want to focus on what I did this time around that I think makes it better.  I'm quite proud of the simplicity of the app and I'd like to share.

Separation of Concerns

The old app was concerned with way too many things.  I've been working hard to componentize various pieces of our business into a service oriented architecture.  The basic workflow of a file from a client goes something like this:

  1. File gets dropped onto our ftp site
  2. File gets unzipped/decrypted/un-whatever-is-keeping-it-from-being-plain-text
  3. Claims are extracted and network discounts are applied
  4. File are zipped/encrypted/re-whatever-was-keeping-it-from-being-plain-text
  5. File gets delivered to client

Simple, eh?  Well, the old app was concerned with all of this and had client specific logic hard coded into the app.  In place of the one app, we now have 3 services, 2 of which already existed before I even rewrote this thing. 

Service #1 is a windows service that reads client information from a database table.  This service is responsible for unwrapping and re-wrapping the files to and from plain text.  It could care less what the data actually is.  It only has a limited set of duties.  The only thing it knows is: "Where do I get the files?", "How do I make it plain text?", "Which internal web service gets the data when I'm done?", "How do I redo what I just undid?", "Where does the final file go?", and "Who do I notify when something bad happens?".   I didn't personally write this app, but I did have a hand in its direction.  It does what it's supposed to, and it does it well.

Service #3 is the other pre-existing service.  This is where our actual discount logic sits.  This is something I created a few years back and just recently revised.  I can't tell you how this works in detail because that's how we make our money.  If I told you, then I'd have to kill you.  If I did that, then I'd have no one to read my blog.

Service #2 is where the new x12 parser and translator sits.  This service can now be a lot more naive than the original.  There's no client specific logic in the app.  It has one focus, and that is to take the x12 formatted file and turn it into a web service call then take the web service response and but it back into the x12 format.

Focus on Only the Things that Matter

One of the things that plagued the old app was how stingy it was with it's input.  It was trying to validate data for segments that never really mattered for our purposes.  All of the parsing logic was the same for the segments, so I pulled that logic into a base class.  This class is responsible for taking a segment and breaking it's elements down into buckets and the reassembling these buckets via .ToString(); nothing less and nothing more.  For those segments we really cared about, I wrote more specified classes that inherited from the base class.  These classes exposed properties that did type conversion from those buckets I mentioned earlier.

Now, if I'm passed a segment that I've never seen, then I'll just treat it like all of the other segments that I don't care about.  I don't have to know what every segment does in order to do my job, so why try to validate it?

Make it Easy to Setup

I mentioned that client logic was embedded in the app.  This really made it hard to add new clients.  With the client information tucked away in the database, the code became a lot simpler to setup and maintain.  Setup is now a breeze because it's just a row insert.  Maintainability is improved because there is none of the repeated code that once existed for each of the clients.  Testing is easier too because I now have a limited set of inputs and outputs that I need to test. 

Conclusion

I'll admit, none of this is ground breaking stuff.  This is just good practices.  I really took pride in the final product though because I felt like the code expressed my original intentions in a very concise manner.  The other pre-existing services made this process a lot less painful and that's how it should be.  It shouldn't take a small act of God to implement something you are already able to do with client A for client B.  Only time will tell if the app is flexible enough to accommodate future needs.  

Photos Going Away

I've decided to remove the photos page for the time being.  I wasn't totally pleased with the integration with my Facebook photos.  I'm looking to possibly replace it with some kind of Picasa Web Album or Flickr version.  That is still up in the air though since I'm not sure that anyone really cares about my photos.  I may just throw photos in a blog post every once in a while.

XSL Noob


Photo courtesy of Will Pate

Yesterday I had my first crack at XSL.  In about 30 minutes I was able to transform an XML document full of medical bills into a summary report worthy of showing other people.  Not too bad for a quick little adventure into a new language.

Everything I did revolved around 2 tags and a handful of embedded functions.  I used "<xsl:for-each />" to loop over a collection. I used "<xsl:value-of />" to pick up individual values from elements.  All of the selectors use XPath to navigate to where you need to be.  XPath itself is kind of odd, but I had already been using it in the past, so this was not an issue.

If you are using XML and you haven't looked at XSL, I encourage you to take a peek.  There are a lot of angle brackets to go around.

De-Cluttering Soothes my Soul

Inspired by a recent zen habits blog post, Ashley and I have made some major efforts at removing clutter from our home.  I'm not going to go into the silly detail of what we've cleaned up or how.  We just got rid of stuff we don't use and therefore don't need.  This new found simplicity is a breath of fresh air.

I can only encourage you to take a look around your space and evaluate your own piles of nick-knacks.  Do you really need that trinket that your great aunt gave you back in the sixth grade? If the answer is no, then toss it or donate it.  Run through that process in for about 30 minutes and see what kind of a pile you can make.

The Cost of Healthy Eating


Photo courtesy of churl

As an employee in the healthcare industry, I'm privileged enough to hear the gripes and moans about the problems with our nation's healthcare system.  There is a large strain on the country because of the rising costs of healthcare.  I'm sure there are plenty of things that could be amended in the current system, but we shouldn't be so quick to point our fat fingers at everyone else.  Our nation is facing an obesity epidemic that I believe is a major source of the strain on our healthcare system.

According to the CDC, studies are showing that obesity rates are increasing in both adults and children.  The studies they mention span from 1976-1980 for the first and from 2003-2004 for the second.  Adult obesity rates rose from 15% to 32.9%.  In a 25 year time span, obesity rates among adults have more than doubled! What's even more mind-boggling is the obesity rates among children.  In that same time span, obesity rates in children ages 12-19 rose from 5% to 17.4%.  In that same time span, childhood obesity has more than tripled!

Now that I'm becoming extremely conscious of what I'm eating, I'm coming to realize that healthy food just costs more money.  The December 2007 issue of the Journal of the American Dietetic Association shows the findings from the University of Washington on the subject.  Their article, The Rising Cost of Low-Energy-Density Foods found that energy dense foods (junk food) cost only $1.76 per 1,000 calories where the least energy dense foods (healthy food) cost $18.16 per 1,000 calories.  Not only that, but the price increase from 2004-2006 for the healthier foods was 19.5% whereas the junk food price dropped in price by 1.8%.   

Since Ashley and I have been eating healthier (lean meats, fruits, and vegetables) I've seen our weekly grocery bill increase by about 30%.  Keep in mind, this is without us buying sodas.  We're buying less food and spending more money on it all.  It's quite depressing.  There's no way that a lower income family could afford the higher cost of healthier food.

Next Page »