I love how you're able to make content both informative without being too long! your instincts on project architecture are really helpful and easy to learn from.
Great video, Arjan. I love the great names used in the Order class. For instance, is_cancelled is a great example as it already tells the user that the result is a boolen. Using such intention revelaing names allows one to read code almost like written English sentences which is great for readability. I also like how the Order class demonstrates information hiding. Best wishes to the Netherlands from Austria :)
Great video as always! I would really love how your Git/project management process is. My small team and me always struggle with that. How do we handle branches. How much do we edit/add per branch. How to structure commits and so on. Stay healthy and a happy new year ;)
@@18something I thnik you are wrong. It is simple and easy and is being use all the time. Even when you use for loop on any iterator ex. tuple, list it is polymorphism.
Whew! I saw Arjan’s picture and then I saw a word in the title that my brain initially (mis)recognized as “emasculation” an’ I’m like, “Okay, Arjan, this better be good!” And then I looked at the title again.
My python is like my SOLID c#, glad I found this channel which sort of promotes more practices which are timeless (to a point) and apply to most languages. Main python guy at my place thinks pattern defeat the point of using python and regularly considers abstractions code debt ! Wtf.
In your opinion, should you use normal get and set methods in python, like the standard java way "get_name()". Or should you use the property() method or @property decorator as a more "pythonic" solution?
I like the property syntax a lot in Python, so I will generally use that instead of get_xxx and set_xxx methods. I think getters and setters are still useful, especially if the computation to be done is more complex. I tend to restrict using properties to things that are easily computed.
Python does allow you to restrict access. That's what __setattr__ and __getattribute__ do. You can also ensure that an object's variable doesn't get its access modified in an unintended manner by using metaclasses or having the parent class' attibute assignment overloaded so the super() call can't allow for an unintended mutation. For more complicated encapsulation, you can also use descriptors, which control how they themselves are accessed and modified when assigned a variable to a class.
Based on the contrived example, attempts to hide information without encapsulation seem to only occur as hacks (in the case given, I could imagine that code existing as part of a migration). Is that right?
Another way to look at this is that when you create a new class, you use information hiding to make the distinction between the public interface and the private implementation. When we design a new class we encapsulate together several elements. The encapsulated elements that are NOT hidden become the public interface. The elements on which you apply information hiding are not part of the interface, they become the implementation (Some would say the are private interface).
Is there a way to enforce it in python, other than essentially placing hints in the name? An IDE will surely give a warning when encapsulation is broken, but this isn't like C++ where the compiler enforces capsule integrity.
Unfortunately, there isn't. There are some ways to make it harder for the lib user, making them going through some hoops to direct access it. But effectively enforce that, not. At least not on the lib developer side. If an user is using internal code when they are not suppose to, and you update breaking the internal api, all the places that they are using it is going to break, and that's on them.
@@18something python changes the name, you can still access it. The name becomes _ClassName__member. That just make it obvious that you should not be accessing it. It is on the dev, which is using the lib, to be responsible and not use it.
The first 1,000 people to use this link will get a 1 month free trial of Skillshare: skl.sh/arjancodes01221.
It just feels wrong seeing python in vscode and and not seeing it colored with an explosion of semantic highlighting.
Cannot get a free trial without entering credit card details. :(
I love how you're able to make content both informative without being too long! your instincts on project architecture are really helpful and easy to learn from.
Glad you enjoy it!
thanks for sharing knowlege, and being a mentor for us
Great video, Arjan. I love the great names used in the Order class. For instance, is_cancelled is a great example as it already tells the user that the result is a boolen. Using such intention revelaing names allows one to read code almost like written English sentences which is great for readability. I also like how the Order class demonstrates information hiding. Best wishes to the Netherlands from Austria :)
Yep - making sure your function names are (almost) always verbs is good practice too.
Great video as always!
I would really love how your Git/project management process is. My small team and me always struggle with that.
How do we handle branches. How much do we edit/add per branch. How to structure commits and so on.
Stay healthy and a happy new year ;)
Good suggestion, thanks!
@@ArjanCodes I'd love that too! I'm only using git to learn the ins and outs of it but at the same time I have these exact same questions!
I love the star wars reference :)
Couldn't resist :).
God bless u. This is awesome.
Thx a lot from QA engineer from Russia:)
Glad it was helpful!
RUclips has to have a button of love it.
Awesome video as always! Polymorphism is the one that still gives me headaches with Python. Would love a video on it in the future.
Not easy to implement in python, you will need to overload the class methods
@@18something I thnik you are wrong. It is simple and easy and is being use all the time. Even when you use for loop on any iterator ex. tuple, list it is polymorphism.
There are four types of polymorphism in python:
1. Duck typing
2. Method overriding
3. Method overloading
4. Operator overloading
Whew! I saw Arjan’s picture and then I saw a word in the title that my brain initially (mis)recognized as “emasculation” an’ I’m like, “Okay, Arjan, this better be good!” And then I looked at the title again.
Lol, I watched a few of your videos from time to time. Only just realised that you were my professor a few years back!
My python is like my SOLID c#, glad I found this channel which sort of promotes more practices which are timeless (to a point) and apply to most languages. Main python guy at my place thinks pattern defeat the point of using python and regularly considers abstractions code debt ! Wtf.
Thanks Arjan! I would request about several ways implementing complex state machine (incl. substates).
This is so awesome.
Glad you enjoyed the video, Enrique!
Haha, I loved the Han Solo encapsulation!
In your opinion, should you use normal get and set methods in python, like the standard java way "get_name()". Or should you use the property() method or @property decorator as a more "pythonic" solution?
I like the property syntax a lot in Python, so I will generally use that instead of get_xxx and set_xxx methods. I think getters and setters are still useful, especially if the computation to be done is more complex. I tend to restrict using properties to things that are easily computed.
@@ArjanCodes That makes sense. Thanks for the reply! I really enjoy your videos, always very informative.
Python does allow you to restrict access. That's what __setattr__ and __getattribute__ do. You can also ensure that an object's variable doesn't get its access modified in an unintended manner by using metaclasses or having the parent class' attibute assignment overloaded so the super() call can't allow for an unintended mutation.
For more complicated encapsulation, you can also use descriptors, which control how they themselves are accessed and modified when assigned a variable to a class.
I have not understood descriptors till know. I read that they are what make quite a few things happen in python.
@@pranavnyavanandi9710 this + reflections
Would it be possible to define is_cancelled/is_paid as properties and cancel/pay as property setters? It that makes no sense?
Based on the contrived example, attempts to hide information without encapsulation seem to only occur as hacks (in the case given, I could imagine that code existing as part of a migration). Is that right?
Hello, another greate video! Can you recommend me a book that covers design principles in python? Thank you!
Hey Arjan, what are your thoughts on protected and private methods, variables, constants, etc on the *module* level? (for importable modules)
(if I follow the same rules consistently, I feel my code gets littered with underscores.)
Another way to look at this is that when you create a new class, you use information hiding to make the distinction between the public interface and the private implementation.
When we design a new class we encapsulate together several elements. The encapsulated elements that are NOT hidden become the public interface. The elements on which you apply information hiding are not part of the interface, they become the implementation (Some would say the are private interface).
Have the same glasses at home... coincidence?
Is there a way to enforce it in python, other than essentially placing hints in the name? An IDE will surely give a warning when encapsulation is broken, but this isn't like C++ where the compiler enforces capsule integrity.
You can use a linter such as Pylint to detect access violations
Unfortunately, there isn't. There are some ways to make it harder for the lib user, making them going through some hoops to direct access it. But effectively enforce that, not. At least not on the lib developer side. If an user is using internal code when they are not suppose to, and you update breaking the internal api, all the places that they are using it is going to break, and that's on them.
The __ means private and is hidden. You cant access that atribute
@@18something python changes the name, you can still access it. The name becomes _ClassName__member. That just make it obvious that you should not be accessing it. It is on the dev, which is using the lib, to be responsible and not use it.
@@juniorceccon yo mean "fortunately, there isn't."