Remove links to Python design patterns repository#994
Remove links to Python design patterns repository#994spookylukey wants to merge 1 commit intovinta:masterfrom
Conversation
Replace with link to video showing why patterns are unnecessary.
mblomdahl
left a comment
There was a problem hiding this comment.
Thanks for opening the PR!! I'm so sick and tired of Java developers shoehorning "Java complexity" into Python projects. 😸
|
@spookylukey I'm a few years late on this but as the creator of PyPatterns... I actually agree completely. I created the project a long time ago when I was fairly new to programming and only had classroom experience with Java and all the design patterns that come with it. I kind of regret making the repo for exactly the reasons you stated. I might add a deprecated disclaimer to the repo so people stop using it, but yeah I would be in agreement that it should be removed from this list. It promotes python anti-patterns and should never have been added in the first place. |
|
@tylerlaberge kudos to you for a comment like that, especially when I probably should have expressed myself quite a lot gentler than I did! (I couldn't find a decent 'kudos' emoji...) |
23abd09 to
40cd98b
Compare
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Replace with link to video showing why many patterns are unnecessary.
In my opinion, the linked repos (python-patterns and PyPatterns) are really unhelpful ways of thinking about patterns in Python - they are anti-patterns in Python, and not something that should be promoted.
Basically, most of the patterns popular in Java world are "invisible or simpler" in dynamic languages like Python (according to Peter Norvig - http://www.norvig.com/design-patterns/ ). This is due to:
template-method, visitor)
Of the two links, PyPatterns is the worst, and actually encourages importing a library to get functionality that only increases the amount of code you have to write. I see that it was added because someone wanted something they could actually
import. However, this comes from people thinking in Java - but Python is not Java without the compile. There is negative value in using this kind of repo - Python makes the pattern invisible or simpler, by adding an import and base classes you have only made life hard for yourself.For example, Factory and Abstract Factory pattern:
https://github.com/tylerlaberge/PyPattyrn#factory-pattern
https://github.com/faif/python-patterns/blob/master/creational/abstract_factory.py
Once you understand that Python has first class types, these become totally pointless.
Here is a class in Python:
And here is a factory for it:
(
Ais it's own factory - when you call it, it produces an object of type A. There is nonewkeyword in Python.)And here is a factory that you can assign to a variable, or pass as an argument to a function/method:
(First class types.)
And here is a factory if you wanted to create
Ain a non-default way:Or, in a builtin-standard-but-non-default way
These are the idiomatic ways to do these things. If you are writing anything more than that, you are doing it wrong.
Even when the pattern is bigger than invisible, its implementation is often massively simpler in Python. The linked repositories often use classes with no state and a single method. This is pointless - we should be deleting such classes and replacing them a single callable - see Stop Writing Classes
PyPatterns even includes an implementation of iterator and iterable - when these are built in to Python!
I was going to submit PRs to the linked repositories, but most of the PRs would involve deleting 90% of the code, which is unlikely to be accepted, I thought it better to submit this PR first.