Unhandled Exceptions

18 Nov

Extension Methods, Fluent Interfaces, and the evils of API Pollution

I am going to propose a guideline for the use of C# 3.0 Extension Methods: Don’t Use Them to Rename Existing Functionality in an API Just Because You Don’t Like A Function’s Name.

The idea of extension methods is that you can improve an otherwise non-extensible object’s public API by ‘extending’ its Interface to include additional methods that the original class designer hadn’t considered.  Used judiciously, this technique can improve the usability of the object and make interacting with it much more intuitive.  Common uses are in the areas of aggregating what would otherwise be calls to multiple separate methods into a single ‘meta-method’ that wraps several more atomic methods, providing ‘converter’ methods that handle type conversions, and wiring up external validation logic to an object.

But all too often lately I am seeing these methods used simply to provide alternate preferred names to existing methods already present in the original class.

Unit Test Frameworks should remain Pure

This is probably most-commonly seen in (of all places) Unit Test frameworks.  For a long time there was (general) agreement among both designers and users of Unit Test frameworks about the ‘common’ way to state assertions.  Or at least I thought there was general agreement.  Apparently, it seems that this ‘agreement’ may have just been a consequence of people not having an easy way to deviate from the commonly-accepted norms.

Today in all kinds of sample code in various blog posts all over the Internet I routinely see things like…

Assert.AreEqual(expected, actual);

Assert.Equal(expected, actual);

Assert.That(expected, actual).AreEqual();

Assert.That(actual).ShouldEqual(expected);

Even if reasonable people can debate the ‘best’ way to state an equality assertion in a unit test framework, I firmly believe that the place for this debate is between the team maintaining the unit test framework project and its user-base, NOT between different adopters of each Unit Test Framework by randomly inventing extension methods that provide the exact same capability as already present in the framework.

Technology isn’t evil, but its implementation sure can be

This isn’t to say that I don’t like fluent interfaces and don’t like extension methods.  These are just techniques and technologies like any other that can be used either for good or evil at the whim of the developer who wields them.

But when used to arbitrarily restate behavior that already exists on a class in an alternate syntax just for the sake of a very limited (and entirely debatable) improvement in readability, I think reasonable people have to agree that this is leading us down a road towards what I call API pollution where three and four methods on a single class all do the exact same thing but use a slightly different syntax to accomplish it.

Assert.That(actual).Should().Nearly().Equal(expected).Except().When().Varying().By().LessThan(3);

…is the inevitable end-result of this trend and I for one don’t want to try to be a consumer of such a framework, no matter how ‘readable’ it was thought to be.

17 Nov

Autumn of Agile Iteration 1 Part B Primer Notes

As promised, here are the preparation materials for the upcoming next installment in the Autumn of Agile screencast series.

In this installment, we will be looking at completing our first User Story (User can associate self with one or more skills) by creating our first ASP.NET MVC page, wiring up ASP.NET MVC to take advantage of Rhino Tools infrastructure, and building our first Repository to use NHibernate to access our database.

To set the stage for all this work, I am recommending the following resources be explored to help provide some basis for better understanding the upcoming session…

James Kovacs excellent intro to the concepts of IoC and DI from MSDN Magazine:

Tame Your Software Dependencies for More Flexible Apps

http://msdn.microsoft.com/en-us/magazine/cc337885.aspx

The sadly less-than-comprehensive Rhino Tools documentation (and if you find the docs lacking, its a WIKI so go contribute something, damnit!):

http://ayende.com/Wiki/Rhino+Commons.ashx

For the video-inclined…

Roll Your Own IoC Container by James Kovacs (this guy seems to be on the ’share-DI-with-the-world tour courtesy of MSDN smile_tongue)

http://www.dnrtv.com/default.aspx?showNum=126

