Комментарии:
When a project is modular for users to expand functionality of and eg. add new devices, or when someone new is getting into an existing project, won't protocols make it much less obvious what methods have to be implemented to fit a given interface, or even where said interface is located? When you encounter the code defining different strategies, unless a comment describes what it does, it might be impossible to know that it's meant to plug into any interface, sure it reduces coupling but it also makes code kind of hard to follow and make it ambiguous how to implement new algorithms/devices etc.
ОтветитьHello Arjan. Thank you for the quality of your videos and all the knowledge that you dissipate.
This video is from a year ago but you look younger (I prefer you old [😎])
Help me😂😂😂
ОтветитьI watched this video now a few times and it is really great. Now I have a question relying on the Interfaces: How would I visualize the optional diagnostic Interface in the UML (for example in mermaid)? I am on my way to understand design patterns and principles but this would be good to know for me. I also ask myself how to keep track of the different protocols in large projects (in my job we have a Django application with many….many apps)? If the question is too complex to answer maybe an idea for an advanced mermaid tutorial? ❤
Thank you for your great videos!!!
listened to this again for lunch and already applied protocols succesfully for the first time:)). thanks again Arjan.
ОтветитьI can't help thinking that Protocols leave the code less clear than ABCs. The ABC makes clear the relationship between the classes whereas Protocols leave it so decoupled that you might not even realise/remember in what ways you can use certain classes and methods together. Is this just the point?
ОтветитьThe best channel for Python design principles.
ОтветитьIt is funny to see how strongly Python claim to be a pure OOP language, and being slow at enhancing its OOP features. Great content and great channel!
ОтветитьReally good explained. It's given me some good piece of advice for an app I'm refactoring.
ОтветитьWhy do dutch people speak great English ? they speak dutch, dont they ? not English always make me wonder
ОтветитьI'll have to watch the video a couple more times, but it's brilliant stuff. You explained it so well I can't thank you enough.
ОтветитьHi @arjanCodes, I'm curious to know what course you provide includes the amazing video, Protocol Or ABC In Python - When to use which one?, I just watched above. Is this part of "The Software Designer Mindset" course?
ОтветитьI can understand how Abstraction is a blueprint of a blueprint (class), but when I read on the Google, it always stated stat abstraction is an act to hide the context of a method and hide the complexity from the user.
But, I can't understand which part is exactly "HIDE" the complexity from the user?
And from whom exactly we want to hide?
Hope anyone can explain this.
Bring back the letterboard!!!
ОтветитьHi Arjan, glad to find this lecture, love it. Ty!
ОтветитьDont stress about the letterboard. Its small stuff. People come back to you because of your helpful content and good attitude, not your letterboard. X3 you can fill those roles any number of ways.
Ответитьתודה!
ОтветитьSo.... a protocol is just an interface. Python, why do you make it so hard?
ОтветитьI don't get all the fuzz about Python Protocols. Really.... It seems like a completely unecessary formalisation of what has been known for decades as 'duck typing'. In fact this whole 'Typing' thing introduced a few years ago seems to be pushing python towards such a boring Java-esque reality that doesn't really fit with the language (and the Zen of Python) and to compesate for that they just keep adding more and more beaureaucracy on top of it like this 'Protocol' BS. Practically, nobody needs that in Python and absolutely 100% of programs written employing the concept of Protocols could have been written without it (and not with a great deal of difference).
ОтветитьWhy multiple inheritances would be required if instead of protocol one decides to use Abstract Base Classes? Couldn't I just have the same 2 separate ABC classes (Device & DiagnisticSource) and then simply have their own concrete subclasses and use objects of those concrete subclasses as you did there?
Ответитьwhat are the diferences between pass and ... in the current examples?
ОтветитьWith all due respect for people from the Netherlands, I've never met or watched anyone who comes from there that's actually funny. I have a great respect for their intelligence and abilities in other areas. It's why I watch this channel.
You don't need to try and be funny or witty because it's doesn't work for you anyway. It just wastes time. Yours and ours. Just sayin'.
All other issues aside, are there any performance issues between the two methods. Are the method arguments checked each time the methods are called? Thanks
ОтветитьThanks
ОтветитьThanks, great video! What about Sphinx dealing with Protocol?
ОтветитьThere's nothing wrong with multiple inheritance and this is precisely the kind of situation where it's useful. The decision between structural and nominal typing should be one of interoperability: do you want classes that implement the required interface to work with your code, or would you like to keep things controlled and open access only to those that explicitly opt in? You may want different things in different cases.
ОтветитьA truly excellent video, as always, you've gone way above and beyond simply explaining the concept, and outlined excellent use cases and way of thinking to know when to pick which one. thanks again, Arjan :)
ОтветитьThe part I found the most impressing was how you used your IDE to edit the code, mostly with shortcuts.
ОтветитьBoth useless to me. But, I like the video!
Ответитьi have interface created in python using protocol but when i click to any method in vs code it does not open main method but it opens method in protocol / interface class, how can i click to open main implementation instead of interface ?
ОтветитьThanks again for your very helpful video which explains the differences between protocols and ABCs.
ОтветитьGreat demonstration, thanks for sharing!
ОтветитьFrom experience.
It seems protocols are for objects you do not control and ABCs are for objects you do control.
Example.
how do you type hint an sql connection?
It can be SQLite or Postgres or MYSQL. libraries.
You can type the the connection as a protocol of the methods you use instead of the concrete connection
I really feel like ABC is completely useless.
You can juste create a class with methods filled with "NotImplementedError" and use it as a base class without ABC
So how can you tell some class implements some protocol? Sure, you can inherit the protocol explicitly, but then you're back to ABCs. It's the same issue I have with Go's interfaces.
ОтветитьEdit: I wrote my comment before playing the video up to the end, where Arjan mentions both ISP and Uncle Bob. But I decided to leave the comment as is. Anyway, good job Arjan!
What happens here when Device abstract base class was replaced by two protocols seems like "I." from "S.O.L.I.D." principles. Namely "ISP = Interface Segregation Principle".
And hey, Python allows doing that without too much strict typing, but rather with "duck typing"!
Depending on the case this may be handy. And sometimes when more info is necessary when implementing a new class (to avoid mistakes ofc.) - would be to stick to ABC. Anyway, thanks for informative video 👍
In the protocol code, if I implement the device class as a normal colon 'class Device:' instead of 'class Device(protocol)'. The code can still run without any issue. Besides the IDE don't do static typing check before running. Then why we use the 'from typing import Protocol' library?
ОтветитьProtocols are mirrored by Type Classes in functionsl programing
Type classes are a powerful feature in functional programming that can help solve the expression problem of adding new types to which existing operations apply.
In functional programming, the expression problem refers to the challenge of adding new functionality to existing code without modifying that code. This is particularly difficult when dealing with types, as adding a new type often requires modifying existing code to support it.
Type classes provide a solution to this problem by allowing you to define a set of operations that can be applied to any type that implements the type class. This means that you can add new types to your code without modifying
existing code, as long as those types implement the required operations.
For example, let's say you have a type class called `Printable` that defines a single operation called `print`. Any type that implements the `Printable` type class can be printed using the `print` operation. Now, if you want to
add a new type to your code that can be printed, you simply need to implement the `Printable` type class for that type. You don't need to modify any existing code that uses the `print` operation.
Content was so useful for me. but I have one question. As you mention the protocol is the natural way in python. Why we can not have interface for each of instance of each protocol. In your Device abstraction class some how we can say that you violate interface segregation in SOLID principle. Somehow in Protocol some of the dependencies are hide ?
Ответитьwhat I am worried about is less readability of the code with protocols , with abstract classes and inheritance it is easier to trace routes where everything is going and from where it is extracted.
ОтветитьGreat tutorial, quick question what font are you using on your IDE
ОтветитьDear Arjan, great thanks for your videos. That is one of the few channels that really help me upskill as a hobbyst python dev
Ответитьoh man... there was a letter board this whole time!? I am excited for the replacement jokes :D
Ответитьwhoa... i thought protocals were just a fancy way to annotate the type of a variable or parameter containing a function... by typing the _call_ method of the protocal you can do some things that the typing.Callable[...] syntax can't (or maybe thats fixed now?)... This is a much more sane use of protocals. Thankyou for the excellent video as always, you are amazing at explaining clearly!
ОтветитьIt's a shame, today I got that an entire word can be deleted at once in VSCode. Ctrl+Delete, Ctrl+BackSpace btw.
ОтветитьWhen your solid samples and easy to understand explanation combines, content inevitably becomes perfect
Ответить