Speaking at the Austin Code Camp, May 5th, 2007 – level 200

This is the second Austin Code Camp, organized by the Austin .net user group : www.adnug.org.  Get more information on the code camp here: http://www.adnug.org/codecamp2007.aspx

I will be giving a talk on 1 topic, but it will be separated into two parts because of the amount of material to cover.

Fundamentals of modern programming

Join C# MVP Jeffrey Palermo for a talk that gets back to the basics of programming with .Net in the 21st century. This talk will not venture into Test-Driven Development, Domain-Driven Design, O/R Mapping or other recent advances in programming. Instead, I’ll focus on fundamentals that few colleges or training courses are equipped to cover. Some fundamentals include the actual differences between procedural programs, object-oriented programs as well as how to leverage both for service-oriented programs. Code presented herein will be basic and geared toward illustrating specific fundamentals. An example presented will be what a class should look like and how to decide when to create a class. If you feel a bit rusty on your fundamentals or if you’d just like a refresher course, this talk is for you. (Level 200)

 

In my career, I’ve found that many programmer focus on certain technologies and become very skilled in them, but the foundation of programming knowledge is lacking.  Granted, many of us may get along these days without having to write a compiler from scratch, but there is plenty of knowledge missing from the common base of programmer knowledge.  My talk will not cover net glitzy technology.  Instead, it will cover more foundational knowledge and extensively reference well-known works and software studies.

My goal is that those who attend my talk will leave with a better understanding for how to go about constructing software.

22 hours of podcasts – 3 nuggets to share – level 200

This weekend I was a groomsman at Kevin Dulaney’s (great friend from grade school) wedding in Missouri.  I drove from Austin, TX on Friday and returned Sunday.  11-hour drive each way.  I stocked up my Windows Mobile phone with podcasts and listened the whole way there and back.  For those who ask “why would you do that”?  It’s my study time.  Constant learning.  I get to attend virtual lectures by industry experts.  Invaluable.

