Tuesday, September 24, 2013

Patterns in the Code

Square Pegs is round holes. Could be design patterns
I spend a great deal of time reading other peoples code.  It is part of my day job as a Scrum Master.  It is also what I do as the president of E3 systems.  It is a tedious task sometimes but I recommend it for every developer working today.  This week on the blog, I want to discuss code patterns and why they are important for any developer.

In the world of literature, there are countless critics and competing schools of literary thought.  Fortunately, the world of computer science does not have that problem.  The most important standard for software is that it works and that it meets the needs of customers.  This is changing as software becomes more complex and it has become more important to the operation of the business.  Standards cropped up thanks to this new reality and I think it has been a good thing for the industry.

Developers in many respects are like painters; they are creative, temperamental and a little crazy.  Ask two developers to write the same software with the same requirements, you will get code that is written very differently.  Multiply this by several hundred developers over three continents and you have a recipe for disaster.

Most coding standards are fairly common sense.  I personally like the standards from Microsoft regarding C#.  However, I am starting to see some troubling trends.  First, the Gang of Four, design patterns for Java are being used as a cudgel to punish self taught developers.  These design patterns have been taught in computer science classes the last ten years and the original book on the subject came out in 1994.  Today those patterns are used in numerous development languages.  A good developer with an understanding of the object oriented development doesn't need to use these patterns but some architects and a sizable minority think they should be the necessary grammar of development.

I strongly disagree with this position.  Gang of Four design patterns are a style of development not the last word on the subject.  To barrow from my friends in English and Communications theory, the Gang of Four represents a dialect of coding rather than the grammar.  Just like the formal language of a court room is different than the informal tome construction workers use on the job site.  There is a time and place for both and slavish devotion to design patterns make about as much sense as using a hammer to drive a wood screw.

Software developers often that they are artists but in the real world they are often being used like animators helping create large and complicated pieces of work with an almost infinite number of moving parts.  The Gang of Four design patterns are helpful but are being misused by a minority in the development community to judge the ability of other developers who do not understand these processes.

I am much more open to the SOLID programming approach which creates general guidelines for flexible code.  These guidelines make design patterns possible but not necessary.  If you use SOLID are more likely to write cleaner and easier to use code.  Furthermore, this approach instills good habits in both self-taught and classically trained developers.

A developer is his own worse critic.  I know that I look at code I worked on three years ago and cringe at my lack of technique.  I think I am a better developer now than I was when I started fifteen years ago.  I may not use design patterns but I think that I can create satisfying customer solutions.  In the end, that was why I wanted to be a programmer in the first place.

Until next time.