CSharp On The Fritz
See how sharp a Fritz can be
Scrum Practice: The 15:5 doc

As my role within our scrum project team has evolved into a lead developer, I find myself in more and more design and collaboration tasks with my developer teammates.  I was initially going through oral and white board design sessions with my team to convey how the technical design for the sprint was evolving.

However, our team has grown to 5 developers (including myself), 2 QA analysts, a product owner and our scrum master. I’ve found that my verbal communication approach is simply taking too much time away from coding.  In discussion with my director and our scrum trainer, we settled on a practice called the “15:5 document”.  I have not found discussion of this technique on the web, and will share what I have found over the past week of using this approach.

The 15:5 document receives its name because it takes 15 minutes to write, and only 5 minutes to understand.  This document is a complementary document to the User Story, and I store them as an attachment to the User Story in Team Foundation System (TFS).  This isn’t a full-blown design document, but more of a place-setting.  It is the springboard of tribal knowledge a developer needs in order to get about 40-50% into the design of a user story’s tasks.  The remainder of the design is confirmed through periodic code-reviews when builds are pushed.

Typically, I load the document with:

  • An entity-relationship diagram from Visio or a photo of one scrawled on a whiteboard
  • Some bullet points describing the diagram
  • A sample database table design if necessary
  • A scribbled wire-frame of what the UI may look like

I was thinking of putting together an MSWord template for this type of document, but these 3 sections seem too easy to simply build out as I write out my designs.