The ASP.NET MVC homepage (with a decent collection of 10-15 minute videos that introduce the concepts one at a time) [warning: many of these are slightly outdated and don't reflect the latest BETA release so pay attn to the concepts rather than the specific coding in each video]

http://www.asp.net/mvc

Phil Haack (ASP.NET MVC Product Manager)’s ASP.NET MVC talk @ PDC

http://mschnlnine.vo.llnwd.net/d1/pdc08/WMV-HQ/PC21.wmv (warning: this link leads to a 300mb + download!)

Where to Focus

Since there is a lot here, many people with limited time will have to pick and choose where to focus their attention.  If you must choose among the above, I recommend that you…

  • Read James Kovac’s MSDN article and grok the concepts rather than the details (Windsor will abstract away the guts of the details for us anyway); if you are unfamiliar with IoC and DI, this article is an excellent intro
  • Read the table-of-contents at the Rhino Tools WIKI page to get a good sense of the overall capabilities of the libraries; don’t concern yourself with any of the details at this point as we will be covering the real-world implementation of some of this collection in our own screencasts
  • Watch Phil Haack’s PDC presentation; it walks you thru making the transition from WebForms thinking to ASP.NET MVC thinking and along the way introduces most of the important ASP.NET MVC concepts that I won’t be bothering to cover in my sessions as info is already provided in many other places on the ‘net (ASP.NET MVC has to be the most comprehensively-documented BETA release in history in terms of the number of resources that are out there on learning it)

Lastly (and this one is simple since its just a 2 paragraphs in length) review the following definition of the Repository Pattern culled from the always-excellent (and mandatory reference source on every good programmer’s bookshelf), PoEAA by Fowler…
http://martinfowler.com/eaaCatalog/repository.html

But where’s the screencast?

Astute viewers will take note that I am now officially ‘late’ with the next installment of the series.  This is because I am still struggling with the original challenge that I mentioned when first considering this series: that of having to decide whether to record every little bit of coding I’m doing or fade-in and fade-out a-la Rob Connery’s ASP.NET MVC Storefront series.

What I’ve decided is that for the initial several iterations we are going to see everything I do since its setting the stage/foundation for what’s to come and at some indeterminate point in the future I will switch to a more fade-in/fade-out style of showing what’s going on so that repetitive stuff goes away and the focus remains on the new stuff for each iteration.  We’ll see how that goes smile_sarcastic

13 Nov

ALT.NET NYC Meeting 03 Videos are Posted

Just wanted to point out that the videos for the most-recent ALT.NET NYC meeting have just been posted for viewing.  In this meeting we had the benefit of a guest appearance by the famous weary traveler Oren Eini, better known as Ayende Rahien, the creator of RhinoMocks, and contributor to various well-known OSS projects like NHibernate, Castle Windsor, Castle MonoRail, Rhino.* (tools, commons, queues, security, etc., etc., etc. smile_tongue) and more I’m sure I’ve forgotten to mention here as well.

Ayende = CHAOS (but not in a bad way) smile_teeth

As is usually the case when Oren is involved, the discussion bounced from topic to topic as one conversation trended into another area, into another, and so on.  That meant that the discussion didn’t manage to stay particularly well focused on TDD (or mocking!) but instead jumped from topic to topic in an effort to explore all the various areas that attendees wanted to explore.

This is partly due to a few different reasons (IMHO):

  • attendees arrived with very different levels of experience in unit testing in general and TDD specifically
  • its somewhat difficult to discuss effective TDD without also exploring the other practices, technologies, and design principles that help to support it (Dependency Injection, Inversion-of-Control, Mocking, cohesion, isolation, etc., etc., etc.) and attendees had vastly different levels of exposure to all of these topics as well
  • Oren can speak to many if not all of these topics at once and also provide valuable (and usually amusing!) anecdotes to reinforce his opinions and this can often further move the conversation off its planned track

ALT.NET  = UNEXPECTED

IMHO one of the underlying premises of ALT.NET meetings is that of “what happens happens” (see Open Spaces and other sources for additional details) and this can sometimes mean that a planned narrow focus of discussion can branch off into equally (if not more) valuable conversations but ones that don’t necessarily remain ‘true’ to the publicly-stated focus of an event.

While we received feedback from some attendees that they were disappointed at the wide-range of discussion varying from the more narrowly-stated topic of TDD and Mock Frameworks, I believe that the meeting was never-the-less a strong success in that attendees were exposed to a much wider variety of discussion topics, tools, recommendations, and ideas than would have been possible had the topics stayed more ‘true to plan’.  To be fair, we also received feedback from attendees that reported that this meeting was an incredibly valuable experience that left them with all kinds of new ideas that they wanted to go begin to explore on their own after having been introduced to them for the first time.

So if you’re interested in a rip-roaring, topic-jumping, wide-ranging discussion about all things test-related (and otherwise too as we slide into ASP.NET MVC and other reasonably unrelated topics!) then surf on over and check out the videos.

And if you want to visit a meeting where you can be assured that the conversation will not stray from the narrowly-stated published topic, then I think there are any number of more traditional user groups out there that will give attendees the opportunity to sit through a pre-canned powerpoint that never varies from the planned meeting topics.

December Meeting Skipped

We will be skipping the December meeting slot since the 4th Wednesday of the month of December is actually Christmas Eve, but we will be back in January with a topic that has yet to be determined (and may not be adhered to even if we pick it and announce it! smile_embaressed)

If you can make it, we hope to see you the 4th Wednesday in January in NYC.

12 Nov

AltNetpedia gets index of ALT.NET User Groups~!

For those of you readers interested in ALT.NET User groups but too far away/too busy/too lazy smile_teeth to attend one yourself, a new page in the AltNetpedia site has been added to which user groups are posting videos of past group meetings: http://altnetpedia.com/videos-of-user-groups.ashx

So far there are links to videos of the ALT.NET NYC User group as well as the Chicago ALT.NET group.  Continuing the theme, the Open Spaces conference in Israel video has been linked there as well.  If you have an interest in some of the topics that are discussed in these meetings, I would encourage you to view/dowload/watch some of this content (I know I plan to watch the Chicago stuff if only to get a good sense as to how other groups are running their meetings and to get ideas about our own NYC group).

Anyone with video content of ALT.NET-focused meetings. events, etc. is encouraged to add to the page (its a WIKI after all).

Happy viewing~!

10 Nov

Autumn of Agile: Iteration 1 Part A screencast is available

I am pleased to announce that the next installment in the Autumn Of Agile screencast series is now available for immediate download from the main web site.

Good news, Bad news

The good news is that this is the installment where we finally start to write some code! smile_wink  The bad news is that this installment clocks in at nearly two hours in length (and about 200MB) owing to the wide variety of things that are covered in this one…

  • TDD Concepts and practices
  • Configuring Testdriven.NET keybindings in Visual Studio for speedy test-runs for easy TDD
  • Iteration and Release Planning in TargetProcess
  • Using the TargetProcess Visual Studio plug-in to manage assigned work
  • Getting our CI Server to run our first unit tests
  • Wiring up our Domain Classes for easy persistence support using common base-classes
  • Leveraging NHibernate mapping files to drive the auto-generation of our database schema

>whew!<

I Promise: Sensible length in the future!

Subsequent installments should be a bit more sensible in length; this one got a bit out of control because of all the ‘foundational’ concepts that needed to be put together to support the development of our first User Story.  Now that this is all behind us, subsequent installments can (hopefully!) be a bit more focused and of a more reasonable length (1.5 hours is my practical target goal).

Schedules and Burn-Down Rates

More good news is that the pace at which I am blowing through the tasks in the User Stories is faster than expected.  In the two hours that I spent for this Part A of the first iteration I completed about 50% of the first user story that was estimated at 9 hours in effort.  That’s a burn-down rate of 2.25x the original estimate (9 hrs X 50% complete / 2 hrs spent = 2.25).  If I can maintain that burn-down pace against the backlog throughout the entire project then its at least conceivable that I could complete even the user stories flagged as ‘nice-to-have’ by the end of the series.

But experience has taught me that the burn-down rate in a single iteration (and especially that of just half of the first iteration) is a terrible predictor of maintainable burn-down throughout an entire project, so I’m happy but cautious at this point based on present rate-of-completion of User Stories.  I may be off to a good start, but I don’t have near-enough data upon which to base a positive projection for the life of the project yet.

Coming Next: Rhino.Commons and ASP.NET MVC

In our next installment we will dive into the Rhino.Commons framework and begin to understand how it grants us power over the unruly nuisances of an NHibernate implementation for data-access and will stub out our first user interface page using the ASP.NET MVC framework as we try to complete our first user story.

As always, comments, feedback, and (constructive) criticism are welcome.  Happy viewing~!

04 Nov

Primer notes for Autumn of Agile: Iteration 1 - Part A

Like clockwork, the leaves fall from the trees and the next installment of the Autumn of Agile screencast must come as well.  Next week’s installment will bring us our first actual coding (at last smile_wink ) and introduce us to the principles of Test-Driven Development (TDD), one of the core practices that goes to the heart of enabling an effective Agile Software Development process (IMHO).

For those interested in a few resources to help you bone-up on your understanding of TDD in advance of the next screencast, here are some resources on test-driven-development to take a look at…

Happy reading and I hope you stick around for the next installment in the series~!

03 Nov

Autumn of Agile: Iteration 0 Part B screencast is available

The next installment of the Autumn of Agile screencast series is available now for immediate download from the Autumn of Agile website.

Estimating Our User Stories

In this installment we wrap up our estimates on our User Stories, organize our like Stories into Features, and flesh out some of the actual tasks that we will need to perform to deliver the User Stories’ business value in the system.  We also take a realistic look at the amount of effort that our estimates are starting to suggest will be required to deliver the project and start to evaluate our ‘must-have’ User Stories against our ‘nice-to-have’ User Stories.

Creating our Development Environment

We then take some time to setup our project work folders in our source control repository and also work through the configuration of our CruiseControl.NET continuous integration server to begin to familiarize ourselves with some of the infrastructure items upon which we are going to rely during the life of our project.  We build only the most simple integration steps into the CI server at this point since we don’t need anything more complicated yet, with the expectation that we will enhance the capabilities of our CI server as our own software solution increases in complexity as well.

Still no Code smile_sad

Sadly, by the end of this installment we still haven’t written any code, but that’s the whole point of Iteration 0 (which this installment now brings to a close) — providing us the breathing room we need to setup enough of our infrastructure to help ensure the execution of the project is a success when Iteration 1 (and coding) starts next week~!

As always, feedback, constructive criticism, and other input is welcome.  Happy viewing.

31 Oct

CodeRush Xpress (completely free) is Announced

If you followed the Summer of NHibernate screencast series then you know that I use CodeRush and RefactorPro from DevExpress as Visual Studio add-ins to help supercharge my development experience (yes, I know that Resharper gets all the publicity, but I happen to prefer the CodeRush + RefactorPro approach to solving my extensibility needs, so there!).

If you read this post about the entire collection of VS add-ins upon which I routinely depend, then you also know that I make use of several open-source extensions to the DXCore VS extensibility framework that is the underlying abstraction layer atop which the other DevExpress VS add-ins sit.

If you took a look at the RefactorPro and CodeRush features and said both “I’d really like to use these tools in my own work” and also “but I cannot afford the $250 for the CodeRush + RefactorPro package or even the $99 for the RefactorPro-only license”, then I have a few things to say to you:

  1. How damned cheap are you (or your company) –?  Surely you can find a mere $250 to increase your productivity several-fold~! smile_embaressed
  2. On a more serious note, what I really want to say is ‘your wait is over!’

At PDC in Los Angeles this week, DevExpress and Microsoft have announced a joint-product offering that delivers many of the core and most-frequently-used CodeRush and RefactorPro features for Visual Studio 2008 for 100% free download.

Introducing CodeRush Xpress

The new CodeRush Xpress product offers a very useful subset of the more advanced CodeRush + RefactorPro capabilities.  Following is the list of refactorings that the Xpress product offers for 100% free….

  • Add Block Delimiters
  • Combine Conditionals
  • Compress to Lambda Expression
  • Compress to Ternary Expression
  • Convert to Auto-implemented Property
  • Convert to Initializer
  • Create Backing Store
  • Decompose Initializer
  • Decompose Parameter
  • Expand Lambda Expression
  • Expand Ternary Expression
  • Extract Method
  • Flatten Conditional
  • Inline Delegate
  • Inline Temp
  • Introduce Local
  • Make Explicit
  • Make Implicit
  • Move Type to File
  • Name Anonymous Method
  • Name Anonymous Type
  • Reverse Conditional
  • Split Conditional
  • Use String.Format
  • Use StringBuilder
  • In addition, several of the more valuable and frequently-used CodeRush code navigation, editing, highlighting, etc. features are provided…

  • Duplicate Line
  • Highlight All References
  • Increase or Reduce Selection
  • Smart Clipboard Operations
  • Generate from Using (TDD)
  • Quick Navigation Window
  • Quick File Navigation
  • If you combine the features in CodeRush Xpress with those available in the already long-since free Refactor! for ASP.NET offering, you can get yourself perhaps most of the most commonly-used features in the full CodeRush + RefactorPro products completely for free.

    For a better sense of what the Xpress product offers, read the MSDN Introduction to CodeRush Xpress article that includes many screenshots and walkthroughs of how the product integrates into Visual Studio 2008.  There is also some exposure to the new product demonstrated in the session from PDC entitled ‘Microsoft Visual C# IDE Tips and Tricks’ the video of which you can download here (warning, this link leads to a hi-res wmv file that’s over 300MB so make sure you want to follow it before you click smile_teeth ).

    Please buy the real products!

    For the record, I’m not suggesting that you use the Codeush Xpress tools in place of the full CodeRush + RefactorPro products; each of the full products offers a wealth of additional capabilities that are still well-worth the investment (and I’m sure that DevExpress is offering the CodeRush Xpress products integrated into VS for free in the hopes that you will want to update yourself to the full products at some point in the future), but for the budget-conscious that want access to many of the more-frequently used CodeRush + RefactorPro capabilities at no cost, the combination of CodeRush Xpress + the already free Refactor for ASP.NET download gets you where you need to go for absolutely zero cost.

    Enjoy~!

    PS: I make no money off of any sales that DevExpress makes, I have no relationship with them (other than my being a satisfied customer), and I receive no remuneration in exchange for this or any other recommendation — I just like to see people with great products be successful.

    27 Oct

    Autumn of Agile: Iteration 0 Part A Screencast is Available

    Effective immediately the next installment of the Autumn Of Agile screencast series is now available for download directly from the site.

    In this installment we start to dig into the requirements for our project, flesh out the context for our solution and try to frame our approach in terms of the business problems it will solve and the business value that it will (hopefully) deliver.  We also talk a bit about the relationship between User Stories, Features, and Tasks and learn some techniques common to organizing our requirements in preparation for actual work-item planning.

    We also use Freemind to brainstorm and organize our thoughts about requirements and then take a look at how we convert each of these into User Stories and then enter these into TargetProcess, our Agile project management and planning tool of choice.

    What’s Iteration 0?????

    This installment is tagged as Iteration 0 because it comes before we actually start the coding effort on our project.  Iteration 0 is a common way in Agile planning to ensure that much of the groundwork is properly laid before our project gets started (or more accurately, before the coding on our project gets started).  Its numbered zero because it precedes any of the ‘real’ iterations in our planning and is typically used to setup the development environment and necessary infrastructure, form the team, and organize a decent understanding of the problem domain and the solution requirements.

    What’s Part A?????

    This installment is also tagged as Part A because I’m imagining that each Iteration is going to be 2-weeks in length with one screencast per week (making for a screencast at the mid-point of each iteration and then another at the conclusion of each iteration).  The installment at the mid-point will be Part A and the complementary one at each iteration’s-end will be Part B.

    In a real project, I personally prefer to shoot for a one-week iteration schedule, but since I cannot work on this project full-time each week (and in fact am the only one on the team and working entirely in my spare time), a one-week iteration is just too short a time to produce any actual useful work and so I’m going to plan around a 2-week iteration.  We’ll have to all see how that goes. smile_sarcastic

    For the record, IMHO a 1-week iteration plan is something that only an experienced Agile team should ever try to to execute; for the newbie Agilists a 1-week iteration schedule is just too aggressive and leads to continuous panic rather than continuous effective effort in my experience.  I’m shooting for a 2-week iteration myself purely because of my level of committment/free time.

    As always, comments, feedback, (constructive) criticism are all appreciated~!

    24 Oct

    Primer notes for Autumn of Agile: Iteration 0 - Part A

    Several suggestions were offered to me by readers when I was trying to decide how best to structure the Autumn of Agile screencast series.  One of the challenges of this screencast series is that unlike the previous Summer of NHibernate series that focuses on just a single technology for its entire length, the Autumn of Agile series is designed to showcase multiple technologies and practices all at once (or at least in a logical self-reinforcing sequence).  As such, there is not going to be the same opportunity to dig as deeply into each technology and practice as might be needed to form a complete learn-from-zero training experience.

    One of the suggestions I received was for me to provide some reference material (or at least links to other people’s materials smile_tongue) on the topics that were to be covered in the immediately to-be-released session.  This would allow viewers to do some up front research on the topics and issues covered in the screencasts so that the screencast itself wouldn’t have to be 100% detailed on every how-to point on every concept/topic/technology that was demonstrated.

    Reference Materials

    So without further ado, here is the list of reference links for the upcoming screencast, Autumn of Agile: Iteration 0 - Part A.

    Feel free to bone up on the the concepts in the above links before the next screencast installment is released.  I hope this helps and I’d be interested in feedback about whether people feel this part of the process is of value or if I’m just wasting my time with this.

    © 2008 Unhandled Exceptions | Entries (RSS) and Comments (RSS)

    GPS Reviews and news from GPS Gazettewordpress logo