I'm on vacation and am sitting in a coffee shop catching up on some blogs.  Sergio Pereira posted the other day his praises of the new crop of .NET screencasts.  His post explicitly calls out Steve Bohlen and his Summer of NHibernate series.  I wanted to echo Sergio's sentiments about the .NET screencasts and in particular Steve's new series.  I have used the quiet evening in the cabin to watch the excellent videos that Steve Bohlen has put out.  The quality of the videos both in production and content are unsurpassed.  I've used NHibernate before but this is a much better primer than reading a few blog posts/tutorials here and there when a roadblock is hit.

If you've not seen these videos yet and are looking for a good introduction to NHibernate, check out the Summer of NHibernate series.  When you do, make sure you donate (at least a dollar).


 
Categories: .NET | Open Source Software | ORM

This is the third in an ongoing series of articles about my team's transition to the Asp.NET MVC Framework.  In my last post I blogged a bit about how I haven't quite got comfortable enough with the new MVC framework to feel über productive.  What augments the feeling is the difficulty of finding quality information.  The data is few and far between and only sometimes relevant.

I was struggling yesterday to find information on the ComponentController class.  Things I was finding were from the Preview 2 release but finding something on the Preview 3 release was a bit more challenging.  Things are rapidly changing in the framework and the MVC team is not afraid to refactor, rename , or even remove a class.  For example, with the release last night, ComponentController is no longer a worry of mine because it's now gone, removed completely from the framework. 

The MVC framework has been around for under a year (Nov 2007 I believe).  It is now in it's fourth iteration (Preview four, released last night).  While a number of people have downloaded and are using the framework the amount of data/tutorials/blogs/articles pales in comparison to the same information about web forms.  This makes finding the info you need much much tougher.  It's exciting though and must say I enjoy the challenge.  The change in releases doesn't bother me.  It's a bit of a nuisance but I signed up for this trip.  Also the changes are for the better.  The ComponentController class that was replaced yesterday was not easily testable.  The MVC team removed it in favor of the Controller class, which is testable!  Fundamentally it boils down to the fact that I trust the guys on the MVC team and where they're going with the framework.

That trust doesn't help me day to day in moving my project forward though.  In order to find the data I need I've had to be both resourceful and thorough in my reading.  The trick I've found is following a few bloggers closely and reading all of their posts regarding MVC and all comments made to the posts (that's where I find the real gems, in the comments).

Here is a list of bloggers I'm following, obviously some are well-known, others are not.  If you follow some bloggers who post about the MVC framework that aren't on my list please share!! My list:

Updated to add new blogs (7/23/2008) ... thanks Ben

Yesterday I reported that I was learning to walk and while I can't quite say I'm walking yet,  I'm feeling a bit more comfortable.  My velocity increased ever so slightly today and I'm encouraged by that and excited for tomorrow!  And to be quite honest that's a perfectly find place to be.


 
Categories: .NET | MVC

A few days ago I posted that our team was making the transition from webforms to MVC.  Since then a few days have gone by and I wanted to post my some struggles and successes (however few) in recent days.

First, it's been tough wrapping my head around the shift from web forms to MVC.  I would caution anyone making a similar shift or considering it, that despite the recognized short comings of web forms and the postback model that one should approach the change expecting a bit of a rough going in the beginning.  Never underestimate what years of articles, blogs, and webcasts about web forms and working in web forms will do to your perspective.  OnClick...gone.  PreRender...gone.

Does the experience thus far cause me to regret the choice to go MVC route?  Absolutely not.  It was 100% the correct decision.  Despite the difficulties of making the shift, there are points where something clicks and it feels better and more natural.  I'm waiting for that shift and those clicks to be more permanent.  The best analogy I can use to explain it is likening the experience to my one year old son who is learning to walk. To him crawling feels right.  When crawling, he's quicker, self-assured, and can generally get where he wants to go.  When he attempts to walk however, he falls down, he struggles to keep his balance, and generally getting anywhere takes longer.  It's temporary though, we know it and that's why we encourage him to walk and push through the awkwardness. In a few years Lincoln will realize (if not verbally but by the way he chooses to move) how much more natural walking is than crawling, a fact that I'm reminded of every time I get down on all fours with Lincoln.

So what am I doing to push through?  First I'm trying to keep in the project.  With smaller tasks and projects always requiring attention, I'm trying to stay in the project as much as possible.  Secondly, I'm thinking about how I think (Metacognition).  Thinking about MVC, testability, loose coupling and other such principles only aid in the transition.  I'm hoping the next two days this week give way to breakthroughs.  Near the end of the day I had some small wins and started to gain some velocity which leaves me optimistic for tomorrow.


 
Categories: .NET | MVC

