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.

ORM vs. CQRS/ES throwdown – Part 4 – NHibernate

Its now time to start with our first entrant into the ORM throwdown: NHibernate.  I’ll spare you the nonsense about what NHibernate is and why you should use it.  For now, I’ll just point you to nhforge.org for more information about the tool.

As a good practice, I prefer to isolate my NHibernate implementation of the data access layer in a class library project.  This implementation allows me to upgrade and tune the data access layer without directly modifying the rest of the application.  Others will argue that by doing this, I have lost the ability to control the boundaries of a unit of work in the context of a web session.  While I agree, I have given up that control, I prefer to have the isolation of my data access code.

First thing to build is a ProductRepository that will access the database.  To do this, with NHibernate, we need an XML configuration file that will define the dialect NHibernate will generate and utilize when communicating with our data store.  My hibernate.cfg.xml file looks like this:

We next need to build an object that will facilitate the presentation of NHibernate sessions.  The NHibernate session is our gateway to the database.  The catch here is, the session factory initialization is a performance drain.  To combat this, I have created a simple (read: not optimized) wrapper to provide static access to the factory:

A quick note:  see line 30..  I have written a TextWriter that will output to the immediate window in VisualStudio every sql statement that NHibernate compiles.  Yeah, I’m tricky like that  😉

I have written a class, therefore its time to write a test:

I have placed my sql connection string in a constant in this class, hidden in the Fields region, and marked the test as ‘Ignore’.  Why?  I don’t want to run this very time-consuming unit test every time I run my suite, this is more a verification that we are configured properly.

Next steps are to create concrete IEvaluation and IProduct objects, and create a ProductRepository.  I won’t bore you with the concrete object definitions and mapping files here, but the repository to use these objects looks something like:

NDepend reports the following on our NHibernate project:

56 lines of C# code across 5 classes.  The most complex method (SessionFactory.Init) has a cyclomatic complexity of 3.  All other methods have a complexity of 1.  This is good…  it means the code is not complex.  

However, there is a distinct code smell, as direct references to the database structure are now embedded in my DLL.  Additionally, all of these references are buried in object mapping hbm.xml files that are embedded resources in the DLL… This library is NOT very resistant to changes in the database without modifications and recompiling.

Source code is now available at:  https://github.com/csharpfritz/Fritz.Evaluations

In our next post we’ll look at Microsoft’s offering in the ORM game – THE Entity Framework.