Give it a shot…  I’d appreciate any feedback or options of other scrum design practices.  You should see more scrum flavored posts in the coming weeks as I adjust to this role.

    Personal Asp.Net with IISExpress builds

    Recently, I ran into an issue where my team wanted to run their local Asp.Net project builds so that their IISExpress instances were visible to the other team members.  This is a non-trivial setup, as a simple checkbox in the Asp.Net project properties window activates IISExpress to host the project, but does not make it visible outside of the local machine.

    To configure IISExpress to answer to other names (besides localhost) the following steps are needed:

    From an administrative command prompt issue the following command:  

    netsh http add urlacl url=http://mymachinename:50333/ user=everyone

    “mymachinename” is the hostname that you want to respond to, and 50333 is the port that Visual Studio assigned to my project.  Your port may be different, change this value to match the port that Visual Studio assigned to you.

    In the applicationhost.config file at %userprofile%\Documents\IISExpress\config\applicationhost.config find the website entry for the application you are compiling and add a binding like the following:

    <binding protocol="http" bindingInformation=":50333:mymachinename" />

    Finally, restart IISExpress to force the web server to re-load the settings you have just changed.  This should allow the service to answer to the appropriate host.

    However, if you would like to configure Visual Studio to launch and browse to “mymachinename” instead of localhost, you need to change 1 more setting in your web project’s config.  On the “Start Action” section, set this to start with a ‘Specfic Page’ and key in the appropriate full machine name and port combination in the textbox to the right.

    This preference entry is saved in the YOURWEBPROJECT.csproj.user file. By making this decision, you will allow the .csproj file to be checked in to your source control without impacting the other members of your team.

    Data Access Layer decisions

    I am now more than 3 months into the development of a greenfield application for my employer.  In October, after 2 weeks of heated discussions and gnashing of teeth (jk), we decided on using the Entity Framework as a data access layer for this project. This decision came about for the following reasons:

    • Abstraction of database access, allowing us to focus on the business entities we need to construct
    • Automatic generation of SQL to access the database, significantly reducing the amount of code we need to hand-write
    • Through a simple repository model and partial class structure, we’re empowered to easily abstract the data access and unit test our service layers
    • This is a known tool distributed by Microsoft that any .Net developer who is actively working should have some familiarity with

    This decision has allowed us to our application without needing any hand-written SQL stored-procedures or functions.  All of our business logic is encapsulated in a service layer that is 98% covered with unit tests.  This assurance provided by the service layer gives our team the confidence to make changes to the data access layer without significantly impacting the rest of the application.

    Our application lives in a hosted web application model, that is attempting to achieve 99.99% uptime.  To meet these needs, we have redundant web servers, redundant application servers, but only 1 database.  As a software analyst, I want to protect the database processors and memory from unnecessary work.  To that end, I want to move as much business logic away from this single point of failure so that it can focus on what it does best: store and retrieve data.

    When we do need something more sophisticated to access data from the database, we can augment our model with stored procedures that populate and maintain our entities.

    Our project team has profiled our Entity Framework code, and have not found any significant “n+1” query issues.  I will find it very hard to believe that anyone would want us to write additional SQL code, that needs to be maintained. Entity Framework is already generating and maintaining that code for us automatically.

    AJAX performance and Session Management

    Asynchronous loading of content on a web page is an effective way to make web pages with slow loading content appear to run faster.  However, beware abusing this technique, as you may end up making your initial problem worse.

    Consider a web page with 2 div elements that will be loaded by a jQuery ajax load function.  If you simply list these two load commands one after another in a javascript function, the browser will submit both requests back to back, effectively simultaneously. 

    If you are like me, and don’t modify your Asp.Net MVC controllers too much from their boilerplate defaults, you are getting burned by this configuration.  By default, the two requests from jQuery will request read-write access to their server-side session. These requests are translated as GetItemExclusive calls to the Session provider, which block other requests for session while they are operating.

    The first request will request a exclusive access to session, succeed and return promptly.  However, this request will block the second request.  When the second request to the server is processed and requests exclusive access, it will be denied by the first request.  In Asp.Net, the attempt to reload session will block for half a second and then re-attempt to acquire the lock. (MSDN:  http://msdn.microsoft.com/en-us/library/aa479024.aspx)

    How should we work around this ‘limitation’?  Use an Asp.Net controller decorated with the SessionState attribute  When you mark the controller that will generate this content with a ReadOnly or None session state, the requests Asp.Net will make for session will NOT block each other.  The result you should see is near simultaneous return of your two requests.

    Windows Phone testing begins

    I have been struggling with this decision for months.  Finally today, I’ve taken the plunge, and I have a Windows Phone.  A Verizon HTC Trophy with Mango is now in my possession.

    I’m still carrying my iPhone 4S, but the Windows Phone is just so much easier to use and work through social interactions with my family and friends.  But honestly, this is not the real reason I purchased the phone.

    I have several applications that I have written and are just about ready to publish in the Window Marketplace.  However, I want to perform some final tests on a real device, before I publish.  Finally, I also have several ideas for an XNA game or two… and would like to test and build those over the next few months.

    For Christmas, I have acquired and been reading XNA Game studio books.  I am really enjoying what I am seeing in XNA, and will be sharing some of my trials and findings with XNA over the next few months as I build and release a game or two.

    Finally, look forward to the next steps in the CQRS series tomorrow.  This next phase requires a bit more development and fact checking.  I don’t want to present code and strategies that are not accurate.

    ORM vs. CQRS/ES - Part 7 - Intro to CQRS
    Before we plunge into the CQRS approach, a brief description of the CQRS architecture is in order.

    CQRS stands for Command Query Responsibility Separation. For the common developer like you or I, this could be simplified to mean a 2-datastore architecture. In this architecture, we construct a read-only datastore and a write-only datastore. Of course these two are not ONLY for read and write, after all… the system needs to populate and maintain these stores. The naming is intended to define what the end-user’s interaction with each data-store is.

    Before I go too much further, if you want the complete details from THE authoritative source on the topic, I highly suggest reading two thought leaders:

    • Udi Dahan - Founder of NServiceBus, and all around nice guy
    • Greg Young - World Traveller and Founder of CQRS Info.

    By separating the reads from the writes, we enable some significant optimizations in our architecture. A read-only database can be configured to mirror layout and access patterns the end-users prefer when they consume our data. The write-only datastore can be optimized to allow fast append-only access to the store, and a minimum number of indexes allowing for very fast write-access.

    Consider this: when users access your website, they are primarily reading data from your data store. In many environments, the users are less-frequently writing to the data store. When those users are writing to the data store, it is acceptable performance for that write-action to take a second or two to complete. However, Google now considers page speed in search ranking algorithms. So, lets optimize for lightning fast read-access, provide acceptable write access, merge the two and provide details to our end-users about when the last write occurred so they can make appropriate judgements about how to work with our data.

    With the architecture, several choices are afforded to us because we are no longer tied to the necessity of keeping our read and write data in the same structure. The read-only datastore can actually be optimized to be file-stores on disk or we can also consider NoSQL offerings like MongoDb from 10Gen. On the write-only side, the strategy we will be discussing is the “ES” or EventStore strategy. In particular, I will be walking through the usage of the Jonathan Oliver Event Store library.

    How do we tie these two datastores together? How do we ensure that they are consistent? This is the job of a messaging platform like NServiceBus or MassTransit. The scope of using these tools is beyond this discussion, but may be the target of a future blog post.

    In the next post, we will begin constructing a Domain-Driven-Design class architecture to support the write-access to the data store. This will expose the Event objects to be stored. The composition of the read-only store will follow, and we will pull the three parts together in the following post.

    K-Cups - are they worth it?

    Over the Christmas holiday, I wrestled with the idea of buying a Keurig coffee maker for the wife.  Yes, I know…  quite romantic, an appliance for a holiday gift. For the past 5 years, I’ve had and been using a faithful Cuisinart Grind-and-Brew coffee maker that does a great job in making a pot of coffee for me.

    Keurig Mini Coffee Brew system

    Each morning, or programmed from the night before, I set my Cuisinart to brew 3-8oz cups of coffee.  I take 2 cups in a thermal mug for in the car and at the office. The wife has one cup with her breakfast.  I make this coffee daily with 3oz of coffee grounds (or beans that my coffee maker grinds for me) typically from a bag I buy at the grocery store or local coffee shop.  In the k-cup world, this is 3 k-cups we would use each morning.

    Is this cost effective?  Am I saving money if I switch to a Keurig coffee maker?  I tried to run the numbers in my head while I was staring at the rack of coffee makers in the store, and had no luck making sense of it.  So, I did what many programmers might consider, I started measuring things and mapping a spreadsheet to compare.

    What metric am I measuring to determine ‘cost effectiveness’?  I am going to calculate and compare the ‘cost per 8oz cup of coffee’.  

    For this discussion, I am going to normalize the amount of grounds used from the bag of coffee for 1-8oz cup of coffee to 1oz of grounds.

    Using prices from all over the internet (and excluding the cost of tax and shipping), I compiled the following spreadsheet:

    Coffee Price Comparison Spreadsheet

    The results?  Keurig k-cups are 17.9% - 54.5% more expensive than a 11.5oz tub of Folgers Simply Smooth grounds from Walmart.com.  These are not my “preferred grounds”, but they are the cheapest grounds I could find online in a few minutes of searching.  My morning coffee is $0.90 from these grounds, from the Green Mountain k-cups at 1CupCoffee.com my mug costs $1.40 to fill.

    Yes, I typically prefer a more “gourmet” cup of coffee… I would purchase the 12oz bag of grounds from my favorite local coffee shop.  Those are my preferences, and you the reader are entitled to yours.  Feel free to make a copy of my spreadsheet and use it to help your decision.

    Can I afford the additional $0.50 for a cup of coffee?  Certainly.. But purchasing another coffee maker so that I can spend more money on my daily cup of coffee, using non-recyclable k-cups?  No thanks 

    UPDATE:  Thanks to Doug White for pointing out that Keurig makes a re-usable filter called ‘My K-Cup’ that can be used in place of the disposable K-Cups.  This insert allows you to use your own coffee grounds, tea leaves, or hot-cocoa mix to make your favorite beverage.

    Sorry for the delay

    An initial apology is in order. I’ve tried in the past to make blogging a part of my daily / weekly habits, and several life-changing events have happened to me that have delayed that process.

    A month ago, I went through some significant pain and several rounds of tests with a handful of doctors. All of this resulted in the diagnosis of Celiac Disease. In hindsight, I believe I have been exhibiting Celiac’s-like symptoms for as many as 7 years. I am now a gluten-free individual.

    While I initially mourned the loss of TastyKakes (those of you from the Philadelphia region will understand), Papa John’s pizza, breakfast pastries and most fast food menus, I find that I am now on my way to a healthier and happier lifestyle.

    With the apologies and health disclosure out of the way, I will be resuming the discussion of the ORM vs. CQRS/ES series I had previously started. In the days ahead, I have snippets I will be discussing on SCRUM methodology, leading developer teams, continuous testing practices, and hoepfully a bit of XNA sprinkled in for fun :)

    I will be scheduling all posts to be published at 8am (US Eastern Time) on business days of the week. You should see my next post on Tuesday, January 3rd.

    So… let’s get back to our discussions…

    ORM vs. CQRS/ES throwdown - Part 6 - Entity Framework

    Before we get into the CQRS implementation, lets take a comparative look at using the ‘built-in’ ORM tool in the .Net framework - the Entity Framework (EF).  Unlike NHibernate, you do NOT need to go digging across the internet (or load some NuGet packages) to get EF running.

    Microsoft has really done their homework with the tooling surrounding EF.  In NHibernate, we needed to hand-code a series of XML mapping and configuration files that get compiled into our DLL and EXE files.  In contrast, with EF a developer can point the data modelling wizard at a database and all of the corresponding classes and goo to connect the database to your DLL is just generated.

    That’s what I did… I added a new “ADO.Net Entity Data Model”, chose to generate from database and got this popup:

    .. and the resultant model looks like:

    That was a bit too easy…  to get our Product and Evaluation objects to re-map into our predefined interfaces, we need to write some partial classes. Easy:

    Wow…way too easy…  last task, connect up the repository model as defined by our IRepository interface.  Here’s the GetById implementation:

    The rest of the source code is available at:  https://github.com/csharpfritz/Fritz.Evaluations

    So, let’s crank up NDepend and extract some metrics:

    88 lines of code in 7 types.  Our most complex method has a complexity of 3, ProductRepository.Save.  I blame this on my naive approach to adding a Product to the entity context and triggering the SaveChanges method on the context.

    In less than an hour, I had my entire data access layer generated and wired up with Entity Framework.  The tooling generated some code that is very manageable and for smaller projects, I can live with that.  In comparison to NHibernate, if I need more control and want to reduce the complexity of my code, I’ll use NHibernate.  However, if I have a simple project that needs a quick data access layer, I’m using Entity Framework.

    Next up in the series:  our initial discussion of CQRS.  This is NOT a simple topic, and will be spread over several posts.  The first of these posts will describe the design approach and we’ll cover the ‘simplest implementation’ according to Greg Young.  We’ll get into Event Storage in the second post, and we’ll finally hit some testing approaches in the third post.

    ORM vs. CQRS/ES throwdown - Part 5 - Web UI

    I’ve been tip-toeing around this topic, but I think it should be addressed now.  How are we going to access this architecture from our website?  What work is Asp.Net doing in this thing?

    First off:  I am faithfully drinking the Asp.Net MVC kool-aid.  This is some great stuff, and I intend to use that web application model for this example.  I believe that MVC Views should be stupid - check that, MVC projects should be SIMPLE.  These web projects should have little to no logic, as the only purpose of this project is to emit HTML and other angle-bracket code.

    Thanks to NuGet, I can easily sprinkle in the Unity IoC Container and MVC3 bindings for it.  To complete the Unity installation, I added a configuration section to web.config:

    I also updated the BootStrapper class to configure the UnityContainer at application startup:

    Next, I’m going to add a ProductController with a constructor that accepts an IProductRepository.  At this point, I can now swap the data access architectures in and out with a simple change in web.config.

    My Index action looks very simple:

    and finally, a simple index.cshtml to generate a table that outputs the details of our Products.  Piece of cake…  We can get fancy with our views later, and since this series isn’t about fancy web pages, I’ll end this post about UI here.

    I’ll wire up the remaining actions and UI for the web over the next day or two, and you will find the results on the GitHub repository with one of the next posts in the series.