There are three things that I MUST follow up on:

  • CI Factory
    • This is a configuration management tool that does the basics of integrating CruiseControl, automated testing, NAnt, MSBuild and other build-related things.
  • Windows 2009 (http://www.pcworld.com/article/id,128888-c,vistalonghorn/article.html)
    • So far Vista isn’t the smashing hit many hoped it would be.  I’m currently running XP on my home machines, XP on one work machine and Vista Business on my main work desktop machine (no issues so far).  I’m curious to see what changes will be in Windows in less than 2 years!
  • Windows Developer Powertools: http://www.amazon.com/exec/obidos/ASIN/0596527543/infozerk-20
    • From James Avery and Jim Holmes, this book covers so many tools and frameworks including many open-source ones I use on a daily basis.  This book reaches out and brings to light that there are many, many great things out there that are not from Microsoft but aid in Microsoft development.

I’m still 3 weeks behind on my podcast list!!!! Arg!

Plan on catching my Birds of a Feather sessions at Tech Ed – level 200

My two BoF’s have been accepted for Tech Ed.  Plan on attending if you are interested.

“Agile development with .Net”

“Techniques for writing less code (frameworks, libraries, and tools)”

The selections were determined from votes from Tech Ed attendees.  It’s encouraging that many others are interested in these topics.

Results of a SOLID pair-programming day – level 200

There it is.  A pile of ripped up note cards denoting all the engineering tasks completed by my pair.  This was an unusual day because it started at 7:30am with some white board modeling and brain-crunching a very, very tough problem.  We wrote out some tasks to get us started, and we played the TDD game.   It was such a tough problem that neither my pair partner nor I could imagine the complete solution, but we could imagine a few things that would be included.  We wrote down the items to do on note cards and ordered them.  The navigator manned the note card deck.  In the course of completing some of the engineering tasks (all part of the same story), we uncovered new tasks that needed to be done.  We wrote those down and added them to the bottom of the pile.  We also ran into a brick wall and had to stop to do another task before we could continue.  We wrote that down and added it to the TOP of the stack.  We used these note cards as a true STACK.  FILO.  It helped us stay on track.  We finally got through the stack, and when we did, the story was implemented.  We didn't have the complete plan at the beginning, but we adapted and changed the plan along the way.

This pile of ripped up note cards is all that's left of that nasty story.  It did take us all day, though, and at 6PM, we both were wiped out!  It was the last day of the iteration, and we had committed to the story.  We ate a quick lunch at our desks and worked straight through.  It was great that we were able to meet our iteration through micro-adaptive planning.

I hope I don't have to do that again for a long time because that was the most difficult pair-programming I have ever done.  We were talking through the problems _all day_.  My brain was hurting on the way home.

My pair partner commented that it would have taken him 3 days if he had had to work through this nasty story by himself.  Pairing on the entire solution cut the delivery by 2/3. 

Streamline Model-View-Presenter with new StructureMap feature – level 300

I'm going to present you with a very exciting new feature of StructureMap that is available in the 2.0 release.  You can download StructureMap from SourceForge.

There are plenty of articles about StructureMap's service location capabilities, and the documentation is quite good, but I'll throw out the bread-and-butter usage scenario for service location.  Here is is.

I have an ICustomerRepository, and an "impl" class that implements the interface, CustomerRepository.  As the names suggest, this interface will return an array of Customer(s) given a whole or partial phone number.  Here is the full code.

    1 using StructureMap;

    2 

    3 [PluginFamily("Default")]

    4 public interface ICustomerRepository

    5 {

    6     Customer[] GetCustomersByPartialPhoneNumber(string phoneNumberOrPartial);

    7 }

    8 

    9 [Pluggable("Default")]

   10 public class CustomerRepository : ICustomerRepository

   11 {

   12     public Customer[] GetCustomersByPartialPhoneNumber(string phoneNumberOrPartial)

   13     {

   14         //do the right thing to find the customers;

   15         return null;

   16     }

   17 }

   18 

   19 public class Customer

   20 {

   21     private string _name;

   22     private string _phoneNumber;

   23 

   24     public Customer(string name, string phoneNumber)

   25     {

   26         _name = name;

   27         _phoneNumber = phoneNumber;

   28     }

   29 

   30     public string Name

   31     {

   32         get { return _name; }

   33         set { _name = value; }

   34     }

   35 

   36     public string PhoneNumber

   37     {

   38         get { return _phoneNumber; }

   39         set { _phoneNumber = value; }

   40     }

   41 }

In another place, I want to make use of the ICustomerRepository interface, so all I need are the following lines:

   49 //imagine this method were real.

   50 ICustomerRepository repository = ObjectFactory.GetInstance<ICustomerRepository>();

   51 Customer[] customers = repository.GetCustomersByPartialPhoneNumber("555-5555");

   52 return customers;

Of course, when my application starts, I'll put these lines to ensure it will work (or I could use a StructureMap.config file).

   47 StructureMapConfiguration.UseDefaultStructureMapConfigFile = false;

   48 StructureMapConfiguration.ScanAssemblies().IncludeTheCallingAssembly();

Now that you get the gist of it, I'm going to use StructureMap to enable the Model-View-Presenter pattern in a cleaner way with ASP.NET UserControls.  First consider the following usage:

I have a page that has a complicated piece which has been delegated to a usercontrol-presenter pair.  The page, of course, will embed this usercontrol in the appropriate place.  Immediately you can spot the problem:  The "Foo" view is responsible for creating the "Widget" view.  Then the Widget view creates its presenter and uses it.  This is too much responsibility for both views. 

Now consider an alternative:
 

Now notice that the FooPresenter is responsible for creating and using WidgetPresenter.  WidgetPresenter, in return, uses StructureMap to service-locate its view, which implements IWidgetView.  Because Widget.ascx.cs implements IWidgetView, this wiring works easily.  The StructureMap change that made this possible is the following usage of the configuration.  Here is the code:

   58 public interface IWidgetView

   59 {

   60     void ShowWidget(RedWidget theRedWidget);

   61 }

   62 

   63 public class RedWidget

   64 {

   65 }

 And the usercontrol that is the view:

    5 public partial class Widget : UserControl, IWidgetView

    6 {

    7     protected void Page_Load(object sender, EventArgs e)

    8     {

    9     }

   10 

   11     public void ShowWidget(RedWidget theRedWidget)

   12     {

   13         HttpContext.Current.Response.Write("Red widget shown");

   14     }

   15 }

 And the configuration that makes this possible:

   66     void Application_Start(object sender, EventArgs e)

   67     {

   68         StructureMapConfiguration.UseDefaultStructureMapConfigFile = false;

   69         StructureMapConfiguration.ScanAssemblies().IncludeTheCallingAssembly();

   70         StructureMapConfiguration.BuildInstancesOf<IWidgetView>().TheDefaultIs(

                        Registry.LoadUserControlFrom<IWidgetView>("Widget.ascx"));

   71     }

 Now that we can service-locate asp.net usercontrols, we can inject them as well.  The next step is having the WidgetPresenter receive IWidgetView in the constructor.  StructureMap will chain-create the usercontrol in order to create WidgetPresenter.  Now, our presenter is in control, and the views can concentrate on presenting information to the user and not worry about control flow.

 

 

Houston, April 17, 2007: Come to my automated testing presentation – level 300

If you will be in Houston on Tuesday, come participate in my presentation. http://www.hal-pc.org/CsharpSIG/

HAL-PC C# SIG

April 2007 Meeting

Date April 17, 2007
Time 7:00 PM
Location HAL-PC Headquarters

4543 Post Oak Place
, Suite 200, Houston, Texas
Topic The Benefits of Developer Testing
Speaker Jeffrey Palermo
Meeting Details This month's speaker is Jeffrey Palermo. Jeffrey is an independent
software consultant with special skills in Scrum, XP, and .NET. He runs
the Austin .NET User Group and is the South Texas INETA Membership
Mentor. He enjoys spending time with his wife Liana, riding his
motorcycle and country dancing. He is a member of Journey Bible
Fellowship where he helps with the youth group ministry. Jeffrey is an
Eagle Scount and graduated from Texas A&M University. He recently
served in the Army in Iraq during Operation Iraqi Freedom.

Topic abstract: Developer testing
includes unit testing, integration testing, and acceptance testing.
Jeffrey will present how to test software in an automated way and how
to design code to be testable. He will provide a special focus on
testing ASP.NET and using mock objects.

   
  To receive email notification of C# SIG announcements, please send a message to 
Harry Nystrom

 

Debugging tip: But that can’t happen!! Ah, but it did. Ensure you are looking at the right object – level 300

Debugging can be easy or hard.  It’s easy if you have an easily reproducible error.  This morning I wrestled a bug where a screen just stopped showing data.  Nothing.  Zilch.

When I debugged through, I watched every piece of data get properly set to labels in my Winforms view that were visible, but the screen shows up without the data!! What gives?

Ultimately, I was looking at the wrong instance of my screen/view. 

Here’s a debugging tip to use if you watch the code executing properly but it still doesn’t work in the end:

Make sure you are looking at the right object.

In the debugger, set a breakpoint in the constructor and ensure you are watching the right instance.  In the immediate window, use the hashcode to track the instance:

this.GetHashCode()
34169857
this.GetHashCode()
61248560

This way, you can clearly identify the object.

Resharper Nant support: more discovery – level 200

I knew that Resharper had Nant and MSBuild support, but I don’t use it that much because once my build scripts are working, I modify them much more seldom than code.  Today, however, I made some modifications, and I happened upon a Nant target that didn’t appear to be used:  Dead code. . . er. . . xml.  With cursor on the target name, I pressed CTRL+ALT+F7 to find usages, and it found none.  I then proceeded to delete the target but in the safest way I know how, with R#’s safe delete, ALT+DEL.  Here is a screenshot.

I continue to discover that the Nant support has so many of the features I rely on for C# work.  Just had to share.

Feedback requested: Proposed Code Camp talk: Fundamentals of modern programming – level 200

On May 5th (Cinco de Mayo, for those of you like me who live in a State that was once a part of Mexico), ADNUG is holding its second Code Camp.  I’ll be giving a talk entitled Fundamentals of modern programming.  Here is the abstract:

Join C# MVP Jeffrey Palermo for a talk that gets back to the basics of programming with .Net in the 21st century.  This talk will not venture into Test-Driven Development, Domain-Driven Design, O/R Mapping or other recent advances in programming.  Instead, I’ll focus on fundamentals that few colleges or training courses are equipped to cover.  Some fundamentals include the actual differences between procedural programs, object-oriented programs as well as how to leverage both for service-oriented programs.  Code presented herein will be basic and geared toward illustrating specific fundamentals.  An example presented will be what a class should look like and how to decide when to create a class.  If you feel a bit rusty on your fundamentals or if you’d just like a refresher course, this talk is for you.

 

Now, a question for you, my handful of readers:  What should my outline look like?  I have a rough one, but I would love to get some feedback on a subtopic that you think should not be missed.  This talk is geared toward the basics of programming for those who already “know” how to program but skimmed over the fundamentals. 

Another way to approach it is to think if you were giving the talk, or if you were in the audience.  What is a topic that absolutely should be covered?  Please leave comments.