We recently decided that with the effort we're putting into our website and some changes that we're making that now would be as good of time as ever to make the switch to the new Asp.net MVC Framework.  We're no Google, but we're currently receiving around 18,000 unique visitors a day and 300,000 page views and hope to grow that number as we make our site easier to use for our customers.  I hope to rely heavily on Phil, Rob, and Scott for assistance if needed. 

The MVC design appeals to us because the large amount of business logic that has crept it's way into the codebehind.  Despite the best intentions, the current site, which is programmed in asp.net 1.1, has had too much logic to creep into presentational areas while running with webforms.  The biggest drawback to this is reduced testability.  Testability should be important in any project but for us it is paramount. We have business rules that if not adhered to amount to real-world fines:

A few years ago a customer bought some lubricant that is sold in an aerosol can.  Since 9/11 aerosol cans cannot be shipped as cargo on airplanes.  Somehow this order made it though the checks we have for this type of thing in the warehouse and made it onto the UPS truck.  At the UPS facility, a UPS employee heard something emanating from a box that sounded like an aerosol can.  At that point he is required by law to check the contents.  When he opened the box he found the aerosol cans.  Despite knowing us and our reputation, he was required to call the FAA and say something to the effect of, "I found some aerosol cans in a package that was scheduled to be flown."  It didn't matter that this was an accident or "just a few cans", we were still fined.  We were warned that if this were to happen again that we would face a fine somewhere in the low six figures. The FAA doesn't mess around.

As we go forward I plan to document on this blog the highs and lows of our transition.  I'll post questions and problems we're having that I hope you can help with as well as tips and tricks our team has found helpful.  Stay tuned as we make the transition.


 
Categories: .NET | MVC | Software

A coworker ran across the following and shared with me.

   1: Dim strpage
   2: strpage = pageNumber.ToString()
   3: If Len(strpage) = 1 Then
   4:     strpage = "000" & strpage
   5: ElseIf Len(strpage) = 2 Then
   6:     strpage = "00" & strpage
   7: ElseIf Len(strpage) = 3 Then
   8:     strpage = "0" & strpage
   9: End If 

The programmer is trying to ensure that the page number, when printed out, is always four characters long.  This is not the best way to write this code.  I thought I'd keep this post to myself but unfortunately this isn't the first time I've seen code like this, it is quite common.

The better way to write the above is:

   1: Dim strpage
   2: strpage = pagenumber.ToString("0000")

It's shorter, more concise, and easier to read.  Further the second example is more extensible.  If the requirements change to say the page number should be five characters, the first example must recompile.  The second example must be recompiled as well in it's current state, however the string "0000" could be moved to a configuration file somewhere and then wouldn't need to be.


 
Categories: .NET | Programming

June 17, 2008
@ 03:05 PM

Compare the following two error messages and think about which you would find more helpful.  Then, the next time you are throwing exceptions with messages remember this post.

Error Message from Castle's Windsor IoC libraries:

Can't create component 'ProductService' as it has dependencies to be satisfied.

ProductService is waiting for the following dependencies:

Services:
- JPCycles.Framework.Services.IInventoryService which was registered but is also waiting for dependencies.

ControllerInventory is waiting for the following dependencies:

Services:
- JPCycles.Controller.IInventoryRequestInterpreter which was not registered.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Castle.MicroKernel.Handlers.HandlerException: Can't create component 'ProductService' as it has dependencies to be satisfied.

ProductService is waiting for the following dependencies:

Services:
- JPCycles.Framework.Services.IInventoryService which was registered but is also waiting for dependencies.

ControllerInventory is waiting for the following dependencies:

Services:
- JPCycles.Controller.IInventoryRequestInterpreter which was not registered.

Error Message from .NET framework:

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

 
Categories: .NET | Programming | Software

"But you have the source!"

I heard that statement a little over a month ago at the Alt.Net Open Spaces event in Seattle.  It's no secret to those who know the community, that open source technologies are at the very least promoted and in many cases you'll find many open source project committers within the Alt.Net community.  Heck, David Laribee, a founding member if there is such a thing, in a post defined Alt.Net as (emphasis mine):

  1. You’re the type of developer who uses what works while keeping an eye out for a better way.
  2. You reach outside the mainstream to adopt the best of any community: Open Source, Agile, Java, Ruby, etc.
  3. You’re not content with the status quo. Things can always be better expressed, more elegant and simple, more mutable, higher quality, etc.
  4. You know tools are great, but they only take you so far. It’s the principles and knowledge that really matter. The best tools are those that embed the knowledge and encourage the principles (e.g. Resharper.)

