in

 

AgileJoe

Answering all world issues with, "...it depends..."
  • Grapevines and Agile make great Wine...

    I couldn't resist the title.

    By this point in most of your careers you have been exposed to the grapevine exercise. This exercise is geared to show you how one thought through many control points gets distorted and misrepresented. I believe this is true for the majority of conversations out side of work but if leveraged properly can add tremendous benefit to an organization.

    Keith Davis did a study of the grapevine in 1953.  Keith Davis stated

    "the grapevine is a natural part of a company's total communication system...it is a significant force within the work group, helping to build teamwork motivate people, and create corporate identity."

    This type of discussion medium is prevalent and natural to the greater society. Just think about what happens in your homes.

    In most homes there isn’t a plan written down for how to do the budget, there isn’t a process on how discussions at the dinner table will be deliberated. There are guidelines but these guidelines are mutually agreed upon in open discussion. In most homes these types of forums are left open and honest, focus is on content then exactness.

    Organically barriers are established but periodically they are revisited (usually by teenagers) to test their validity.  The content however is “I heard...”, “Did you know...”, “Today at work...”.  Nothing of empirical substance but enough to spark decisions in the house hold.  If we are wrong we readjust and go on.

    Some of us however need more control in order to FEEL safe. Some of us feel that the more we pursue exactness the better our decisions will be. Issues arise when this personality type forces others to fall in line with this thought process.

    Several heavy weight methodologies have attempted to control discussion and thought through various bureaucratic mechanism. While some have the perception of control, few if any, have ever been able to achieve this.

    The Agile Manifesto tells us that we should value Individuals and interactions over processes and tools. 

    So with this philosophical mindset we must propagate fluid communication and document or create processes around communication when “absolutely necessary.”

    Take a moment and evaluate “absolutely necessary,” this implies that you have exhausted all low friction practices to promote communication. Then and only then do you investigate a tool or a process to govern communication.

    If you do come up with a process or tool please take the time to put in place some type of 6 week reevaluation period to determine if whatever avenue you are pursuing is proving to beneficial and not wasteful.

    How does this have anything to do with the grapevine paradox? Well, you have to remember that people are people, rather then trying to change their innate ability to communicate openly, embrace it!

    I would venture to argue that the majority of individual you interact with daily would welcome open communication over documentation.  There are the few that do  so if your organization is composed of this type of individual you must respect their needs and give them what they need to be successful. But weigh it in contrast to the majority.

    Take the grapevine paradox and embrace it by facilitating open communication such as daily stand-ups, fishbowl discussions, innovation games, collaborative retrospectives and development lab architectural discussions. The emphasis is on the openness which breeds transparency.

    Let us not forget that People communicating successful to accomplish a common goal are what determine project success not charts or graphs but people.

    Simple in concept but often overlooked.

  • Matrix Resource Management and Agile

    I have been having an ongoing discussion lately concerning matrix management styles and how they conflict with Agile Project Management.

    If you look at the traditional "Iron Triangle", resources are estimated, in that change is expected in the resource allocation depending upon task and assignment.

    clip_image002

    In Agile resources are fixed throughout the duration of the project and features are variable.

    This is a clear delineation into the approach of Agile resource management. Traditional matrices were based off of manufacturing models that do not lend themselves to effectively managing knowledge-based work such as software development.

    Manufacturing management relies on technicians to be trained at various activities in their line of work. These activities rarely, if ever, change. So, mastery of these activities increases dramatically with repetition. This is not a bad thing, since tremendous value is gained through the repetition for the business. From a management perspective it is very easy to assign different work streams to one person since the proficiency level of the work environment is not built upon change or adaptability but on repetition and skill mastery.

    Knowledge-based resource management understands that knowledge workers are trained professional but the context domain on which their skills are applicable is in a constant dynamic state. Therefore, this forces the knowledge worker to pursue greater levels of training and reconstitute positions of ideology based on experience. This is the benefit of the organization that employs knowledge workers.

    The fluidity of communication and thought surrounding a project (especially a software project) forces the knowledge worker to gain greater depth in the problem domain so that they may better serve the business in providing services.

    This idea is compounded when you start to manage teams of knowledge workers. The term, "two minds are better the one", shines in this environment. As knowledge teams ensure business value is rendered and investiture in the project increases, the thoughts and ideas of the whole out weight that of the individual.

    As matrix management encroaches upon Agile management the philosophical view points on resource allocation are contrary to each other. Consider the following:

    Organization: Gloop Org

    • Developer UberBob – Is assigned to

    • Project A @ 25% of his time
    • Project B @ 65% of his time
    • Project C @ 10% of his time

    I know this NEVER happens but work with me. The Gloop organization is wanting to move toward a more Agile development approach but is not willing to give up it's matrix model just yet.

    • Project A is in the planning stages and several meetings have been setup to discuss how the new billing system is going to work.

    • Project B is knee deep in the second release and velocity has been established for each iteration. The new warehouse system is underway.

    • Project C is just finishing up but automated testing wasn't followed so the team is mainly focusing on defect removal. Defect backlog is high.

    Monday:

    Bob comes to work and is perplexed to what standup he has to attend since he has input to each one of the projects he is on. He has already been dealing with this dilemma for the past couple of months as he spends the latter part of his day creating emails to send to the project managers of the standup he will not be attending.

    The project managers do their best to convey Bob's work and impediments but usually Bob has to follow up with team members throughout the day to determine what he missed and what issues he has to solve due to the breakdown in communication.

    In Project B, Bob is working heavily on how the conveyor system is going to determine what gates to open to ship the merchandise. There is an issue, however, that the team has to figure out because the communication protocol isn't fully supported for the gating system as originally thought. Several meetings are planned in the afternoon with the development team to discuss the correct course of action.

    In Project A, they are still going through several domain modeling sessions to flush out how the billing system is going to work. The billing system model for Gloob is unique and is how the company maintains it's competitive advantage. They are going to go over the complexities of this system in the afternoon.

    In Project C the defects are just getting out of hand. There are several show stopping defects and the team is going to have to determine how they are going to solve these issues before going to production. They are going to get back to Bob on when the meeting is going to be held.

    I am not going to go into what happens here but magically Bob is able to pull a miracle and make it to each meeting but he has to sacrifice time and only go partially to each meeting and rely on the meeting minutes to catch him up to speed.

    Bob is an awesome developer, he is prideful about everything he does, and works late hours to overcome all the impediments his projects go through daily. The issues surmount when the communication breaks down.

    What Bob didn't know was after he left the Billing System meeting they went into a critical discussion on how the system calculates interest. His fellow teammates estimated that feature at taking days, but in reality with Bob's experience, it will take months. In the warehouse system the Product owner came in and changed the backlog since the “gate issue” is going to take longer to flush out. So they added other value stories above the gate. But Bob doesn't know this and is planning on staying late to figure out how to solve the gate issue. Bob was unable to really bring any value to the defect discussion since he came in at the tail end of the meeting. Bob's teammates weren't too happy with him for missing the defect meeting.

    End of Monday…

    I know this never happens in the real world but it is very possible (I say that tongue in cheek). All these projects are at risk because of the matrix model. Knowledge workers need to focus on one context at a time so that we harness the power of their collective thought.

    By fixing the resources on a given project and dedicating them throughout, you gain momentum and predictability of effort. Matrix models disrupt communication continuity as well as iteration velocity. As you mix and match resource from project to project every week, you might as well throw whatever velocity you have been tracking out the window as the team dynamics have been disrupted. If you simply perform a one for one swap of personnel you cannot expect output not to be disrupted.

    I want to make sure that everyone understands that I am not saying that matrix management doesn’t work. I have seen it work on extremely large RUP projects that lasted several years. My definition of “work” is slightly skewed because the project was less then stellar but the work effort was as fluid as RUP can be.

    My argument solely revolves around matrix management and Agile. You can do it but the experience of true Agile will be lost. The people aspect of Agile, which to me is the most critical, will be damaged due to constantly managing frustration based around priority and delegation.

    I have always said this and continue to say this, “Agile refocuses management to concentrate on people aspect of leadership. By focusing on increasing quality of life for the employee and increasing knowledge share, the benefits are tremendous!”

  • My issues with the term "Scrum Master"

    A few years ago I was very excited at the possibility of becoming a Scrum master.  At the time I had been an avid XP practitioner for a little over two years.  I had read several books on the Scrum but viewed it as simply Yet Another Agile Methodology (YAAM) with a focus more on the project management.  I thought to myself that I must have been missing something.  How can something as simple as this methodology be taking off like wild fire in the corporate arena?  I figured that a Scrum Master class would shed light on this dilemma of mine.

    Day 1 of Scrum Master training, typical PowerPoint presentation with lots of slides telling you how great Scrum is and different scenarios where Scrum has been applied. Still no epiphany.  The day goes on and we get to do hands on Sprint planning meetings, we emphasize the importance of the Daily Scrum. OK been there already, understand the importance feedback, still nothing ground breaking. Next we talk about value stream prioritization from the perspective of the Product Owner.  People are asking lots of questions on what do you do…etc.  Lots of dialog but still nothing earth shattering.  Next we discuss organic team composition, something that is near and dear to my heart but we spend around 20 minutes on this topic basically saying let the team self organize to gain the greatest value. On to retrospectives, very enlightening, nothing really new, there isn’t one way to do a retrospective, several books are recommended.  And this is the end of Day 1.

    Day 2 we actually go though an entire mock release.  We form up into 5 person teams. Each of us assumes various roles such as Product Owner, Scrum Master, and the development team.  We go through the Sprint Planning session and prioritize a backlog with the product owner learning several techniques on how to gain insight into how the backlog is being prioritized. Now we start our first development cycle that is time boxed to 5 minutes. Team self organizes and pulls stories from the backlog to work on.  At the end of 5 minutes we do our daily Scrum.  We talk about what we did, what we are going to do and are there any impediments in our way. We go through several cycles with some of them trying to be sabotaged by the instructors with various impediments that the team manages to overcome. At the end of the Sprint we demonstrate the final product to the Product Owner (in this case it was a magazine) they make suggestions and reprioritize the backlog.  We then hold a Sprint retrospective and talk about what worked, what didn’t work, and where we could improve. On to the next sprint to start the whole process again.

    At the end of Day 2 we had a feedback session about how the class went.  We talked about what we learned and ways on which to improve the class.  For me it was nothing more of a confirmation of what I had already been practicing but there was something that was missing, more on that later.

    Now the scary part! Towards the end of the class we signed several sheets of paper and 30 minutes later I was awarded the title of, “Scrum Master”! What I didn’t tell you is that the class was filled with individuals with out any software development background.  Here is a list of some of the titles that where in the meeting.  Vice Presidents, CIO’s, Project Managers, Product Mangers, Developers and a Financial Analyst.  All of these individuals could now place, the title of Certified Scrum Master on their resume and wreak havoc to any organization that would give them the power.

    It is not that I have a problem with Scrum so much as it is I have a problem with title, “Scrum Master”. The word “master” implies that this person has attained a level of mastery of everything related to scrum though experience, experimentation and trial.  I would have preferred the term “Scrum Apprentice” to “Scrum Master”.

    Scrum is very instrumental at getting an organization to adopt Agile.  I have a post about this calling out that, “Scrum is the gateway drug to Agile”.  If you choose to adopt Scrum your organization you will gain greater insight into its culture.  This insight is not always welcomed as it will expose many of your organization process and personnel related issues.  How you choose to deal with these issues will determine how successful your project will be.

    Personally speaking Scrum cannot be practiced on its own.  Scrum lacks software engineering disciplines and practices, this is where XP excels.  By combining both methodologies into one ecosystem you have a very powerful foundation to build on.

    If you do decide to go down this path make sure to ask for the Scum Masters list of impediments and how they overcame them.  Also ask about what they have learned from their mistakes.  This will give you an idea on the level of experience the individual has running Scrum Projects.
     

  • Twittering from the command line

    So I was experimenting with Twitter last night and started to use their RESTful services from the command line. 

    Why you may ask? Well sometimes I just want to tweet something quickly and I don't want to bother with opening a client or web page.  So I through together this simple bash script.

    tweet()
      {
        curl -u <username>:<password> -d status="$1" http://twitter.com/statuses/update.xml
      }

    Simply add this to your .bash_profile and you can tweet from the command line all day.

    tweet "Tweeting from the command line is awesome!" 

    I love RESTful services despite popular belief.  :-) 

  • JUnit 4 TestSuite Declaration

    This is mainly for my own reference but if it helps people out there great!  The documentation on this aspect of JUnit is very poor.

    package agalliao.wealthManagment.domain;

    import org.junit.runner.RunWith;
    import org.junit.runners.Suite;

    @RunWith(Suite.class)
    @Suite.SuiteClasses({
    investmentTests.class,
    catalogTests.class,
    markerTests.class
    })
    public class AllTests {
    // why on earth I need this class, I have no idea!
    }
    Posted Apr 14 2008, 10:35 PM by Joe Ocampo with no comments
    Filed under: ,
  • PTOM: OCP revisited in Ruby

    I was playing with some Ruby code this weekend and thought I would show some OCP with Ruby.

    For more of an in-depth discussion on OCP please read my previous post.

    Now the first thing I want to point out is that dynamic languages are naturally by default open for extension. Since the types are dynamic, there are no fixed (static) types. The enables us to have awesome extensibility. It is the closure part of the equation that really scares me more than anything else. If you really aren’t careful when you are programming with dynamic languages you can quickly make a mess of things. This doesn’t take away from the power of a dynamic language you just have to exercise greater care that is all.

    So let’s use our OCP scenario template again and apply them to the example scenario.

    • The ProductFilter is responsible for filtering products by color
    • The ProductFilter is responsible for filtering products by size
    • The ProductFilter is responsible for filtering products by color and size

    Let’s go ahead and create the ProductFilter first.

    class ProductFilter
        
        attr_reader :products
        
        def initialize(products)
            @products = products
        end
        
        def by(filter_spec)
            
        end
    end

    For those that have never created a class in Ruby let me breakdown the syntax structures.

    class keyword is used to define a class followed by the name of the class. It is important to note that class names must be start with an uppercase letter. The uppercase letter signifies to the Ruby interpreter that this is constant, meaning that whenever the term “ProductFilter” comes up it will always reference this class structure.

    attr_reader keyword used to signify a read only accessor (read only property). The property name follows the colon.

    def keyword is used to declare a method block. The “initialize” method is the same as the constructor method in C#.

    The @ symbol denotes an instance variable. Notice that the “products” read accessor is never typed but is assigned in the constructor through @products reference. The instance variable @products is assigned to the products parameter variable that is passed into the constructor.

    Now that we are talking about products we have to create the actual product class.

    class Product
        attr_accessor :color
        attr_accessor :size
        
        def initialize(color, size)
            @color = color
            @size = size
        end
    end

    Nothing fancy here, just a class with two read/write accessors Color and Size.

    If you remember from my previous post I was using a template pattern to serve as the basis for extending the behavior of my filter class. Well I am going to do the same thing here (kind of) and define an Item_color_filter_spec class.

    class Item_color_filter_spec
        attr_accessor :color
        
        def initialize(color)
            @color = color
        end
        
        def apply_to(items)
            
        end
    end

    Now I have a class that accepts a color and has an “apply_to” method that accepts “items”. I have left out the implementation code of this method on purpose.

    The next thing I am going to do is create an array of products I can use against the ProductFilter class. Ruby makes this pretty painless:

    products = [
        Product.new("Blue", "Large"),
        Product.new("Red", "Large"),
        Product.new("Blue", "Medium"),
        Product.new("Red", "Small"),
        Product.new("Blue", "Large"),
        Product.new("Yellow", "Small"),
    ]

    So what’s going on here? I declared a variable called “products” and assigned it to array by using the square braces “[ ]”. Yup that simple!

    What you may have noticed is that I actually instantiated several new products in the array. To instantiate a class you simply use the “new” method that is part of the Object class that all objects in Ruby inherit from similar to C#.

    Now that I have a collection of products I am going to give to my product filter class.

    product_filter = Product_Filter.new(products)

    In the example below I am going to filter all the “Blue” products.

    blue_products = product_filter.by(Item_color_filter_spec.new("Blue"))

    At this point I am creating a new “Item_color_filter_spec” and giving the color “Blue” as the color to filter on. The ProductFilter class would then simply call the “apply_to” method on the “Item_color_filter_spec”.

    If you ran the code at this point nothing would happen because we haven’t actually written our filter code yet. So to do that we are going to modify the “apply_to” method of our “Item_color_filter_spec” class with the following code.

    def apply_to(items)
        items.select{|item| item.color == @color}
    end

    In the code above the “apply_to” method is expecting an array of items to be passed in. We then call the “select” method on the array class and pass in a filter “proc” by enclosing the statement in curly braces {} (In Ruby a “proc” is an object that holds a chunk of code but more on this later). The pipe block “||” is used to signify parameters to the proc similar to the parameters of a method. After the pipe block is the actual statement that is executed. We are trusting that the “select” method of the array object is going to enumerate over each object (product) it contains and pass it into Proc. Once in the Proc we simply determine if the color of product matches the instance variable “@color” of the “Item_color_filter_spec” in this case the color “blue”. When the Proc evaluates to true it passes the item to an array that the select method returns.

    You can possibly equate a “proc” to a lambda expression in C#.

    (Normally I would have used rSpec to govern everything I am doing but I didn’t want to explain BDD as well. I wanted to focus on the Ruby language in general.)

    Now if you run the code you will have three products in the “blue_products” variable. How do you know? Well let’s iterate over it by using the following code.

    blue_products.each do |product|
        puts(product.color)
    end

    Now remember “blue_products” is an array object. The array object has an “each” method (as do other objects in Ruby) that accepts a “proc” object. The “proc” block is denoted by the “do” keyword and terminated with the “end” keyword. In our block we expecting that the array objects “each” method is going to give us a product. As the each method iterates over each product it passes it to the “proc” and we simply tell Ruby to write it to the screen using the “puts” method. The result of this small statement block in the following:

    Blue
    
    Blue
    
    Blue
    

    So there you have it 3 blue products!

    I know, nothing special right? Well now let’s play with some Ruby sweetness!

    That sure is a lot effort to filter a product by color. Imagine if you had to keep adding different color filters. You would have to create several “color filter specs” over and over again. That is dull and most static languages have played this out! So let’s use some Ruby Lambda’s to accomplish the same thing as the “color filter spec”

    We are going to create a filter spec that filters all products that are yellow.

    Remember I told you that Ruby views all uppercase variable names as constants; well we are going to harness the power of this convention and create a constant to hold the reference to the lambda. After all DRY principles still apply here.

    YELLOW_COLOR_FILTER_SPEC = lambda do |products|
        products.select{|product| product.color == "Yellow"}
    end

    Nothing in the code block above should be foreign at this point except for the “lambda” key word. What the “lambda” keyword does is tell the Ruby interpreter to assign the “Proc” to the constant “YELLOW_COLOR_FILTER_SPEC”.

    We have to now modify our ProductFilter class to accept a Proc object. All you have to do is add the following method to the ProductFilter class.

    def by_proc(&filter_spec_proc)
        filter_spec_proc.call(@products)
    end

    This method has a parameter named “filter_spec_proc” but if you notice there is an ampersand preceding its declaration. This tells the Ruby interpreter to expect a Proc object to be passed in. Since we are expecting a Proc object all we have to do is use the "call" method and pass the products instance variable to the Proc.

    Now let’s wire the whole thing together.

    yellow_products = product_filter.by_proc(&YELLOW_COLOR_FILTER_SPEC)

    Pretty simple about the only thing you have to remember is that you have to place the ampersand before the Proc constant when you call the “by_proc” method on the ProductFilter class.

    But wait there is more!

    Our ProductFilter class now has a method that accepts a Proc object. In our previous example we passed it a constant that referenced a lambda Proc block. But since it accepts a Proc we can simply write the block in line with the method call like this.

    With our new found knowledge lets filter all the “Red” products.

    red_products = product_filter.by_proc do |products|
            products.select{|product| product.color == "Red"}
        end

    Parenthesis are optional in Ruby when you call a method.

    Pretty nice huh?

    Now for something really freaky for all you static type people!

    Lets say you aren’t dealing with products anymore and you are dealing with Cars.

    cars have 4 wheels but they also have color don’t they. Gee it would be nice if we could filter the Cars just like we are able to filter the Products. Wait! We can, we already wrote it!

    We have that “Item_color_filter_spec” class. We could use the ProductFilter class but that class already has a purpose but the “Item_color_filter_spec” is pretty agnostic.

    class Car
        attr_accessor :color
        def initialize(color)
            @color = color
        end
    end
    
    cars = [
        Car.new("Red"),
        Car.new("Blue"),
        Car.new("Red"),
        Car.new("Blue")
    ]
    
    blue_filter = Item_color_filter_spec.new("Blue")
    blue_cars = blue_filter.apply_to(cars)

    Wow talk about reuse!!!

    How is this possible? Well remember types do not exist in Ruby. There are objects but objects are duck typed when you ask them to perform an action. Meaning if it walks like a duck or quacks like a duck it must be a duck. The “Item_color_filter_spec” only cares that it is passed an array of objects. It is then going to iterate over the array of objects and call the “color” accessor on each object to check for equality against the instance variable that was passed in through the constructor. It doesn’t care if the array contains cars, products or both; just that whatever object it is has to have an accessor of "color."

    I know this is a ton on information to digest all at once but I am just very passionate about the Ruby language. I see tremendous potential in its future especially with its entrance into the .Net space through the IronRuby project. I can easily see it over throwing the Visual Basic crowd once it becomes more main stream in the .Net community.

    Posted Mar 30 2008, 10:54 PM by Joe Ocampo with 6 comment(s)
    Filed under: ,
  • Hanging your code out to dry

    I was speaking with Marcus Bratton the other day about code reviews. We both agreed that they are very valuable but finding the time is probably the most difficult aspect of any code review.

    Paired Programming helps to eliminate the need for code reviews but paired programming caries waste of its own when it comes to menial task that need to be accomplished such as HTML.

    We practice an approach we coined “Complexity Based Programming”. The approach allows us to focus our pairing on highly sensitive areas of our code and leave the lower risk task to single individuals. A problem occurs with both approaches in that certain refactoring exercises have failed to be accomplished due to pressure from management or the project in general. So developers begin to cut corners and compromise the integrity of the code base resulting in technical debt. The issue is that the code base isn’t transparent enough that you could readily see this.

    As Agilest we look to our CI server’s state to give us feedback on the health of our code base. We also use tools such as NCover to give us the test coverage state. But this doesn’t necessarily give us our health. It is the equivalent of looking at Lance Armstrong when he had cancer and saying, “This guy’s health is great, look at all the races he is winning.” Little did you know he had cancer growing in his body that is slowly threatening his life?

    Technical Debt is like cancer. If you treat it early on, the health of your software will be tremendous. Let it go or turn a blind eye to it and it will slowly eat its way through every bowl in your code to the point of complete system shut down.

    Tools such as NDepend are like the MRI scanners of medicine. They help to give us a picture into our codebase where we can view low cohesion and high coupling between software entities, which theoretically results in high technical debt. They ease the pains of understanding the COCOMO model and give us high degree of comfort when it comes to our overall health of our system.

    The problem with tools such as NDepend is you have to know how to decipher the data. Don’t get me wrong they do a great job of making it as painless as possible but there is a cost. You have to run the tool! You have to wait for the tool to complete its analysis. You have to be willing to sift through the data. A rewarding exercise but none the less an exercise.

    So we have lots of HiFi options but what LoFi options do we have. Well one that I read about recently peeked my interest.

    As you can see this low friction high value approach is well within anyone’s skill set to produce. What I am recommending is at the end of a given coding session that you simply print out the classes you worked on. Place a string somewhere visible in the lab and hang your code on it. If it is several pages long, tape the pieces of paper on the vertical and hang it out to dry.

    Then developers can walk by the “code line” as tell if you missed a spot or quickly see the 20 page mess you created for the rest of them. Think I am smoking crack? Take a look at a quick test I just did.

    Here is a screen shot of a class file from an awesome OSS project!

    Good_File

    As you can see nice, if you just performed a cursory glance of this code hanging on a line you wouldn’t be too concerned about your teams code.

    Now check this out!

    Bad_Need_Refactoring

    Yes this 30 page monster is ONE class!!!

    Guess which file needed refactoring? If you were to see this hanging on a “code line” would you be worried if you were on this team? If you were a lead or manager what would you do? After all, the test are green!!!

    What??? You didn’t need any fancy tools to discern this premise! I am not trying to take any value away from tools such and NCover or NDepend because they are needed but at the same time light weight approaches are much more valuable from my experience.

    The post I referenced before gives more insight into what to look for as far as margins and typography to determine possible refactoring opportunities.

    In the end all you tree huggers will be screaming fowl but at the same time if you are wasting tons of paper then that may be a indicator that your system is compositionally unstable. So the more you move towards wasting less paper and making the environmentalist happy, the more stable your system will become.

    Disclaimer: There were no trees harmed in the creation of this blog post. :-)

  • Hard to say goodbye

    Well yesterday was my final day at Wachovia.  It was really hard to say goodbye to all the wonderful friends and colleagues I have made there but it was time to move on.  It was really difficult to leave such a great team that has created so many wonderful applications over the last couple of years.  Their Agile mind sets have been cultivated to the point of self sustainability and only great things can come from this group in the future.

    My future path has lead to Rackspace where I will take on the role of an Enterprise Application Architect.  This will be a challenge for me since I really have a distaste for the term Architect as most of the individuals I have met in the past have little to zero exposure in application development.  This lack of experience has resulted in maneuvering this position as more of a governance and standards body, encroaching and decapitating development groups from producing great software under the guise of strategic vision and corporate guidance.  (Can you tell I am a little bitter?)

    My goal is to partner and help the application development groups ALL create great software.  Utilizing the agile and pragmatic tool box to find the best tool for any given job.  In the end, the standards and policies will reveal themselves through the result of working software and ONLY though working software.  Partnership, transparency and open communication will be the foundation of the architecture.  Well it is time to put my money where my mouth is and get er done!

    If anyone has been considering a job in San Antonio, I highly recommend Rackspace.  Their culture and principle help to foster creativity which results in creating a leading IT hosting provider.

  • PTOM: The Open Closed Principle

    The open closed principle is one of the oldest principles of Object Oriented Design. I won’t bore you with the history since you can find countless articles out on the net. But if you want a really comprehensive read please checkout Robert Martin’s excellent write up on the subject.

    The open closed principle can be summoned up in the following statement.

    open/closed principle states "software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification";[1] that is, such an entity can allow its behavior to be modified without altering its source code.

    Sounds easy enough but many developers seem to miss the mark on actually implementing this simple extensible approach. I don’t think it is a matter of skill set as much as I feel that they have never been taught how to approach applying OCP to class design.

    A case study in OCP ignorance

    Scenario: We need a way to filter products based off the color of the product.

    All entities in a software development ecosystem behave a certain behavior that is dependent upon a governed context. In the scenario above you realize that you are going to need a Filter class that accepts a color and then filters all the products that have adhere to that color.

    The filter classes’ responsibility is to filter products (its job) based off the action of filtering by color (its behavior). So your goal is to write a class that will always be able to filter products. (Work with me on this I am trying to get you into a mindset because that is all OCP truly is at its heart.)

    To make this easier I like to tell developers to write the fill in the following template.

     

    The {class} is responsible for {its job} by {action/behavior}

    The ProductFilter is responsible for filtering products by color

     

    Now let’s write our simple class to do this:

    public class ProductFilter
    {
        public IEnumerable<Product> ByColor(IList<Product> products, ProductColor productColor)
        {
            foreach (var product in products)
            {
                if (product.Color == productColor)
                    yield return product;
            }
        }
    }

    As you can see this pretty much does the job of filtering a product based off of color. Pretty simple but imagine if you had the following typical conversation with one of your users.

     

    User: “We need to also be able to filter by size.”

    Developer: “Just size alone or color and size? “

    User: “Umm probably both.”

    Developer: “Great!”

    So let’s use our OCP scenario template again.

    The ProductFilter is responsible for filtering products by color

    The ProductFilter is responsible for filtering products by size

    The ProductFilter is responsible for filtering products by color and size

    Now the code:

    public class ProductFilter
    {
        public IEnumerable<Product> ByColor(IList<Product> products, ProductColor productColor)
        {
            foreach (var product in products)
            {
                if (product.Color == productColor)
                    yield return product;
            }
        }
    
        public IEnumerable<Product> ByColorAndSize(IList<Product> products, 
                                                    ProductColor productColor, 
                                                    ProductSize productSize)
        {
            foreach (var product in products)
            {
                if ((product.Color == productColor) && 
                    (product.Size == productSize))
                    yield return product;
            }
        }
    
        public IEnumerable<Product> BySize(IList<Product> products,
                                            ProductSize productSize)
        {
            foreach (var product in products)
            {
                if ((product.Size == productSize))
                    yield return product;
            }
        }
    }

    This is great but this implementation is violating OCP.

    Where'd we go wrong?

    Let’s revisit again what Robert Martin has to say about OCP.

    Robert Martin says modules that adhere to Open-Closed Principle have 2 primary attributes:

    1. "Open For Extension" - It is possible to extend the behavior of the module as the requirements of the application change (i.e. change the behavior of the module).

    2. "Closed For Modification" - Extending the behavior of the module does not result in the changing of the source code or binary code of the module itself.

    Let’s ask the following question to insure we ARE violating OCP.

    Every time a user asks for a new criteria to filter a product do we have to modify the ProductFilter class?
    Yes! This means it is not CLOSED for modification.

    Every time a user asks for a new criteria to filter a product can we extend the behavior of the ProductFilter class to support this new criteria without opening up the class file again and modifying it?
    No! This means it is not OPEN for extension.

    Solutions

    One of the easiest ways to implement OCP is utilize a template or strategy pattern. If we still allow the Product filter to perform its job of invoking the filtering process we can put the responsibility of how the filtering is accomplished in another class by mixing in a little LSP to accomplish this.

    Here is the template for the ProductFilterSpecification

    public abstract class ProductFilterSpecification
    {
        public IEnumerable<Product> Filter(IList<Product> products)
        {
            return ApplyFilter(products);
        }
    
        protected abstract IEnumerable<Product> ApplyFilter(IList<Product> products);
    }

    Let’s go ahead and create our first criteria, which is a color specification.

    public class ColorFilterSpecification : ProductFilterSpecification
    {
        private readonly ProductColor productColor;
    
        public ColorFilterSpecification(ProductColor productColor)
        {
            this.productColor = productColor;
        }
    
        protected override IEnumerable<Product> ApplyFilter(IList<Product> products)
        {
            foreach (var product in products)
            {
                if (product.Color == productColor)
                    yield return product;
            }
        }
    }

    Now all we have to do is extend the actual ProductFilter class to accept our template ProductFilterSpecification.

    public IEnumerable<Product> By(IList<Product> products, ProductFilterSpecification filterSpecification)
    {
        return filterSpecification.Filter(products);
    }

    OCP goodness!

    So lets make sure we are NOT violating OCP and ask the same questions we did before.

    Every time a user asks for a new criteria to filter a product do we have to modify the ProductFilter class?
    No! Because we have marshaled the behavior of filtering to the ProductFilterSpecification. "Closed for modification"

    Every time a user asks for a new criteria to filter a product can we extend the behavior of the ProductFilter class to support this new criteria without opening up the class file again and modifying it?
    Yes! All we simply have to do is pass in a new ProductFilterSpecification. "Open for extension"

    Now let’s just make sure we haven’t modified too much from our intentions of the ProductFilter. All we simply have to do is validate that our ProductFilter still has the same behavior as before.

    The ProductFilter is responsible for filtering products by color: Yes it still does that!

    The ProductFilter is responsible for filtering products by size: Yes it still does that!

    The ProductFilter is responsible for filtering products by color and size: Yes it still does that!

    If you are a good TDD/BDD practitioner you should already have all these scenarios covered in your Test Suite.

    Here is the final code:

    namespace OCP_Example.Good
    {
        public class ProductFilter
        {
            [Obsolete("This method is obsolete; use method 'By' with ProductFilterSpecification")]
            public IEnumerable<Product> ByColor(IList<Product> products, ProductColor productColor)
            {
                foreach (var product in products)
                {
                    if (product.Color == productColor)
                        yield return product;
                }
            }
    
            [Obsolete("This method is obsolete; use method 'By' with ProductFilterSpecification")]
            public IEnumerable<Product> ByColorAndSize(IList<Product> products,
                                                        ProductColor productColor,
                                                        ProductSize productSize)
            {
                foreach (var product in products)
                {
                    if ((product.Color == productColor) &&
                        (product.Size == productSize))
                        yield return product;
                }
            }
    
            [Obsolete("This method is obsolete; use method 'By' with ProductFilterSpecification")]
            public IEnumerable<Product> BySize(IList<Product> products,
                                                ProductSize productSize)
            {
                foreach (var product in products)
                {
                    if ((product.Size == productSize))
                        yield return product;
                }
            }
    
            public IEnumerable<Product> By(IList<Product> products, ProductFilterSpecification filterSpecification)
            {
                return filterSpecification.Filter(products);
            }
        }
    
        public abstract class ProductFilterSpecification
        {
            public IEnumerable<Product> Filter(IList<Product> products)
            {
                return ApplyFilter(products);
            }
    
            protected abstract IEnumerable<Product> ApplyFilter(IList<Product> products);
        }
    
        public class ColorFilterSpecification : ProductFilterSpecification
        {
            private readonly ProductColor productColor;
    
            public ColorFilterSpecification(ProductColor productColor)
            {
                this.productColor = productColor;
            }
    
            protected override IEnumerable<Product> ApplyFilter(IList<Product> products)
            {
                foreach (var product in products)
                {
                    if (product.Color == productColor)
                        yield return product;
                }
            }
        }
    
        public enum ProductColor
        {
            Blue,
            Yellow,
            Red,
            Gold,
            Brown
        }
    
        public enum ProductSize
        {
            Small, Medium, Large, ReallyBig
        }
    
        public class Product
        {
            public Product(ProductColor color)
            {
                this.Color = color;
            }
    
            public ProductColor Color { get; set; }
    
            public ProductSize Size { get; set; }
        }
    
        [Context]
        public class Filtering_by_color
        {
            private ProductFilter filterProduct;
            private IList<Product> products;
    
            [SetUp]
            public void before_each_spec()
            {
                filterProduct = new ProductFilter();
                products = BuildProducts();
            }
    
            private IList<Product> BuildProducts()
            {
                return new List<Product>
                                   {
                                       new Product(ProductColor.Blue),
                                       new Product(ProductColor.Yellow),
                                       new Product(ProductColor.Yellow),
                                       new Product(ProductColor.Red),
                                       new Product(ProductColor.Blue)
                                   };
    
            }
    
    
            [Specification]
            public void should_filter_by_the_color_given()
            {
                int foundCount = 0;
                foreach (var product in filterProduct.By(products, new ColorFilterSpecification(ProductColor.Blue)))
                {
                    foundCount++;
                }
    
                Assert.That(foundCount, Is.EqualTo(2));
            }
        }
    }
    Posted Mar 21 2008, 07:47 PM by Joe Ocampo with 15 comment(s)
    Filed under:
  • Twhirl is a must for a desktop Twitter client

    If you are Twitterhaulic like Mr Chad Meyer.  I strongly recommend giving Twhirl a whirl!  (Sorry couldn't resist).  I am very impressed with the Adobe Air interface.  Very clean and stylish.

    Twhirl brings together tons of functionality leveraging the twitter API to the max.  I assume that since it is uses the Adobe Air framework that it should run equally impressive on a Mac as well.

    Twhirl

    Posted Mar 18 2008, 11:05 PM by Joe Ocampo with 4 comment(s)
    Filed under:
  • Some people have too much time

    So I gave my two weeks at my current employer around a week ago.  So I really wasn't expecting practical jokes until maybe the end of this week.  Well lets just say my team got creative and managed to wrap my entire cube in foil paper in less then 30 minutes while I was in a meeting today.  Very impressive!

    There attention to detail was astonishing.  They managed to wrap everything from the dry erase markers to every book on my shelf.  They even went so far as to wrap the thumb tacks I have on my board.  Like I said impressive! 

    Here are some images if their work.

    IMG00022

    IMG00023

    IMG00024

    Posted Mar 18 2008, 05:59 PM by Joe Ocampo with 6 comment(s)
    Filed under:
  • Using Context as an example group in rSpec

    If you try to do the following in rSpec you will receive a (nil:NilClass) error on the inner context in the 'before' statement when it tries to use @user.

    describe User do
    
        before(:each) do
            @user = User.new
        end
    
        context "(adding assigned role)" do
            before(:each) do
                @user.assign_role("Manager")
            end
    
            specify "should be in any roles assigned to it" do
                @user.should be_in_role("Manager")
            end
           
            specify "should not be in any role not assigned to it" do
                @user.should_not be_in_role("unassigned role")
            end
        end
       
        context "(adding assigned group)" do
    
        end
    end

    This perplexed me because the rDoc indicates that [context] method is an alias for [describe] method. Turns out there are two different places where describe is defined. One in main (the outermost layer) and one inside an ExampleGroup. The one in the example group isn't aliased.

    So to solve that for the short term in your own code you can do this in your spec_helper.rb file:

    module Spec::Example::ExampleGroupMethods
     alias :context :describe
    end

    In your spec file add the following to the header assuming the spec_helper.rb is in the same directory:

    require File.dirname(__FILE__) + '/spec_helper'

    Now everything should work out great!  BDD sweetness!  Here is the final user_spec.rb

    require 'user'
    require File.dirname(__FILE__) + '/spec_helper'
    
    describe User do
        
        before(:each) do
            @user = User.new
        end
    
        context "(adding assigned role)" do
            before(:each) do
                @user.assign_role("Manager")
            end
    
            specify do
                @user.should be_in_role("Manager")
            end
            
            specify do 
                @user.should_not be_in_role("unassigned role")
            end
        end 
        
        describe "(adding assigned group)" do
        end 
    end

     

    Happy coding!

    Posted Feb 27 2008, 04:22 PM by Joe Ocampo with 2 comment(s)
    Filed under: ,
  • !!!!Please update your LOSTECHIES RSS FEED!!!!

    We have recently updated our main feed to feedburner.  Everyone please update your RSS readers to point too.

    http://feeds.feedburner.com/lostechies

    Thank you, you may now continue with your regularly scheduled reading.

  • Updates to NBehave

    What happened to NSpec?

    I am not sure if all of you know but the NBehave project consolidated with the NSpec project a while back, since then we have been pretty silent about what we are doing because we wanted to give the community something they could simply drop in and not be to evasive in its implementation. Meaning we didn’t want you to have to learn how to use yet another runner.

    What we decided is that NSpec did a lot of cool things but at its heart was an assertion engine. We contemplated if we really wanted to go down the path of creating a whole new assertion engine. This is where Andrew Stopford’s and Jeff Brown’s MbUnit 3.0 Gallio engine come in.

     

    “The Gallio platform is an open, extensible, and neutral system that provides a common object model, runtime services and tools (such as test runners) that may be leveraged by any number of test frameworks. In this vision of the world, MbUnit v3 itself is simply another test framework plugin with the same status as any other.”

    NBehave will utilize the Gallio extensible test framework and employ as many of the BDD idioms as we can manage to squeeze in.

    This will enable us to offer:

    • To use any of the 7 current Gallio test runners, including console, GUI, MSBuild, NAnt, PowerShell, ReSharper and TD.Net plus any new ones that are developed.
    • CCNet integration and most anything else that's built around Gallio
    • NBehave with Gallio as a bundle.

    Pretty cool right? Well as you can imagine this has been ongoing trial an error but the good part is we are working with the Gallio dudes to get something out there.

    So does that mean I have to wait to use BDD then? No…

    We wanted to give you all something now.

    One of the more important constructs of BDD is that we are now specifying how our code should behave under a governed context. Whether that context is story governed or system governed is particular to the situation that is eliciting the invocation. Laymen response it is not just about stories and acceptance testing.

    BDD is about creating a reentrant code base that can be understood by development teams working together to create great software. You should be able to perform a cursory glance at you specifications and understand intentions and expected behavior. The difficult part is that this is going to require the same type of self discipline that TDD fostered.

    So how do you take advantage of this now?

    Well the current repository on Google Code has several features that we think the community can take advantage of now. Thanks go out to David Laribee and JP Boodhoo for the help with the base spec fixture.

    Here is a list of some of the features we have completed and are working towards.

    • · NUnitSpecBase – Done
    • · MbUnitSpecBase - Done
    • · NUnit assertion extensions - Done
    • · MbUnit assertion extensions - Done
    • · Automocking Container - Done
    • · Create MSTest assertion extensions (April 1st)
    • · Create xUnit assertion extensions (April 1st)
    • · TestDriven.NET integration (April 1st)
    • · XML output for stories (April 1st)
    • · XSLT for XML story runner output (April 1st)

    So how do I use these new features?

    • 1. Download the latest trunk from Google Code or wait till April 1st for the official build
    • 2. Execute the go.bat
    • 3. Now create a new project and reference the following dll’s from the build folder (this is assuming you are using NUnit)
      • a. Castle.Core
      • b. Castle.DynamicProxy
      • c. Castle.DynamicProxy2
      • d. Castle.MicroKernal
      • e. Castle.Windsor
      • f. NBehave.Spec.Framework
      • g. NBehave.Spec.NUnit
      • h. NUnit.Framework
      • i. Rhino.Mocks
      • j. …The kitchen sink!

    As you can see there are a lot of dependencies but for the most part they are everything you would need to have the optimal BDD experience.

    At this point I am really jealous of Gem! :-)

    Here is how you would setup a basic specification fixture.

    Pseudo DSL:

    these specs are concerning this [Type]
        when this [type] is in this [context]
            then [specify] that it [should behave] this way

    The first thing is to setup the using aliases.

    using Context = NUnit.Framework.TestFixtureAttribute;
    using Specification = NUnit.Framework.TestAttribute;
    using Concerning = NUnit.Framework.CategoryAttribute;
    

    Then use the namespace to define the concerning type:

    namespace MathFlash.Core.EquationGenerator_Specs

    In the case above the specs in this file are going to be concerning EquationGenerator_Specs.

    Now let’s define our first context.

    [Context, Concerning("EquationGenerator")]
    public class When_initializing_the_EquationGenerator_with_one_and_five : NUnitSpecBase

    As you can see we have defined a class decorated with a Context attribute and a Concerning attribute. We have also inherited from the NUnitSpecBase. The name of the class is defining the context that will govern the expected behavior that we will assert on later.

    Next we will define our first specification.

    [Specification]
    public void Should_generate_equations_where_the_left_hand_side_is_greater_than_or_equal_to_the_lower_bound()
    

    So you have defined a context and specified expected behavior. What is so important about the NUnitSpecBase. Well for one it abstracts the use of the automocking container (I will have a post on that in the next couple of days). It also has several new method conventions that have their roots in rSpec.

    protected override void Before_each_spec()

    This method will be called before_each_spec similar to the SetUpAttribute.

    protected override void After_each_spec()

    This method will be called after_each_spec similar to the TearDownAttribute.

    Last but not least are the NUnit extension methods. You have two options. You can use the standard CamelCase notation or you can use to more readable underscore notation. For example: