473,672 Members | 2,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

do design patterns still apply with Python?

Since Python does so many things different, especially compared to
compiled and statically typed languages, do most of the basic design
patterns still apply when writing Python code? If I were to read a
design pattern book (such as Head First Design Patterns), could I apply
their Java examples to Python easily enough, or does Python require a
different perspective when applying patterns?
Mar 2 '06 #1
24 2092
Hi John.

Design patterns aren't tied to any specific implementation so they
should apply to any language. You might find that they can even apply
to solution domains outside of computer science.

Implementation details will usually differ between languages. But the
implementation can also be different using the same language. For
example, you can use Java to implement the Model View Controller design
pattern when writing a web site or when writing a database engine --
the implementation will be very different, but both will be MVC.

In python, you might find it more natural to do design patterns in a
completely different way than they're implemented in Java. For
example, I've heard of using the Singleton pattern in python by just
implementing it as a module, no classes necessary.

sjbrown

Mar 2 '06 #2
sh******@gmail. com wrote:
In python, you might find it more natural to do design patterns in a
completely different way than they're implemented in Java. For
example, I've heard of using the Singleton pattern in python by just
implementing it as a module, no classes necessary.

Yeah, that's what I was wondering. I wonder if, after reading a DP book,
I might have to 'unlearn' some things when applying them to Python. But
I suppose I should just do it first and then try to implement them
myself. OOP is just so mind-bending for me that I've kind of put off
patterns right now until I get more comfortable with it. :)
Mar 2 '06 #3
On 2006-03-02, John Salerno <jo******@NOSPA Mgmail.com> wrote:
Since Python does so many things different, especially compared to
compiled and statically typed languages, do most of the basic design
patterns still apply when writing Python code?


Definitely. Especially plaid, paisley, and a nice medium
houndstooth check. But please, not all at the same time.

--
Grant Edwards grante Yow! Maybe we could paint
at GOLDIE HAWN a rich PRUSSIAN
visi.com BLUE --
Mar 2 '06 #4
In article <8S************ ******@news.tuf ts.edu>,
John Salerno <jo******@NOSPA Mgmail.com> wrote:
Since Python does so many things different, especially compared to
compiled and statically typed languages, do most of the basic design
patterns still apply when writing Python code? If I were to read a
design pattern book (such as Head First Design Patterns), could I apply
their Java examples to Python easily enough, or does Python require a
different perspective when applying patterns?


Many of the classic design patterns apply just fine to Python, at least in
the high-level view. On the other hand, much (most?) of what's in the
classic design pattern books is so tied up with ways around C++/Java type
bondage, it's difficult to see the forest for the trees.

For example, take the most classic of all patterns, Singleton. A typical
C++ Singleton treatment will be all about making constructors private and
shit like that. None of that carries over to Python. What I would do in
Python is have a module-level factory function which caches a single
instance of the class to return to the 2nd and subsequent caller and not
get my panties in a twist over the fact that some clever programmer could
find away around my code and force creation of a second instance.

The basic concepts in the pattern books are worth knowing. You just have
to be able to tease apart the concepts from the language-specific cruft
that so often obfuscates the descriptions.
Mar 2 '06 #5
John Salerno wrote:
Yeah, that's what I was wondering. I wonder if, after reading a DP book,
I might have to 'unlearn' some things when applying them to Python.
I would say adjust instead of unlearn. This is probably true to a
lesser or greater extent of any language for which your DP book was not
written.
But I suppose I should just do it first and then try to implement them
myself. OOP is just so mind-bending for me that I've kind of put off
patterns right now until I get more comfortable with it. :)


I would suggest getting a good grasp on OOP before you get into design
patterns. When most people start with any new concept they tend to try
and see everything in terms of their new toy, so sticking to one or two
new concepts at a time will make things a little easier.

Design patterns are kind of like sarcasm: hard to use well, not always
appropriate, and disgustingly bad when applied to problems they are not
meant to solve. You will do just fine without them until OOP is at
least familiar to you, and by that time you should be a little better
able to use them appropriately.

Mar 2 '06 #6
On Thu, 02 Mar 2006 16:38:44 -0500
Roy Smith <ro*@panix.co m> wrote:
In article <8S************ ******@news.tuf ts.edu>,
John Salerno <jo******@NOSPA Mgmail.com> wrote:
Since Python does so many things different, especially
compared to compiled and statically typed languages, do
most of the basic design patterns still apply when
writing Python code? If I were to read a design pattern
book (such as Head First Design Patterns), could I apply
their Java examples to Python easily enough, or does
Python require a different perspective when applying
patterns?

[...]
The basic concepts in the pattern books are worth knowing.
You just have
to be able to tease apart the concepts from the
language-specific cruft that so often obfuscates the
descriptions.


This sounds like an article crying out to be written,
"(Learning) Design Patterns with Python".

Has it been written already?

Cheers,
Terry

--
Terry Hancock (ha*****@Anansi Spaceworks.com)
Anansi Spaceworks http://www.AnansiSpaceworks.com

Mar 2 '06 #7
John Salerno <jo******@NOSPA Mgmail.com> writes:
Since Python does so many things different, especially compared to
compiled and statically typed languages, do most of the basic design
patterns still apply when writing Python code? If I were to read a
design pattern book (such as Head First Design Patterns), could I
apply their Java examples to Python easily enough, or does Python
require a different perspective when applying patterns?


I'd say the relative importance of particular patterns depends on
whether the problems it solves are easier or harder in the language
you're using. Many things that are difficult in Java are easy in
Python, so the patterns in the book aren't terribly relevant.
Somewhat less often, something is easy in Java and difficult in
Python. When that happens, you may need approaches that aren't in the
book. Finally, you have to think of all of these books as different
approaches of explaining elephants to blind men. There's a lot of
murkiness in programming and design patterns are yet another way to
help guide people through it. But the more programming you do, the
better your own internal maps and instincts become, and the less you
need a guidebook that doesn't always correspond to the actual
landscape you're operating in. So consider the books to contain
helpful guidelines but don't feel afraid to trust your own instincts
over them, especially after those instincts become better developed.
Mar 3 '06 #8
In article <7x************ @ruckus.brouhah a.com>,
Paul Rubin <http://ph****@NOSPAM.i nvalid> wrote:
Somewhat less often, something is easy in Java and difficult in
Python.


Example?
Mar 3 '06 #9
Roy Smith <ro*@panix.co m> writes:
Somewhat less often, something is easy in Java and difficult in
Python.

Example?


Sandboxed code is a real obvious one.
Mar 3 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2863
by: Tony Ha | last post by:
Hello I am learning Python for in the pass ten months, and have brought a few books about Python. Most of them are good books by its only right, and all of them only teach you how to write Python programs using Python syntax and Python ways, but no one single Python book explicitly teaches you on how to analyst your application, and structure your programmes in a way, so that, it is easy to maintain, easily to reuse, (i.e. use loosely...
4
1983
by: Ian Giblin | last post by:
I am an experienced C programmer, learning C++ by writinging a mathematical toolkit in the framework of a script interpreter. I am posting here to ask for advice (or references) on the object design and implimentation. Currently I have a portable "ScriptSession" class which contains the mechanics of looping with a user prompt, parsing a sentence and handling syntax errors, etc., and I wan this to be a class I can use for any script...
1
2370
by: Jay | last post by:
The GOF text is widely considered the definitive book on the topic. Design Patterns: Elements of Reusable Object-Oriented Softare, Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides Note, all the examples are in C++ but you can get through them with a little work.
1
1874
by: Josh28 | last post by:
Hi We are a group of two chaps just out of undergrad, we created a software to automate the use of Design Patterns. We have put it up at Source Forge--http://dpatoolkit.sourceforge.net/ The software has been designed using the .NET framework and coded in C#. The patterns can be stored as plug-ins in XML, adding any number of attributes like Intent, Behavior and the like... Class
12
4699
by: Jean-pierre Martineau | last post by:
how apply design patterns to c ?
6
4700
by: Daniel Santa Cruz | last post by:
Hello all, I've been trying to go over my OO Patterns book, and I decided to try to implement them in Python this time around. I figured this would help me learn the language better. Well, I've gotten stuck with my first go at OO patterns with Python. I guess it goes without say that some of the stuff that are taken for granted in most of the books (ie. Interfaces, Abstract classes) don't really apply to Python per say, but the idea...
6
1960
by: Gabriel Genellina | last post by:
Hello Most authors talk about Java/C++, and describe patterns used as a workaround to their static class model; the dynamic nature of Python allows for trivial implementations in some cases. I've seen some design patterns examples on the ActiveState site, and some discussions some time ago on this list. But does anyone know of a complete discussion/analysis of patterns in Python? Books, articles, web pages... Unfortunately the...
19
1742
by: adriancico | last post by:
Hi I am working on a python app, an outliner(a window with a TreeCtrl on the left to select a document, and a RichTextBox at the right to edit the current doc). I am familiarized with OOP concepts and terms but I lack practical experience
10
3659
by: vital | last post by:
Hi, I am designing the middle tier of a project. It has 6 classes and microsoft application data access block. The six classes are DBServices, Logger, ProjectServices ... etc. and all these classes talk to front-end directly. Do I need to use any design pattern in this? or what kind of design pattern is this?
0
8498
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8940
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8630
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8694
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6251
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5718
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4237
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4434
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2084
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.