The quote, and many like it, came in a session titled "Mature Open Source projects versus first generation Microsoft projects".  The discussion centered around why some (many) developers, managers, and executives feel comfortable choosing a brand-new Microsoft product when a far more mature open source alternative exists.  One the fears surrounding the adoption of open source is the lack of surety that open source project will exist in perpetuity.  One needs to look no further than two projects, NVelocity and NDoc, to find historical evidence of an open source project vanishing.  The main counter-point to that argument, and many others, was the quote above, that with open source, you were never truly left high-and-dry, since you had the source.

It's a noble thought, but really, who wants to manage another codebase in addition to their own?  In fact I turn to open source project many times so I don't have to write my own code.  Why re-invent what someone else has already done and guided to maturity?  The idea that I can compile and manage another, possibly large, and probably complex codebase is hardly a comfort to me.  It wasn't until a few weeks ago that I realize that the open source pundits were correct.

I have been working on a project for the last year that has, as of two versions ago, started using Watin to automate the downloading of a file from the internet.  Watin is a testing framework but is used by many to automate business processes, which is what I use it for.  If you haven't checked it out yet, it's beautifully simple.

Watin provides handlers to download a file, however, the code was hanging at the point where it should've cleared the download.  I looked at every documentation page, blog post, and blog comment I could to see if I was missing something.  My usage was correct.  So I dug in a bit further using WinDowse to find the handle of the button that should be clicked.  As it turns out the handle of the Save button in a FileDownload Dialog changed from 4424 to 4427 in IE7, who would've guessed it right?  Well, since I had the source I went in and made the change, and voila, I'm back in business.

It gave me some confidence that if an open source project does cease, I can pick it up and patch it up.  I still don't want to manage multiple codebases from many different source, but in the end the pro open-source guys were right, "You have the source!"


 
Categories: .NET | ALT.NET | Musings | Open Source Software | Software

Yesterday I attended the first ever Iowa Code Camp in Iowa City, Iowa.  This was the first code camp I had ever attended and that fact withstanding, I don't know how the event could have gone any better, it was absolutely flawless.  There were well over 125 attendees and waiting list to boot.

I attended sessions on Java/Hibernate, Inversion of Control, Mocking and .NET Performance Tuning. I enjoyed Derik Whittaker's talk on mocking as it's something I've been into for the last few months.

Talking to other attendees it was very obvious that others enjoyed themselves as well.  The feeling was that the materials presented were things we can take into work tomorrow.  And that is what a code camp is all about.

Thanks to Chris, Javier, Greg S. Greg W and the many others who helped make yesterday a success, you guys set up a wonderful event!


 
Categories: .NET | Ineta

April 19, 2008
@ 11:04 AM

From the moment we got here it's been so absolutely incredible.  We (Chris Sutton and I) arrived in Seattle about 11:00 and met up in our hotel lobby with a few guys and went off to lunch.  The subject of mocking came up and got into an interesting debate with the guys about mocking, among which was Roy Osherove.

I'm generally a nobody, but that's not how it feels here, everyone comes here to learn from others, so it actually tends to be a great group of developers.  Yesterday afternoon I was chatting with Udi Dahan, Greg Young, Drew Sellers, and Evan Hoff about event driven design.  I'm amazed that when surrounded by many celebreties in our community that they are really just like us (Roy O is the most down to earth guy).

The open spaces format is interesting, people get up and say what they want to talk about and then we figure out what will be talked about.  Some topics from Friday evening were mocking, agile scaling with teams, distributed design, and javascript testing, just to name a few.

A highlight was talking in a small group with Martin Fowler and Scott Hanselman about languages and the importance of finding good code to learn from.

All in all, I'm so far impressed and the conference really hasn't begun.  From the time people showed the conference began, despite it not officially beginning until 6:00 last night.  After the conference everyone went out to eat and this morning people are gathering for breakfast.

Ultimately one cool group of people that I'm proud to be a part of.

 


 
Categories: .NET | ALT.NET

March 10, 2008
@ 10:51 AM

The new Resharper seems to favor the "var" keyword and I don't understand why.  Is it some performance benefit?  To me, if you know the type, then write it as such.  Consider the following:

Person p = new Person("Tim", "Barcz");

Resharper doesn't like this and suggests the following:

