Ang3lFir3 – Life as a Code Poet

February 23, 2011

Harmony Hackathon: the beginning of something big?

This story starts somewhere between 7 and 10 mnths ago, when I was talking to my friend @cbilson during a break in a pairing session. We had previously talked about give camps and coding for causes events. This led us to the fact that we both liked the idea but felt it could be more targeted. We had also talked about renting some space from the facility my wife works at for the South Sound .Net Users Group to hold a workshop.

The idea stuck with me, my wife works for a non-profit after all and I had worked for one recently. I talked to my wife about an idea I had brewing. The place she works for just so happens to be one of the premiere Cancer Retreat facilities in the Northwest (if not the world[but don't tell them]). Where is it that she works you ask, Harmony Hill …. just about the most centering place on earth (ok yeah I know I’m REALLY biased).  Anyway back to the story. I bounced the idea of my cohorts including @NotMyself . Every person I brought the idea to thought it would be amazing. So I decided to move forward with what would become Harmony Hackathon.

Harmony Hill agreed to support the group by providing hospitality services and lodging for the entire group while they were on the hill. I can not even begin to tell you how amazing this staff is, for 48 hrs 12 of the finest developers in the northwest didn’t want for anything!

The setup on my part was pretty easy, invite some of the best programmers in the northwest and ask them to do the one thing they love, code!, for charity…. plus I promised them beer! It worked… attendance was limited by the number of beds we had available for people to sleep in. It was only seconds after sending out the first request did I have people signed up to the eventbrite site.

Finally the day arrived to begin the Hackathon and you could say the excitement in the room was palpable. We started with introductions to the projects (we had initially intended to run to two projects) and to the facilities. We then headed down to the first of several amazing meals on The Hill. After dinner is when the real excitement began. We had decided on building the needed registration/waitlist management tool which is centered around available beds at the retreat center. @darkxanthos took the reigns as PM/customer liaison person and began gathering requirements for the developers to start working with. There was a lot of desire to start coding but also a deep understanding amongst the group that we must first understand the problem before we can solve it. A lot of effort went into making sure we focused on breadth and not rabbit holing ourselves on a single problem. Once again Justin did a great job and with the help of Rodica and Aeden a group of requirements was beginning to emerge as a set of mockups.

We began building out the plumbing and infrastructure of the project and decided on a couple of technology choices… MVC 3 and the default Razor view engine that comes with it.

The next 40 some hours of the weekend were a frenzy of coding…. pulling changes and merging changes…. I swear if nothing else our git skills improved. There were times that a person might have to pull again after merging changes from the last commit only to find out that they were still behind master. It was crazy, as a matter of fact you can see for yourself, thanks to a video from @NotMyself showing the gource animation of what happened.

We didn’t exactly finish, but we did cover some really awesome ground and learn a lot about how to manage such a gathering. A couple of the things we learned are kind of obvious but extremely powerful.

1. While it is exciting to see what can be started from nothing, it is a really good idea to be aware of the problem space to get the best results out of the group. Have a small group meet with the product owner at least once before the event date to flush out stories to keep the team working and not waiting. You can do more the day of the event but you need a foundation to work against.

2. Smaller teams truly do work best. Even a team of 12 is too large optimal is about 5-6. We learned that with all the commits and furious amounts of work we couldn’t help but all get in each others way no matter how much we tried not to.

3. You need a dictator. Sometimes the group can not come to a decision about technology (who’da thought a bunch of Alpha geeks couldn’t agree ) so someone has to be able to make a decision and cast that extra vote. I wouldn’t personally say you need to use this power often, only when the group seems to be wasting time arguing over some tech that doesn’t directly solve the problem. I say this because it is extremely important that the group be open to exploring lots of new spaces so that the benefit is not only to the PO but also to the developers.

4. Infrastructure is important. You really need to have the core infrastructure laid out and decided on before you get started. We chose to use ASP.Net MVC because we are mostly all web developers and are familiar with the technology. We also chose NHibernate and StructureMap as we were all familiar with them as well (well maybe not StructureMap but its concepts are universal … see we learned stuff). This meant there was some setup that was needed to get all the plumbing in place. Had this been ready at a cursory level earlier we would have spent less time shaving that particular Yak.

So the ultimate question remains. Will we do it again? The answer is quite simple, OF COURSE !!! The group learned a lot from the experience and the project continues to move forward. As a matter of fact last night while talking with my wife she informed me that they had already started to talk about how the product could help with other programs at Harmony Hill. We have already started to think about how to plan for the next one and how to get the most out of the event.

The ultimate goal…. start something amazing to help out not only this one organization but potentially help out many others. Start a tradition of greatness and see the program grow. Which is good because we might just need that waitlist manager to help out with the future waitlist for Harmony Hackathon 2012.

July 30, 2010

My technology stack

So following in the footsteps of my friend Liam I decided to respond to David Burela’s ‘What is your preferred technology stack?’ question.

By day I am lucky enough to work with the likes of @NotMyself @codingreflection and other great developers as an Enterprise Developer. Our customers are internal and the corporate preference is for .Net solutions. Our organization and management sees the value in letting developers be productive by allowing them to use the tools that best fit the job. I am proud to work with a team of developers that pushes me to improve myself each and every day.

In my day to day life I am just me, a geek with a passion for learning and all things… well… geeky.

quoting Liam I also favor tools that are :

  • are open source. Open source libraries are often designed to facilitate quality practices, not to sell tools. Also, access to the source and the price are bonuses.
  • support the software craftsmanship ideology. Small, sharp tools that stay out of the way and don’t force any design decisions.

My work stack:

web framework => MonoRail, ASP.Net MVC 2+
ui => JQuery w/ plugins, Ext JS
viewEngine => Brail, Spark, ASPX
Testing => MbUnit for unit testing, MSpec for BDD … I tend to do mostly just BDD now
TestRunner => TD.Net
Mocking => RhinoMocks. I’ve tried Moq and really don’t like it compared to Rhino
IoC => Windsor
exceptions => Log4net, we are increasing moving towards including Elmah as well
data access => NHibernate + Fluent NHibernate, SqlServer 2000
build => powershell + psake (make in powershell)
CI => TeamCity
version control =>  Git w/ git-svn
misc => NBuilder, SQLite for inmemory testing of repositories and mappings, FluentMigrator, WIX, FileHelpers, A Common lib of tools and useful bits our team has collected over time

My Personal dream stack:

web framework => ASP.Net MVC2+, RoR, Sinatra
ui => JQuery w/ plugins, Ext Js, Coffee Script
viewEngine => spark, haml
testing => MSpec, RSpec , Cucumber
mocking => RhinoMocks, some ruby mocking framework (lol)
version control => Git
build => rake + albacore where needed
IoC => Ninject
exceptions => Elmah, NLog
datastorage => MongoDb ….. pure awesome… on a stick

August 17, 2009

Updates to Subclass and JoinedSubclass mapping in Fluent nHibernate 1.0 RC

Filed under: .NET, Fluent NHibernate, C#, NHibernate — Tags: , , , , — ang3lfir3 @ 3:20 pm

With the release of Fluent nHibernate 1.0 RC (download here) there are some great changes to the mapping structure of Subclass and JoinedSubclass. This excerpt from the 1.0 RC release notes gives a highlight of what those changes are and what is expected of us:

Separated subclass mapping – Subclasses can (and should be) defined separately from their parent mapping. Use SubclassMap<T> the same way as you would ClassMap<T>; if the top-most mapping (ClassMap) contains a DiscriminateSubclassesOnColumn call, the subclasses will be mapped as table-per-class-hierarchy, otherwise (by default) they’ll be mapped as table-per-subclass.

Okay so now we have quite a bit of info, but what does it all mean for the code. For those of you who just want to see the new mappings… I’ve got that for you. Using the same samples that I used in Table Per Class Hierarchy Inheritance Mapping with Fluent nHibernate and Table Per Subclass Inheritance Mapping with Fluent nHibernate I will show you the changes. Which are pretty simple and vary only slightly between the two approaches. This allows you to change mapping styles very quickly and flexibly.

 

The Mappings:

The Mappings for the Subclasses pretty much stay the same. The optional column name portions of the mapping are most helpful in mapping Table Per Class Hierarchy.

  public class BankAccountMap : SubclassMap<BankAccount>
  {
    public BankAccountMap()
    {
      Map(x => x.BankName, "BankAccount_BankName");
      Map(x => x.RoutingNumber, "BankAccount_RoutingNumber");
    }
  }

  public class CreditCardMap : SubclassMap<CreditCard>
  {
    public CreditCardMap()
    {
      Map(x => x.Type, "CreditCard_Type");
      Map(x => x.ExpirationMonth, "CreditCard_ExpirationMonth");
      Map(x => x.ExpirationYear, "CreditCard_ExpirationYear");
    }
  }

Here you can see the base class mapping for BillingDetails. To use a JoinedSubclass mapping as opposed to the Subclass mapping you just simply omit the DiscriminateSubClassesOnColumn() call.

  public class BillingDetailsMap : ClassMap<BillingDetails>
  {
    public BillingDetailsMap()
    {
      Id(x => x.Id);
      Map(x => x.Number);
      Map(x => x.Owner);
      Map(x => x.DateCreated);
      DiscriminateSubClassesOnColumn("BillingDetailsType");
    }
  }

kick it on DotNetKicks.com

August 6, 2009

Table Per Subclass Inheritance Mapping with Fluent nHibernate

Filed under: .NET, Patterns, Fluent NHibernate, ORM, C#, NHibernate — Tags: , , , , , , — ang3lfir3 @ 2:45 pm

Note: Updates for Fluent nHibernate 1.0 RC can be read here

This is the third in a short series of posts I am working on. While reading through NHibernate in Action I thought to my self that I should create these same examples of Inheritance mapping using Fluent nHibernate to show how simple these mappings can be.

The three types of Inheritance mappings that are mentioned on page 92 of NHibernate in Action are :

Model

  • Table Per Concrete Class
  • Table Per Class Hierarchy
  • Table Per Subclass

I will be using the example from NHibernate in Action to illustrate the mappings. This post covers the Table Per Subclass example. In Table per Subclass inheritance mapping we represent inheritance by using a foreign key to join tables together as needed.  This most closely represents the object model in the relational model of the database by using a table for the base class and one for each subclass.

TablePerSubclassFiles

Here you can see that again I only have one mapping file which covers the entire class Hierarchy.

Below you can see the Fluent Mappings for this approach. The JoinedSubClass<T> uses the Type as the table name by default (“CreditCard” and “BankAccount”) and the first parameter of the method is the name to use for the foreign key column. Additionally the mapping for the class being joined is included.

  public class BillingDetailsMap : ClassMap<BillingDetails>
  {
    public BillingDetailsMap()
    {
      Id(x => x.Id);
      Map(x => x.Number);
      Map(x => x.Owner);
      Map(x => x.DateCreated);
      JoinedSubClass<CreditCard>("CreditCard_Id", m =>
                                                    {
                                                      m.Map(c => c.Type);
                                                      m.Map(c => c.ExpirationMonth);
                                                      m.Map(c => c.ExpirationYear);
                                                    });
      JoinedSubClass<BankAccount>("BankAccount_Id", m =>
                                                      {
                                                        m.Map(b => b.BankName);
                                                        m.Map(b => b.RoutingNumber);
                                                      });
    }
  }

Which maps to the following nHibernate XML mapping file.

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="">
  <class name="TablePerSubclass.Model.BillingDetails, TablePerSubclass, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="`BillingDetails`" xmlns="urn:nhibernate-mapping-2.2">
    <id name="Id" type="Int32" column="Id">
      <generator class="identity" />
    </id>
    <property name="Number" type="String">
      <column name="Number" />
    </property>
    <property name="Owner" type="String">
      <column name="Owner" />
    </property>
    <property name="DateCreated" type="DateTime">
      <column name="DateCreated" />
    </property>
    <joined-subclass name="TablePerSubclass.Model.CreditCard, TablePerSubclass, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
      <key column="CreditCard_Id" />
      <property name="Type" type="Int32">
        <column name="Type" />
      </property>
      <property name="ExpirationMonth" type="String">
        <column name="ExpirationMonth" />
      </property>
      <property name="ExpirationYear" type="String">
        <column name="ExpirationYear" />
      </property>
    </joined-subclass>
    <joined-subclass name="TablePerSubclass.Model.BankAccount, TablePerSubclass, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
      <key column="BankAccount_Id" />
      <property name="BankName" type="String">
        <column name="BankName" />
      </property>
      <property name="RoutingNumber" type="String">
        <column name="RoutingNumber" />
      </property>
    </joined-subclass>
  </class>
</hibernate-mapping>

And the corresponding Database Schema. I followed the naming from the NHibernate in Action so you can see here maybe this is a little confusing. But basicly the “BankAccount_Id” is the primary key of the BankAccount table and contains is also a foreign key to the BillingDetails table.

TablePerSubclassSchema

kick it on DotNetKicks.com

August 4, 2009

Table Per Class Hierarchy Inheritance Mapping with Fluent nHibernate

Filed under: .NET, Patterns, Fluent NHibernate, ORM, C#, NHibernate — Tags: , , , , , — ang3lfir3 @ 2:32 pm

Note: Updates for Fluent nHibernate 1.0 RC can be read here

This is the second in a short series of posts I am working on. While reading through NHibernate in Action I thought to my self that I should create these same examples of Inheritance mapping using Fluent nHibernate to show how simple these mappings can be.

The three types of Inheritance mappings that are mentioned on page 92 of NHibernate in Action are :Model

  • Table Per Concrete Class
  • Table Per Class Hierarchy
  • Table Per Subclass

I will be using the example from NHibernate in Action to illustrate the mappings. This post covers the Table Per Class Hierarchy example. In Table per Class Hierarchy  inheritance mapping we enable polymorphism by using a type discriminator column to determine the Type when rehydrating objects. This means that all of the properties of all the subclasses including those of the base class are included in the single table. All columns that are not part of the base class must be nullable allowing the single row to reflect only the data required for the type being stored.

TablePerHierarchyFiles

Here you can see I have only one mapping file. This mapping file covers the entire class Hierarchy in a single file.

Below you can see the Fluent Mappings for this approach. The “DiscriminateSubClassOnColumn” indicates that name of the of the column in the Database that should be used to descriminate the types of each subclass. Fluent nHibernates default behaviour is to use the Class name as the descriminiator value. You can see how each Subclass is mapped. Notice that I used a prefix on the column names for the Subclass mappings. This allows the database schema to be easily readable.

  public class BillingDetailsMap : ClassMap<BillingDetails>
  {
    public BillingDetailsMap()
    {
      Id(x => x.Id);
      Map(x => x.Number);
      Map(x => x.Owner);
      Map(x => x.DateCreated);
      DiscriminateSubClassesOnColumn("BillingDetailsType")
        .SubClass<CreditCard>(m =>
                                {
                                  m.Map(c => c.Type, "CreditCard_Type");
                                  m.Map(c => c.ExpirationMonth, "CreditCard_ExpirationMonth");
                                  m.Map(c => c.ExpirationYear, "CreditCard_ExpirationYear");
                                })
        .SubClass<BankAccount>(m =>
                                 {
                                   m.Map(b => b.BankName, "BankAccount_BankNumber");
                                   m.Map(b => b.RoutingNumber, "BankAccount_RoutingNumber");
                                 });
    }
  }

Which maps to the following nHibernate XML mapping file.

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="">
  <class name="TablePerHierarchy.Model.BillingDetails, TablePerHierarchy, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="`BillingDetails`" xmlns="urn:nhibernate-mapping-2.2">
    <id name="Id" type="Int32" column="Id">
      <generator class="identity" />
    </id>
    <discriminator column="BillingDetailsType" type="String" />
    <property name="Number" type="String">
      <column name="Number" />
    </property>
    <property name="Owner" type="String">
      <column name="Owner" />
    </property>
    <property name="DateCreated" type="DateTime">
      <column name="DateCreated" />
    </property>
    <subclass name="TablePerHierarchy.Model.CreditCard, TablePerHierarchy, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
      <property name="Type" type="Int32">
        <column name="CreditCard_Type" />
      </property>
      <property name="ExpirationMonth" type="String">
        <column name="CreditCard_ExpirationMonth" />
      </property>
      <property name="ExpirationYear" type="String">
        <column name="CreditCard_ExpirationYear" />
      </property>
    </subclass>
    <subclass name="TablePerHierarchy.Model.BankAccount, TablePerHierarchy, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
      <property name="BankName" type="String">
        <column name="BankAccount_BankNumber" />
      </property>
      <property name="RoutingNumber" type="String">
        <column name="BankAccount_RoutingNumber" />
      </property>
    </subclass>
  </class>
</hibernate-mapping>

And finally you can see the relational model this maps to. Every property of every type is represented as a column. Those of the base class are included as well. You can see the discriminator column “BillingDetailsType” as well.

TablePerHierarchySchema

kick it on DotNetKicks.com

Table Per Class Inheritance Mapping with Fluent nHibernate

Filed under: Patterns, Fluent NHibernate, ORM, C#, NHibernate — Tags: , , , , , — ang3lfir3 @ 10:45 am

This is the first in a short series of posts I am working on. While reading through NHibernate in Action I thought to my self that I should create these same examples of Inheritance mapping using Fluent nHibernate to show how simple these mappings can be.

The three types of Inheritance mappings that are mentioned on page 92 of NHibernate in Action are :

  • Table Per Concrete Class Model
  • Table Per Class Hierarchy
  • Table Per Subclass

I will be using the example from NHibernate in Action to illustrate the mappings. This post covers the most basic and often most common example, Table Per Class. In Table per concrete class inheritance mapping we discard polymorphism and inheritance from the relational schema and create as the name suggests a single table for each concrete class. This means that the DateCreated , Number, and Owner properties of the base class will be reflected in each table. This can be dangerous as these column’s datatypes must now stay in sync across the two tables. If a change needs to be made to the schema you will have to find all the tables that inherit from BillingDetails and edit their schemas independently. This is not necessarily a problem when dealing with a few classes but can be come a problem in a larger and more complex model.

TablePerClassFiles

Here you can see that in this case I have only two mapping files. One for each inheritor.

Below you can see the Fluent nHibernate mapping classes that show how simple this mapping is.

  public class BankAccountMap : ClassMap<BankAccount>
  {
    public BankAccountMap()
    {
      Id(x => x.Id, "BankAccount_Id");
      Map(x => x.Number);
      Map(x => x.Owner);
      Map(x => x.DateCreated);
      Map(x => x.BankName);
      Map(x => x.RoutingNumber);
    }
  }

  public class CreditCardMap : ClassMap<CreditCard>
  {
    public CreditCardMap()
    {
      Id(x => x.Id, "CreditCard_Id");
      Map(x => x.Number);
      Map(x => x.Owner);
      Map(x => x.DateCreated);
      Map(x => x.Type);
      Map(x => x.ExpirationMonth);
      Map(x => x.ExpirationYear);
    }
  }

Which maps to the following nHibernate mapping XML:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="">
  <class name="TablePerClass.Model.BankAccount, TablePerClass, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="`BankAccount`" xmlns="urn:nhibernate-mapping-2.2">
    <id name="Id" type="Int32" column="BankAccount_Id">
      <generator class="identity" />
    </id>
    <property name="Number" type="String">
      <column name="Number" />
    </property>
    <property name="Owner" type="String">
      <column name="Owner" />
    </property>
    <property name="DateCreated" type="DateTime">
      <column name="DateCreated" />
    </property>
    <property name="BankName" type="String">
      <column name="BankName" />
    </property>
    <property name="RoutingNumber" type="String">
      <column name="RoutingNumber" />
    </property>
  </class>
</hibernate-mapping>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="">
  <class name="TablePerClass.Model.CreditCard, TablePerClass, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="`CreditCard`" xmlns="urn:nhibernate-mapping-2.2">
    <id name="Id" type="Int32" column="CreditCard_Id">
      <generator class="identity" />
    </id>
    <property name="Number" type="String">
      <column name="Number" />
    </property>
    <property name="Owner" type="String">
      <column name="Owner" />
    </property>
    <property name="DateCreated" type="DateTime">
      <column name="DateCreated" />
    </property>
    <property name="Type" type="Int32">
      <column name="Type" />
    </property>
    <property name="ExpirationMonth" type="String">
      <column name="ExpirationMonth" />
    </property>
    <property name="ExpirationYear" type="String">
      <column name="ExpirationYear" />
    </property>
  </class>
</hibernate-mapping>

And finally here you see the relational model that this maps to. The base class properties are stored as columns of each table.
TablePerClassSchema

kick it on DotNetKicks.com

March 18, 2009

Fluent NHibernate new style mappings – powerful semantics

Filed under: C#, Fluent NHibernate, NHibernate, ORM, Uncategorized — Tags: , , , , , , — ang3lfir3 @ 5:56 pm

So today I updated to the latest build of Fluent NHibernate.  As any of you who might have done the same have discovered there are some breaking changes. I wasn’t sure I liked the new class based conventions at first, especially since it wasn’t clear at first how to tackle altering my mappings. Then it dawned on me how powerful the conventions would end up being while also promoting DRY.

as @jagregory said :

“brevity was sacrificed for power in this case.”

This can be seen in the example below which is a self referencing Parent Child relationship.

The description of the relationship is:

Categories can have one or none parents.

Categories can have many or no children.

The parent Category is always found in a property called “Parent”.

The children are always found in a property called “Children”.

Before

Original Mapping:

public class CategoryMap : ClassMap<Category>
{
  public CategoryMap()
  {
    Id(x => x.Id);
    Map(x => x.Name);
    References(x => x.Parent).TheColumnIs("parent_id").Cascade.All();
    HasManyToMany(x => x.Products).Inverse();
    HasMany(x => x.Children).WithKeyColumn("parent_id").Cascade.All().Inverse();
  }
}

**Note:  These aren’t exactly “Conventions” but it turned out that ‘WithKeyColumn’ got dropped and I had to look for a better way. The new style conventions offered that even over older convention styles.

After

The new style Convention Mappings :

The Convention classes below create a convention that reads like:

“For a HasMany when the child type matches the type of the root and the name of the property is ‘Children’  then use the column ‘parent_id’ as the KeyColumn. For a Reference when the child type matches the type of the root and the name of the property is ‘Parent’ then set its reference ColumnName to ‘parent_id’ “

public class SelfReferencingHasManyConvention : IHasManyConvention
{
  public bool Accept(IOneToManyPart target)
  {
     return target.Member.ReflectedType == target.EntityType && target.Member.Name == "Children";
  }

  public void Apply(IOneToManyPart target)
  {
     target.KeyColumnNames.Clear();
     target.KeyColumnNames.Add("parent_id");
  }
}
public class SelfReferencingReferenceConvention : IReferenceConvention
{
  public bool Accept(IManyToOnePart target)
  {
    return target.Property.ReflectedType == target.EntityType && target.Property.Name == "Parent";
  }

  public void Apply(IManyToOnePart target)
  {
     target.ColumnName("parent_id");
  }
}

The Mapping after the convention :

Clean and clear, the conventions themselves are not cluttering the Mapping. More importantly the conventions help me stay DRY.

public class CategoryMap : ClassMap<Category>
{
  public CategoryMap()
  {
    Id(x => x.Id);
    Map(x => x.Name);
    References(x => x.Parent).Cascade.All();
    HasManyToMany(x => x.Products).Inverse();
    HasMany(x => x.Children).Cascade.All().Inverse();
  }
}

Adding Mappings to my Persistence Model

You can see that adding the conventions was pretty easy and straight forward. This applies to the fact that I am using the PersistenceModel approach.

public class DataModel : PersistenceModel
{
  public DataModel()
  {
     AddMapping(new ProductMap());
     AddMapping(new CategoryMap());
     ConventionFinder.AddFromAssemblyOf<DataModel>();
   }
}

kick it on DotNetKicks.com

The Silver is the New Black Theme. Create a free website or blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.