Mar 18 2009

Patterns & Practices - Part 2

Category: Software DevelopmentJeff @ 06:37

In my previous post on Patterns & Practices, I discussed the fact that in order to learn P&P, you have to be willing to make mistakes.  In the early stages, it is beneficial to look for opportunities to apply patterns to your development so that you can begin to see how they take shape.  You may not understand their benefit in the early stages, but this is a vital step, akin to the experience of the "Karate Kid" as he was told to "wax on / wax off".  He spent weeks practicing the same moves over and over again, not really understanding the purpose of such repetitive tasks.  What he failed to realize was that he was developing muscle memory and creating well worn neural pathways that would prove vital in his development process.  This holds true for us as software developers as well. [For this early development stage, a key resource is a book such as Head First Design Patterns].

Eventually you gain some proficiency with the repetitive tasks.  You begin to realize that certain patterns work better than others in certain circumstances.  You might discover that some patterns can paint you into a difficult corner (Singleton is of course the prime example, though Static Gateway has its pitfalls as well). At this stage you are beginning to deconstruct the value and utility of particular patterns for certain situations and contexts.  You awaken to the realization that code can have a "smell" that communicates whether a design is fitting or not.  While you cannot necessarily name the "smell" it is clearly there.  [At this stage, you're ready to tackle Refactoring to Patterns].

Take time to identify patterns that fit well for addressing particular smells.  Look for examples in code written by others (you are taking time to read code written by others, right?).  And start looking for ways that improper use of patterns can introduce smells of their own.

In my next post in this series, I will switch gears and discuss the relationship between Patterns and Practices and why you ultimately want to emphasize the Practices over the Patterns.  Stay tuned!

Tags: ,

Jan 3 2009

Patterns & Practices - Part 1

Category: Software DevelopmentJeff @ 17:20
This is the first post in a series on Patterns and Practices.  The series will explore the learning process of a developer who desires to learn and apply good patterns and practices.

Emilio and I had an interesting discussion a few days ago regarding Patterns & Practices.  We observed that when a developer first adopts P&P, he behaves like it's all about the patterns.  The developer begins to read books and blogs that describe the various patterns and how these can be useful.  He begins to discover patterns in existing libraries and frameworks.  He starts looking for opportunities to implement patterns in his own development.  And he almost inevitably ends up suffering from some form of patternitis (often concentrated around an overuse of Singleton!).

I believe this phase of development is necessary for a developer.  To comprehend patterns you have to actually try developing with them.  You can learn a lot about patterns from a book, or by reading code from someone else's project.  But ultimately the only way to truly understand patterns is to actually put them to use in a project of your own.  In this regard, learning patterns is like learning to ice skate - you can watch others skate, you can read books on skating, but ultimately you're going to have to throw on some skates and hit the ice.  And when you do, you're going to fall.  When I learned to skate as a kid I remember that I was always afraid to fall.  This fear prevented me from learning.  But eventually someone told me that the only way to learn to skate was to push myself, and that meant I was going to fall sometimes.

So dig in, read about patterns, study them, learn to discover them in your code and in the code of others.  And go ahead and try using some of them in your own projects.  Yes, you will make mistakes, but this is a vital part of the learning process.

This post has focused on the initial process of learning patterns.  In my next post on this topic, I will explore how the developer can begin to experience success applying patterns in his or her own projects.

Tags: