Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #15316 > unrolled thread

Design Pattern and Python: Any book recommendation? Your view?

Started byAnthony Kong <anthony.hw.kong@gmail.com>
First post2011-11-03 17:33 -0700
Last post2011-11-04 13:11 -0700
Articles 9 — 9 participants

Back to article view | Back to comp.lang.python


Contents

  Design Pattern and Python: Any book recommendation? Your view? Anthony Kong <anthony.hw.kong@gmail.com> - 2011-11-03 17:33 -0700
    Re: Design Pattern and Python: Any book recommendation? Your view? Roy Smith <roy@panix.com> - 2011-11-03 21:46 -0400
    Re: Design Pattern and Python: Any book recommendation? Your view? Chris Rebert <clp2@rebertia.com> - 2011-11-03 19:15 -0700
    Re: Design Pattern and Python: Any book recommendation? Your view? Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2011-11-04 10:49 +0100
    Re: Design Pattern and Python: Any book recommendation? Your view? John Roth <johnroth1@gmail.com> - 2011-11-04 05:28 -0700
      Re: Design Pattern and Python: Any book recommendation? Your view? Joe Riopel <goon12@gmail.com> - 2011-11-04 08:41 -0400
    Re: Design Pattern and Python: Any book recommendation? Your view? Andrea Crotti <andrea.crotti.0@gmail.com> - 2011-11-04 12:46 +0000
    Re: Design Pattern and Python: Any book recommendation? Your view? Terry Reedy <tjreedy@udel.edu> - 2011-11-04 15:45 -0400
    Re: Design Pattern and Python: Any book recommendation? Your view? Ned Deily <nad@acm.org> - 2011-11-04 13:11 -0700

#15316 — Design Pattern and Python: Any book recommendation? Your view?

FromAnthony Kong <anthony.hw.kong@gmail.com>
Date2011-11-03 17:33 -0700
SubjectDesign Pattern and Python: Any book recommendation? Your view?
Message-ID<6097694.446.1320366784098.JavaMail.geo-discussion-forums@prap37>
Sorry to resurrect this topic. By google search the last discussion was in 2003.

I would like to find out what is the current prevailing view or consensus (if any) on the use of Design Pattern in python? 

I am doing some 'fact-finding' in this area on request of my colleagues. Some of them want to buy a book or two in this subject area. Hopefully the newsgroup can give me some book recommendation and insight in this topic.

I myself pretty much subscribe to the view that the nature of python language actually do away much of the need of the use of DP, but it is just a personal view. It comes form my experience of migrating from webware4py (webframework based on J2EE/servlet idea) to cherrypy


[toc] | [next] | [standalone]


#15317

FromRoy Smith <roy@panix.com>
Date2011-11-03 21:46 -0400
Message-ID<roy-8C6241.21465203112011@news.panix.com>
In reply to#15316
In article 
<6097694.446.1320366784098.JavaMail.geo-discussion-forums@prap37>,
 Anthony Kong <anthony.hw.kong@gmail.com> wrote:

> Sorry to resurrect this topic. By google search the last discussion was in 
> 2003.

What?  We're bring it up again, SO SOON!?


> I would like to find out what is the current prevailing view or consensus (if 
> any) on the use of Design Pattern in python?
> [...]
> I myself pretty much subscribe to the view that the nature of python language 
> actually do away much of the need of the use of DP

To a certain extent, I agree.  I don't have a huge amount of experience 
in Design Patterns, but have read (years ago) the obligatory Gang Of 
Four book.  My impression was that much of that book was about how to 
build sane data structures to do useful things given the uber-bondage 
constraints of the C++ and Java typing systems.

For example, let's look at Singleton.  It's a useful pattern.  Here's 
how I would implement Singleton in Python (hand-waving a bit about the 
syntax details):

class Printer:
   thePrinter = None

   @staticmethod
   def get():
      if Printer.thePrinter is None:
         Printer.thePrinter = Printer()
      return thePrinter

   def print(self):
      "print some stuff"
      whatever


That seems to cover everything Singleton needs to do.  In your 
application code, you do:

myPrinter = Printer.get()
myPrinter.print(....)

and you can sleep easy knowing you've got the same Printer instance 
every time.  The GoF version for C++ is filled with minutia about 
private constructors and assignment operators.  All that stuff is 
important to get right in C++, but it has nothing to do with Singleton, 
per se.  It's just all the gunk you have to worry about to correctly 
implement Singleton in C++.

[toc] | [prev] | [next] | [standalone]


#15318

FromChris Rebert <clp2@rebertia.com>
Date2011-11-03 19:15 -0700
Message-ID<mailman.2422.1320372912.27778.python-list@python.org>
In reply to#15316
On Thu, Nov 3, 2011 at 5:33 PM, Anthony Kong <anthony.hw.kong@gmail.com> wrote:
> Sorry to resurrect this topic. By google search the last discussion was in 2003.
>
> I would like to find out what is the current prevailing view or consensus (if any) on the use of Design Pattern in python?

I can only speak for myself, but the whole idea of design patterns is
broken. The existence of nontrivial design patterns indicates language
deficiencies. For more extensive corroborating discussions, see:
http://www.codinghorror.com/blog/2005/06/are-design-patterns-how-languages-evolve.html
http://c2.com/cgi/wiki?AreDesignPatternsMissingLanguageFeatures

Python thankfully has relatively few/minor deficiencies (so long as
one judges it within its dynamic language niche), so design patterns
per se aren't too relevant to it.

The canonical Python-specific design pattern is Borg
(http://code.activestate.com/recipes/66531-singleton-we-dont-need-no-stinkin-singleton-the-bo/
) [a variation on Singleton], and nowadays it (like its parent,
Singleton) is considered to be of dubious utility/advisability.

> I am doing some 'fact-finding' in this area on request of my colleagues. Some of them want to buy a book or two in this subject area. Hopefully the newsgroup can give me some book recommendation and insight in this topic.

The closest alternative would be some publication that gave examples
of using some of Python's fancier, higher-level features, such as
metaclasses and context managers. I haven't been in the market for
such a book, so I have no good recommendations to give. Closest I
could suggest would be the Language Reference
(http://docs.python.org/reference/ ) and relevant PEPs
(http://www.python.org/dev/peps/ ; they tend to include examples by
way of motivating use-cases).

> I myself pretty much subscribe to the view that the nature of python language actually do away much of the need of the use of DP, but it is just a personal view. It comes form my experience of migrating from webware4py (webframework based on J2EE/servlet idea) to cherrypy

I am glad you agree.

Cheers,
Chris
--
http://rebertia.com

[toc] | [prev] | [next] | [standalone]


#15331

FromUlrich Eckhardt <ulrich.eckhardt@dominolaser.com>
Date2011-11-04 10:49 +0100
Message-ID<j1pco8-5cn.ln1@satorlaser.homedns.org>
In reply to#15316
Am 04.11.2011 01:33, schrieb Anthony Kong:
> I would like to find out what is the current prevailing view or
> consensus (if any) on the use of Design Pattern in python?

My consensus with myself is that design patterns are language-agnostic. 
If I write "class Foo serves as view and controller for class Bar in a 
model-view-controller (MVC) design", everybody that knows MVC has 
immediately a very high-level understanding of how those two classes 
interact.


> I am doing some 'fact-finding' in this area on request of my
> colleagues. Some of them want to buy a book or two in this subject
> area. Hopefully the newsgroup can give me some book recommendation
> and insight in this topic.

The Gang of Four book on design patterns is one you will probably come 
across, and there are many that refer to it.


> I myself pretty much subscribe to the view that the nature of python
> language actually do away much of the need of the use of DP, but it
> is just a personal view. It comes form my experience of migrating
> from webware4py (webframework based on J2EE/servlet idea) to
> cherrypy

"webframework based on J2EE/servlet" - apart from J2EE being a specific 
implementation, this also describes a design pattern, i.e. one where 
(forgive me if I'm slightly off, this is not actually my field of 
programming) the UI is browser-based and the program logic runs on a server.

Instead of explaining it in many words, you reused the known design 
pattern to describe it, and that is also IMHO what design patterns are 
about. They serve as a tool to make software that follows known 
patterns, so that people that know the pattern will recognize them and 
then get easier understanding. It also serves as tool when talking about 
things, you don't have to explain the design when you can refer to a 
pattern.

In that sense, I fully disagree that design patterns are obsolete in 
Python. However, there are other patterns that are more 
language-specific, like e.g. RAII in C++, so if you rather meant those, 
I would agree with you.

Cheers!

Uli

[toc] | [prev] | [next] | [standalone]


#15339

FromJohn Roth <johnroth1@gmail.com>
Date2011-11-04 05:28 -0700
Message-ID<0531d3c1-61c6-41f6-a74a-fe3d24a731fb@x2g2000vbd.googlegroups.com>
In reply to#15316
On Nov 3, 6:33 pm, Anthony Kong <anthony.hw.k...@gmail.com> wrote:
> Sorry to resurrect this topic. By google search the last discussion was in 2003.
>
> I would like to find out what is the current prevailing view or consensus (if any) on the use of Design Pattern in python?
>
> I am doing some 'fact-finding' in this area on request of my colleagues. Some of them want to buy a book or two in this subject area. Hopefully the newsgroup can give me some book recommendation and insight in this topic.
>
> I myself pretty much subscribe to the view that the nature of python language actually do away much of the need of the use of DP, but it is just a personal view. It comes form my experience of migrating from webware4py (webframework based on J2EE/servlet idea) to cherrypy

I don't know of a book on design patterns in Python. I've got a couple
of observations.

The first is that if you use TDD (Test Driven Development) and
refactor relentlessly to remove duplication, most of the basic design
patterns will emerge naturally from the code as you work.

The second is that, as far as I'm concerned, the utility of a design
patterns book is in the discussion of what the pattern is good for,
and what it isn't good for. That is, as another poster says, language
agnostic.

John Roth

[toc] | [prev] | [next] | [standalone]


#15341

FromJoe Riopel <goon12@gmail.com>
Date2011-11-04 08:41 -0400
Message-ID<mailman.2430.1320410462.27778.python-list@python.org>
In reply to#15339
On Fri, Nov 4, 2011 at 8:28 AM, John Roth <johnroth1@gmail.com> wrote:
> The first is that if you use TDD (Test Driven Development) and
> refactor relentlessly to remove duplication, most of the basic design
> patterns will emerge naturally from the code as you work.

I agree, and there is a pretty good series of articles on
developerWorks that covers this:
http://www.ibm.com/developerworks/java/library/j-eaed2/index.html

The author used Java in this series, but as Ulrich mentioned, I feel
that design patterns (and emergent design) are "language-agnostic.".

[toc] | [prev] | [next] | [standalone]


#15342

FromAndrea Crotti <andrea.crotti.0@gmail.com>
Date2011-11-04 12:46 +0000
Message-ID<mailman.2431.1320410781.27778.python-list@python.org>
In reply to#15316
On 11/04/2011 12:33 AM, Anthony Kong wrote:
> Sorry to resurrect this topic. By google search the last discussion was in 2003.
>
> I would like to find out what is the current prevailing view or consensus (if any) on the use of Design Pattern in python?
>
> I am doing some 'fact-finding' in this area on request of my colleagues. Some of them want to buy a book or two in this subject area. Hopefully the newsgroup can give me some book recommendation and insight in this topic.
>
> I myself pretty much subscribe to the view that the nature of python language actually do away much of the need of the use of DP, but it is just a personal view. It comes form my experience of migrating from webware4py (webframework based on J2EE/servlet idea) to cherrypy
>
>
>

Well this book is work in progress
https://bitbucket.org/BruceEckel/python-3-patterns-idioms/src

but it actually looks very interesting

[toc] | [prev] | [next] | [standalone]


#15353

FromTerry Reedy <tjreedy@udel.edu>
Date2011-11-04 15:45 -0400
Message-ID<mailman.2445.1320435953.27778.python-list@python.org>
In reply to#15316
On 11/4/2011 8:46 AM, Andrea Crotti wrote:

> Well this book is work in progress

Though not touched since May 2009

> https://bitbucket.org/BruceEckel/python-3-patterns-idioms/src
>
> but it actually looks very interesting

The slightly older .pdf version is a bit bizarre as parts of both text 
and code are only half-translated from Java. The testing chapter 
contains obviously untested code like TestDemo.py [sic] with Java lines like
    id = ++objCounter  # this is supposed to increment objCounter
    TestDemo test1 = TestDemo('test1')
    # I presume this declares test1 as a TestDemo object
and text with Javaisms like *static*, *public*, *private*, *protected*, 
and *friendly* and "a little review of Java packages".

Perhaps the later sections are more useful.

-- 
Terry Jan Reedy

[toc] | [prev] | [next] | [standalone]


#15356

FromNed Deily <nad@acm.org>
Date2011-11-04 13:11 -0700
Message-ID<mailman.2448.1320437492.27778.python-list@python.org>
In reply to#15316
Search for presentations and videos by Alex Martelli.  He's the goto (so 
to speak) person on Python design patterns.  Here, for instance:

http://code.google.com/edu/languages/#_python_patterns

-- 
 Ned Deily,
 nad@acm.org

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web