var p = new Person("Tim", "Barcz");

Why?  Just because you can do something, I don't think you should.  Maybe my brain hasn't shifted back to a var world yet, but the second snippet is less readable than the first.  To me it's a case of Don't Make Me Think.  With "var", I now have to stop and think, even for a second, what type is being returned.


 
Categories: .NET | Musings | Software

imageI've thought about writing this post several times over the past two years.  Having had regular expressions come up three times last week, I thought it time to address the lack of programmers out there who understand regular expressions.  The sheer amount of fear surrounding regular expressions and the work that goes into avoiding them is astonishing.

Last year I used to troll around the asp.net forums and quite frequently I would answer the regex questions.  One question was posted which illustrates the problem with regexes among developers.

"...and i also i need to add a validator for the password textbox where the user is required to fill atleast [sic] 6 characters"

I suggested a solution to the problem using a regular expression validator. Making sure there are at least 6 characters, is a simple regex (example: \w{6,}), and yet my solution was met with skepticism.  The following was said, in the event a change was requested,

"Putting a new version of a web site can take a surprising amount of time than can go into man-weeks". 

Man-weeks?!?!?  To change a regular expression?!?!?  I see two problems, first the original developer who didn't know that regex would easily solve their problem.  The second problem is the other developer who doesn't know regex advocating his way as "the way", in effect, spreading his ignorance.  The first developer is easily forgiven, the second is not.

It's been said programmers can't program when faced with a simple FizzBuzz test, Imran states:

"Want to know something scary? - the majority of comp sci graduates can’t. I’ve also seen self-proclaimed senior programmers take more than 10-15 minutes to write a solution."

I'll pile on.  You want to know something scary?  The majority of professional programmers can't write regular expressions, even simple ones.  I'm not the first to say this.  Last year, at the ALT.NET conference, Scott Guthrie made the following statement when talking about routes in the new MVC framework:

"It's pluggable, so you can use Regexes...<some incoherent stuff>...if you wanna use regexes you can.  What we found is, regexes are super powerful, but only about 10% of people actually understand 'em."

Are regular expressions easy to understand? Well, let me ask you, was HTML easy when you started?  Were you born understanding the following HTML?

<fieldset class="CheckRadio">
    <div id="OngoingEventContainer">
        <input type="checkbox" id="OngoingEvent" name="OngoingEvent" value="1" />
        <label for="OngoingEvent">
            This is an ongoing event (no dates and times)
        </label>
    </div>
</fieldset>

If you understand the above, you didn't always.  My guess is that at some point you buckled down and learned HTML because you're job requires it.  Well, if you're a programmer, web or windows, you need to know regular expressions, your job requires it, it's that simple. 

imageRegular expressions have been around so long that they're deeply ingrained in many of the tools we use.  Christopher Bennage illustrates how regular expressions solved a recent problems in Visual Studio.  In a recent post he posts:

"Then I realized that I was missing the simple solution. Ctrl+F and a regular expression!"

I don't know that many people would be able to come to the conclusion that Christoper did.  It's my belief that regular expressions are fundamental, yet the average developer doesn't treat them as such.  They're ultimately doing themselves a disservice.

Regular Expressions are a tool that should be in every programmers bag.  If you don't understand regular expressions and do a google search every time you need a regular expression, shame on you!  It's time to bite the bullet and learn regular expressions.


 
Categories: .NET | Musings | Software

After a snowy weekend being stuck in Minnesota I was greeted by an email in my inbox saying that I was registered for the 2008 ALT.NET Open Spaces, Seattle conference.  Last year the Alt.NET generated a lot of post-conference buzz and was where the .NET MVC Framework was announced by Scott Guthrie.

After looking at the list of participants I'm gushing with enthusiasm.  I feel like a 14 year old freshman who was just asked to the homecoming dance by the homecoming queen.  For the sports enthusiast, I feel like Jason Kapono at the NBA All-Star game.  Kapono won the three point shootout, but many of you are probably asking yourselves, "who is Jason Kapono?"  Kapono, and his three-point skill, was overshadowed by the All-Star game itself and all of the NBA talent on the floor at one time.  I am Jason Kapono.  I must admit I have borderline unhealthy geek-love-man-crush on some of the attendees (listed in no particular order):

Sure, these guy go to conferences and it's not rare that they're in the same place.  What is rare, is that they're all together and there are only 150 participants.  That means the geek-expert to journeyman ratio is going to be quite high.  In other words, they can't avoid me.

Martin, will you autograph my POEA book?


 
Categories: .NET