Why Design Patterns are Rarely Used in Python

preview_player
Показать описание
In today’s short, I will explain why unlike Java/C#, there is a lack of design patterns in Python and how this influences your code.

🎓 Courses:

👍 If you enjoyed this content, give this video a like. If you want to watch more of my upcoming videos, consider subscribing to my channel!

👀 Code reviewers:
- Yoriz
- Ryan Laursen
- James Dooley
- Dale Hagglund

🔖 Chapters:
0:00 Intro

#arjancodes #softwaredesign #python

DISCLAIMER - The links in this description might be affiliate links. If you purchase a product or service through one of those links, I may receive a small commission. There is no additional charge to you. Thanks for supporting my channel so I can continue to provide you with free content each week!
Рекомендации по теме
Комментарии
Автор

Hi Arjan, I disagree with your thesis here. Design patterns are design elements that recur. They don't have to be Object Oriented. It's easy to find some of the patterns described by Gamma et al with Python incarnations, such as Wrapper, Factory, Observer, Iterator, etc (edit: Decorator also!). They may not always be implemented in OO terms, but they are still the same design concept.
I always find your vids enjoyable, and always learn something from them. Programmers should be like Jagger ... Never Stop, Never Stop (learning).
Kind regards, Andy
Programming since 1970 :-)

AndrewBlucher
Автор

depends what you're designing. in API design inheritance is powerful, so are classes generally. but a lot of python use cases are data oriented which clashes hard with OOP imo. I usually don't even use classes unless the complexity justifies it.

bonquaviusdingle
Автор

All my design pattern knowledge is learned from your videos, 2 years ago, I still remember after learning the template method and bridge pattern, I can read TensorFlow code(Layer and Model), which abstracting build and call method for subclasses to implement, and dependency reversion the loss object and metric object(actually a callable). Most of the ML objects has a __call__ method, which wraps up the machine learning procedures. the forward propagation step is just like a function call. It is pretty easy to understand the APIs and build your APIs if we can program both functionally and in the OOP way.

kiraflash
Автор

i definitely like using classes as a way of packaging methods which will not be used elsewhere and to define like an interface on how u should access the information.

i use classes for pipelining the code. do a simple compose and then throw everything through a run method, i find having to write this way makes reasoning about the code much simpler as it forces u to limit scope rather than having a large function. its also i find much easier to modify as there's like explicit separation thats labelled, idk :shrug:, also can be nice to abstract away ur datastore read/write so it's independent of whether snowflake, repo csv config, or databricks file store

ravenecho
Автор

Hmmm, i agree overeagerness for Gang of 4 can be a problem

Functionally with closures, i can implement any class structure. Like thats just partial

Within the ML space, what i find to be most problematic is interdependencies between functions, no interface for which methods to utilise, modification of internal methods with objects they shouldnt know about (especially runtime objects like database connections, or an embedding service)

I love functional, but the amount of map, filter, reduce, partial, chain is almost nonexistent to functions with 10 arguments repeated 30x and with no dirrect way to unravel the behavior except for step by step of removing each layer...

Imo: we need structs in python, and we need private method, a struct cannot be inherited

Functional is great, i love it, but i feel sometimes, when people say "functional" what they mean is no structure and u code urself into a corner and each change becomes harder. Theyre not considering the data as records of the same type. If theyre concerned about type at all

I mean were really talking about seperation, encapsulation, and indirection

Functional vs OOP id an implementation detail😅, or using the filesystem -- seems like to me, personally

ravenecho
Автор

Python has many frameworks that deal with data, like pandas, pyspark, torch DataLoader, hugging face datasets, they use a pattern, say I have a data container class, with many transform functions, each function returns subclass objects, such that the data transformation operations can be chained together. It is like a monad, or chain of responsibility, ...I don't know.... I hope you can talk about that in future videos. functionally and OOP.

kiraflash
Автор

The fact that design patters are seen a a dogma is something I really dislike about the programming community. It's not only design patterns tough, it is Corporate world <=> C#/Java/TypeScript <=> OOP <=> Design Patterns.

Robert-zchr
Автор

i dont really agree cose if it is how you are saying then we would not need design pattern in java 8+ thx to the functional interfaces but thata not always the case

Luca-reve
Автор

Do you recommend any books for design patterns in python specifically?

gubby
Автор

lets be honest, python has poor OOP (regarding advanced oop features and duck typing) and not so good FP. its procedural general purpose language :) its a glue language

cobpnqe
Автор

Aren't you also describing something that can be considered a design pattern?

mike
Автор

This is an extremely bad take on design patterns.

mulatto
Автор

There are still functional design patterns (Monads, meta-programming, etc), python just isn't a good enough functional language to expose these so you don't use them, and at the same time pythons class implementation is so bad you don't use OOP based design patterns - Python is truly the worst of all worlds

miningape