Announcing Design Python Pattern of the Week
Every Monday I’ll be describing a software design pattern and providing an implementation in Python. I’ll focus on mapping the pattern’s intent into idiomatic Python. Email me or leave a comment if you are interested in seeing a specific pattern. I’ll start out with some GoF patterns and then work toward the more enterprisey ones.
What are design patterns?
Certain problems come up over and over again when designing software. Things like localizing the creation of objects and wrapping APIs seem to come up in most projects I have worked on. Design patterns are elegant and extensible solutions to these and other software design problems. A pattern is not a complete design. It is advice for dealing with parts of your design. It describes a set of principles and the situations where they apply. A real design would likely consist of many patterns.
Patterns are discovered, not invented, by finding similar solutions in a wide variety of software systems. This ensures that they are true patterns and not a one-off solutions. This also means that the solutions are battle tested. You are not the first one to use them.
Do you need to know patterns?
They are very important when building large systems. Using patterns will relieve you from having to rediscover solutions to problems that others have already solved. Systems built using patterns are also easier to maintain, because developers familiar with patterns will have less of a learning curve.
Having a firm understanding of patterns will make your designs better. Think of patterns as lessons from master software designers. They have already taken the time to solve this problem by looking at many alternatives. This is the best solution they could come up with.
Why is this different from the countless patterns books?
Most modern pattern books use Java in their examples. The Java implementation can sometimes hide the pattern’s intent especially if you’re not a Java programmer. The implementation may look dramatically different in other languages. So if you’re like me and you use Python, the examples are almost worthless.
While translating the examples directly into Python is possible I wouldn’t suggest it. The resulting code would probably not be Pythonic and would instead stink of Java. We can do better than that.
More Information
Use Google, it is your friends. The discussion on Wikipedia is pretty good and the Hillside.net Patterns Library has a large amount of good information.
Comments
6 Responses to “Announcing Design Python Pattern of the Week”
Leave a Reply





Nice idea. I couldn’t help thinking that design patterns sometimes exist because of the limitations of the implementation language.
For instance, visitor pattern would read very differently if Java had supported coroutines.
It reminds me of what Jim Huginin saw when he first saw C# programmers at MS writing Hello world in Python.
class Main:
def main(self):
print “Hello World”
main = classmethod(main)
Main.main()
@Chui Tey
Yeah I agree that patterns really address the limitations of a language. The word pattern implies boilerplate to me.
FYI: Alex Martelli gave a talk (in two parts) on DPs in Python which there are Videos available from at google.
See:
- “Advanced Topics in Programming Languages Series: Python Design Patterns (part 1)”
http://video.google.de/videoplay?docid=-3035093035748181693
- “Advanced Topics in Programming Languages Series: Python Design Patterns (part 2)”
http://video.google.de/videoplay?docid=-288473283307306160
Awesome! Thank you. I meant to do this myself - in fact I started them on the side but suddenly found myself lacking the time (baby). Really looking forward to it.
Great idea! I’m looking forward to reading along every week.
As a new Python idol I am really interested in your coming up articles. Can’t stand waiting for tomorrow…