Slots can also help you avoid certain types of bugs. For instance person.addres = "abc" becomes an error because "address" was misspelled. Vanilla classes will accept this input without any error leaving you to figure out why the address field wasn't changed as intended.
I actually had that error inside my code for such a long time undiscovered. Recently I found it while reforming the code. Now I'm using slots and it can prevent that kind of mistakes. Thanks to Arjan and Edmunds!
It is nice to see new videos about python but it's coming unactual more as there are a bunch of video curses about python. I very like your videos about project architecture and the unique code examples that you were using. I would really like to see in your channel videos about UML diagrams, project file structure, documenting packages and modules, design patterns that you haven't talked about them yet, etc. Thanks for your job.
I second the opinion that the most interesting videos are that teach us how to reduce coupling in the code by using design patterns and how to make python projects that are scalable.
This is a great feature. Dynamic members is like loose typing: it sounds great as a beginner developer, but as a more experienced developer it's more often a headache
Even as a experienced dev, dynamic attributes and pretty much non existent boilerplate code seriously helps in prototyping or testing out risky features(risky in terms of feasibility). But other than that of course these should be avoided like the plague
When you said "with a single line of code" I thought, "It's going to be slots, isn't it?" but I kept watching anyway because I like how you explain stuff and I thought that I was going to learn something anyway, and I'm not disappointed. Just commenting to let you know that I trust in the quality of your videos, and you deliver. Cool setup BTW.
Amazed that nobody has questioned using the lower bound rather than an average metric, or plotting the distribution of the different runs. It's not clear that a lower minimum translates into general better performance in most cases, especially a "20%" difference. Having said that, this was an interesting video. Might run some of those tests myself.
Same thing I was thinking! Typically I like to see min, mean, and max. And if I'm trying to convince a coworker my way is better then I just take the best one. 😁
I felt so certain that this was just going to be clickbait but honestly it just makes so much sense and I can't believe I didn't know about this before now.
Sweet new set! Just a little feedback: I would love to see a little bit of graphics/illustrations/diagrams sprinkled in the explain-to-camera sections. When there is a visual complement to the topic/explanation at hand I just can't help but feel more engaged in the discussion. Fireship on RUclips has mastered this technique in place of appearing on camera at all (which I'm certainly not suggesting). SciShow is another excellent example of this technique in action. I suppose news broadcasts had this figured out from the start. Anyhow, food for thought at least and thanks for another great python video.
I can see that you are proud of your new studio/office - and you should be! One aspect of inheritance with slots that you didn't mention, and that I am unsure about: how do you add new attributes in a class that inherits from a class with slots? Do you have to declare __slots__ again in the subclass?
I was recently told about slots on an SO question that I'd answered, and was quite confused by the concept until now. This was a fantastic explanation - thank you! A big +1 for touching on inheritance (was my largest concern as I was watching).
The sofa set (0:54) has a lot of potential for you to add animations to explain what you're talking about. Like sketches/code snippets that illustrate.
Dataclass is truly a powerful structure in python. I'm really looking forward to learning more tips and tricks to make the python code faster. This tutorial is helpful. Thanks a lot!
I like dat you are trying to be like other youtubers wid d lights in BG n all. But i subscribed your channel solely for the knowledge u share. Yes, the setup is good, but honestly I loved your setup with a straight up facing camera.
Great video! I wonder if micropython and circuitpython support slots at all. Python on microcontrollers can use all the performance help and this is something most people wouldn't even know about.
Thanks @ArjanCodes. Unfortunately I have not yet seen your free 7-step guide? I have signed up at the link you indicate and even purchased some of your courses by I haven't found this elusive guide, lol. Please help.
Congrats on the new studio/office, Arjan! Looking good. Good to see the contents don't suffer the even better look. Still very informative! Love it. Kappertje gepakt trouwens?
I think you could add a translucent rectangle code graphic inset under the shelf light or something, on the left at 1:00 that could help show the code structure of the very things you're talking about, would work really well
Nice setups!! The changing light in the first setup was a little distracting, but the other setups were perfect. Also, thanks for sharing how slots work, its limitations, and providing a real-life example of a tool using slots. Very informative!
Very nice...as usual. It seems like another advantage of using slots would be to catch spelling errors in your classes' attribute names. For example, without slots, the statement myPerson.namee = "Joe" would work fine, but myPerson.name would not be affected. But using slots, the statement would raise an error: 'Person' object has no attribute 'namee' which would let you find and fix the spelling error much sooner.
Hey Arjan! I have been watching your videos and i have a question that i could not find a clear answer to. Is there a reason to NOT use dataclasses? It really seems to be the cleaner approach to managing and writing your classes but are there reasons to pick normal classes over them? Great content by the way! Loving your channel.
In Go, you can "compose" several structs in a bigger struct, and get convinience of multiple inheritance, without inheritance at all. But in Python, sometimes the only way to make your class smaller is to use multiple inheritance. I think in some ways, Go is a better Python than Python (based on the Zen of Python).
Awesome new setup Arjan! If I'm very nitpicky (but that's not a thing I would ever be) then I'd say the programming view could use a bit of fill light for the right side of the face. But quite an awesome step up already. And besides that, another excellent video. Keep it up!
Nice video! A great way to better show the value of variables is with 'from rich import print'. It automatically highlights types and emphasizes structure.
The videos are amazing! I like the way you explain things. It is easy and fun to follow. I always find something useful even if I know the topic and recommend your videos to my colleagues because they are so informative. The way you present inspires me when I do my presentations. The new setup is very nice!
Hello Arjan. Could you tell about different way to implement class which inherits over employee and person? I agree that multiple inheritance may be bugggy, but how to solve that in a clean and efficient way?
Answering as a sr dev here - try thinking in terms of composition instead of inheritance. Inheritance implies an "is a" relationship. A Square "is a" Shape. Composition implies a "has a" relationship. A vehicle "has a" steering wheel, brakes, and headlights. Its very rare that you will find yourself with the need to describe W "is a" X, Y, and Z. Hope this makes sense. There are others who can explain it way better - just search "prefer composition over inheritance" - it is a well-known axiom amongst experienced OO developers. Edit: As a nice side effect to using composition over inheritance, you'll find your unit tests easier to implement because you'll be in a good position to leverage dependency injection and provide mocks for the dependencies rather than having to mock any dependency chains of your parent class(es).
4:50 if they make the attributes static, then, they are very different from using self.var, which are NOT static but instance based. Person in your example doesnt make sense then because if they are static, you cant have 2 different persons because they will both have the same data.
I don't mean static in the sense of them being static variables, but static in the sense that the list of attributes in an object of that class is static: you can't dynamically add new attributes like you can if you don't use slots.
@@ArjanCodes then i'd say "the number of attributes is fixed if using slots, unlike normal classes". I think that better conveys what you mean without adding confusion with other programming terms
Wasn't able to replicate this example using python 3.10.4, for some reason TypeError: dataclass() got an unexpected keyword argument 'slots' and TypeError: unsupported operand type(s) for |: 'type' and 'type' ~ from the get_set_delete function
Hey, @ArjanCodes! Can you please explain why you use `partial` in your time measurements? From what I've found, using `partial` may save an overhead compared to `lambda`. Is this the purpose you used it here, in your code?
After python 3.11 the benefits of using slots on performance is very low as far as I can see, but you are still saving memory. That's not a bad thing for object you create a lot of instances of.
Honestly, this is the first time I see slots, but I have a question. Does performance grow for get, set and delete evenly or some of them has a bigger contribution? Thanks you for the video!
Hi Arjan, love your videos! Just one little note. Wouldn't it be a better measure to use the average performance, than the minimal one? At least I'd be more interested in the average difference in performance ;) Cheers!
Hello Arjan, great video as always! I would like to ask you. I want to use the super initialyzer in a child class. That is something achievable using dataclasses? Should I explicitly declare the __init__ method? If this is the case, I will lost the syntactic sugar of using dataclasses. Thank you so much!
Hi Matias, what you can do is add a dunder post_init method to your child data class and call super from there. That way, you can still let dataclass generate the init method.
4:17 ( __slots__ = "name", "address", "email" ) that's not a list. that's a tuple instead! That would be a list ( __slots__ = ["name", "address", "email"] )
Hey ArjanCodes, is it true that the main reason for UML diagrams exists is to provide jobs in the tech industry for non-tech people like trainers/coaches etc.?
💡 Get my FREE 7-step guide to help you consistently design great software: arjancodes.com/designguide.
Slots can also help you avoid certain types of bugs. For instance person.addres = "abc" becomes an error because "address" was misspelled. Vanilla classes will accept this input without any error leaving you to figure out why the address field wasn't changed as intended.
that I think is actually the main advantage when building serious applications
If you have read/write properties on a class, specifying slots is a very good idea.
I actually had that error inside my code for such a long time undiscovered. Recently I found it while reforming the code. Now I'm using slots and it can prevent that kind of mistakes. Thanks to Arjan and Edmunds!
It is nice to see new videos about python but it's coming unactual more as there are a bunch of video curses about python. I very like your videos about project architecture and the unique code examples that you were using. I would really like to see in your channel videos about UML diagrams, project file structure, documenting packages and modules, design patterns that you haven't talked about them yet, etc. Thanks for your job.
I second the opinion that the most interesting videos are that teach us how to reduce coupling in the code by using design patterns and how to make python projects that are scalable.
Totally agree on that. Also if performance is a problem, just avoid python.
Thanks & no worries - there will definitely be more of those videos in the future.
Yes!! Project structure, program flow design, design patterns, etc would be great!! Same with UML stuff, I’d love some in depth videos on any of these
This is a great feature. Dynamic members is like loose typing: it sounds great as a beginner developer, but as a more experienced developer it's more often a headache
Even as a experienced dev, dynamic attributes and pretty much non existent boilerplate code seriously helps in prototyping or testing out risky features(risky in terms of feasibility). But other than that of course these should be avoided like the plague
Thanks! Find ways to keep delivering value like this. Thank you
Thank you, will do!
When you said "with a single line of code" I thought, "It's going to be slots, isn't it?" but I kept watching anyway because I like how you explain stuff and I thought that I was going to learn something anyway, and I'm not disappointed.
Just commenting to let you know that I trust in the quality of your videos, and you deliver. Cool setup BTW.
Thanks!
Thank you Valentyn, glad you liked it!
Danke!
Thank you, Marcel!
Thank you for your videos. I learned a lot from them and I also like the entertainment factor of your videos.
Thank you so much - glad to hear the videos are helpful to you!
Amazed that nobody has questioned using the lower bound rather than an average metric, or plotting the distribution of the different runs. It's not clear that a lower minimum translates into general better performance in most cases, especially a "20%" difference.
Having said that, this was an interesting video. Might run some of those tests myself.
Same thing I was thinking! Typically I like to see min, mean, and max.
And if I'm trying to convince a coworker my way is better then I just take the best one. 😁
the lower minimum is the most accurate measurement to take
@@fjolublar why is it the most accurate?
I felt so certain that this was just going to be clickbait but honestly it just makes so much sense and I can't believe I didn't know about this before now.
Sweet new set! Just a little feedback: I would love to see a little bit of graphics/illustrations/diagrams sprinkled in the explain-to-camera sections. When there is a visual complement to the topic/explanation at hand I just can't help but feel more engaged in the discussion. Fireship on RUclips has mastered this technique in place of appearing on camera at all (which I'm certainly not suggesting). SciShow is another excellent example of this technique in action. I suppose news broadcasts had this figured out from the start. Anyhow, food for thought at least and thanks for another great python video.
Thanks for the suggestion Jake, I agree that would be helpful!
I can see that you are proud of your new studio/office - and you should be!
One aspect of inheritance with slots that you didn't mention, and that I am unsure about: how do you add new attributes in a class that inherits from a class with slots? Do you have to declare __slots__ again in the subclass?
I was recently told about slots on an SO question that I'd answered, and was quite confused by the concept until now. This was a fantastic explanation - thank you!
A big +1 for touching on inheritance (was my largest concern as I was watching).
The sofa set (0:54) has a lot of potential for you to add animations to explain what you're talking about. Like sketches/code snippets that illustrate.
Good suggestion! I definitely want to explore animations to improve the clarity of the videos.
Great new studio and very interesting topic. Well done
I'm liking the new setup Arjan. Super clear video and great sound.
Love your new Studio.
Dataclass is truly a powerful structure in python. I'm really looking forward to learning more tips and tricks to make the python code faster. This tutorial is helpful. Thanks a lot!
Love the new recording setup! Thanks for the content and hope you get to 100k subscribers soon.
Thanks David!
I like dat you are trying to be like other youtubers wid d lights in BG n all.
But i subscribed your channel solely for the knowledge u share.
Yes, the setup is good, but honestly I loved your setup with a straight up facing camera.
Loving the new setup! This explains slots really well, and I might just remember to use them next time I write a class haha.
Thank you so much, Arjan, great lesson. It improved my code performance a lot.
Glad you liked it!
Superb as always. Thumbs up
Great video! I wonder if micropython and circuitpython support slots at all. Python on microcontrollers can use all the performance help and this is something most people wouldn't even know about.
Thanks @ArjanCodes. Unfortunately I have not yet seen your free 7-step guide? I have signed up at the link you indicate and even purchased some of your courses by I haven't found this elusive guide, lol. Please help.
Congrats on the new studio/office, Arjan! Looking good. Good to see the contents don't suffer the even better look. Still very informative! Love it.
Kappertje gepakt trouwens?
I think you could add a translucent rectangle code graphic inset under the shelf light or something, on the left at 1:00 that could help show the code structure of the very things you're talking about, would work really well
Nice setups!! The changing light in the first setup was a little distracting, but the other setups were perfect. Also, thanks for sharing how slots work, its limitations, and providing a real-life example of a tool using slots. Very informative!
Really liking the new setups! Your face in the coding setup had a lot of shadows on it though, so it wasn't very clear
I like the new setup, refreshing - good job!
Hey Arjan, congrats to your new setup! Looking forward to achieving 100k subs 👍
Thank you Ali!
The shirt seems a little formal :D but the new recording setup looks dope!
Haha, yeah I thought let’s change things a bit for fun. Next time, back to hoodies & simple shirts 😁
Looking stellar mate, sharp looks to match yer words!
Looks reeaally good. I already thought your setup was tight.
Really insightful my friend, and great pace as well! Looking forward to following your content.
Thank you Maxim, glad you liked the content!
Dang, That set looks superb.
This is such a fantastic video and the fact that it's completely free is astounding!
May I just say that I love the graph monster in the background?
Slots - very useful think. Thank you for the explanation.
Audio has a bit more echo than in the past, in the first two setups. Coding setup is fine.
Very nice...as usual. It seems like another advantage of using slots would be to catch spelling errors in your classes' attribute names. For example, without slots, the statement myPerson.namee = "Joe" would work fine, but myPerson.name would not be affected. But using slots, the statement would raise an error:
'Person' object has no attribute 'namee'
which would let you find and fix the spelling error much sooner.
Awesome camera quality 👌
Thank you!
Cool video, a very good explanation indeed. And a really cool recording setup :D
Thanks for sharing this cool feature
Fantastic video. I’m gonna use slots for sure! Also yes, I love the new look. Enjoy your week!
Amazing new setup! Great video as always!
Thank you!
Great video as always. Love the new studio set up.
the new backgrounds and cameras you use are very nice. pro!
Thanks Pawel!
Hey Arjan! I have been watching your videos and i have a question that i could not find a clear answer to. Is there a reason to NOT use dataclasses? It really seems to be the cleaner approach to managing and writing your classes but are there reasons to pick normal classes over them?
Great content by the way! Loving your channel.
12:11 I do not think SQLAlchemy is using slots, it is using Tuples
Thanks for the videos. They are always super interesting and very practical
Again. Great content Arjan.
Highly appreciated
Thank you! Very informative👍
the setups are really nice! excellent work.
Thank you Jonathan!
You have a fantastic skill in choosing topics. Keep it up.
Nice video. I also like your new setup. Your explanation of the topic always best. Thanks man.
In Go, you can "compose" several structs in a bigger struct, and get convinience of multiple inheritance, without inheritance at all. But in Python, sometimes the only way to make your class smaller is to use multiple inheritance. I think in some ways, Go is a better Python than Python (based on the Zen of Python).
Great video.
Always learning with you. The new setup look great!!
Thank you Pedro!
no hoodie? Arjan I think this strapping professional has taken over your channel 🤣
new sets look great
I think attrs is such an awesome thing, it is faster than dataclasses, has validation, extra features, and the slots are enabled by default!
What is attrs?
we love the new setup! :D
Thanks!
high quality content about python on this Channel. No Doubt in it
Thank you Ahmad, glad you like it!
This is so much informative especially on perf of py classes
h4X0r Arjan to corporate Arjan.
Also changing lights in the background is a bit distracting.
Very informative. I honestly didn't know this. Free performance increases are the best performance increases.
There is no such thing as a free lunch, it's worth knowing about the limitations of slots.
Awesome, amazing way to create a well readable and secure code
thank you that just helped a lot as i remembered watching this a while ago and came back to refresh my mem!
Glad to hear you found it helpful!
@@ArjanCodes awesome
Awesome new setup Arjan! If I'm very nitpicky (but that's not a thing I would ever be) then I'd say the programming view could use a bit of fill light for the right side of the face. But quite an awesome step up already.
And besides that, another excellent video. Keep it up!
Thanks Bart! I agree & it’s already fixed for the next batch 😊.
I dig the new set! And thanks as always for the python tips!
Thanks for your video. That's really what I needed
min not mean?? 6:02
Nice video! A great way to better show the value of variables is with 'from rich import print'. It automatically highlights types and emphasizes structure.
Chief, that lights thing on your left is a bit distracting (setup 1). Thanks for the video!
The videos are amazing! I like the way you explain things. It is easy and fun to follow. I always find something useful even if I know the topic and recommend your videos to my colleagues because they are so informative.
The way you present inspires me when I do my presentations.
The new setup is very nice!
Thank you very much . i love all of your tutorial . it helps me lot to improve my skill .
Hello Arjan. Could you tell about different way to implement class which inherits over employee and person? I agree that multiple inheritance may be bugggy, but how to solve that in a clean and efficient way?
Answering as a sr dev here - try thinking in terms of composition instead of inheritance. Inheritance implies an "is a" relationship. A Square "is a" Shape. Composition implies a "has a" relationship. A vehicle "has a" steering wheel, brakes, and headlights. Its very rare that you will find yourself with the need to describe W "is a" X, Y, and Z. Hope this makes sense. There are others who can explain it way better - just search "prefer composition over inheritance" - it is a well-known axiom amongst experienced OO developers.
Edit: As a nice side effect to using composition over inheritance, you'll find your unit tests easier to implement because you'll be in a good position to leverage dependency injection and provide mocks for the dependencies rather than having to mock any dependency chains of your parent class(es).
Fantastic video!
4:50 if they make the attributes static, then, they are very different from using self.var, which are NOT static but instance based.
Person in your example doesnt make sense then because if they are static, you cant have 2 different persons because they will both have the same data.
I don't mean static in the sense of them being static variables, but static in the sense that the list of attributes in an object of that class is static: you can't dynamically add new attributes like you can if you don't use slots.
@@ArjanCodes then i'd say "the number of attributes is fixed if using slots, unlike normal classes". I think that better conveys what you mean without adding confusion with other programming terms
The best tutor of all
Thank you for the kind words, John!
What about the case when we will have a list object as a slot? Does that make sens?
Wasn't able to replicate this example using python 3.10.4, for some reason
TypeError: dataclass() got an unexpected keyword argument 'slots'
and
TypeError: unsupported operand type(s) for |: 'type' and 'type' ~ from the get_set_delete function
Hey, @ArjanCodes!
Can you please explain why you use `partial` in your time measurements? From what I've found, using `partial` may save an overhead compared to `lambda`. Is this the purpose you used it here, in your code?
After python 3.11 the benefits of using slots on performance is very low as far as I can see, but you are still saving memory. That's not a bad thing for object you create a lot of instances of.
great setup!
Honestly, this is the first time I see slots, but I have a question. Does performance grow for get, set and delete evenly or some of them has a bigger contribution? Thanks you for the video!
Hi Arjan, love your videos! Just one little note. Wouldn't it be a better measure to use the average performance, than the minimal one? At least I'd be more interested in the average difference in performance ;) Cheers!
Hi Arjan, great video! I also like your new setup. However, as also other commented, the audio seems to be worse than before.
Thanks! The audio could indeed be better, still have to tweak the new setup a bit, but we’ll get there.
Believe me or not, I actually watch coding videos instead of taking sleeping pills. And your new studio looks really cool!
Thank you! Your content belongs to the better ones here on RUclips!
Hello any video about Python Guard clauses please
So amazing I want to use the f word! Fantastic!!!
Damnnnn that background 🤩👏👏👏
Glad you like it!
would you write vid about class attributes and instance attributes?
Is it possible to use descriptors for validating attributes in a class that uses slots?
Hello Arjan, great video as always! I would like to ask you. I want to use the super initialyzer in a child class. That is something achievable using dataclasses? Should I explicitly declare the __init__ method? If this is the case, I will lost the syntactic sugar of using dataclasses. Thank you so much!
Hi Matias, what you can do is add a dunder post_init method to your child data class and call super from there. That way, you can still let dataclass generate the init method.
@@ArjanCodes Thank you so much for replaying. Your videos are super enjoyable and a great inspiration for me.
4:17 ( __slots__ = "name", "address", "email" )
that's not a list. that's a tuple instead!
That would be a list ( __slots__ = ["name", "address", "email"] )
Like number: 660 great video, didn't even know slots existed! thank you!
Hey ArjanCodes, is it true that the main reason for UML diagrams exists is to provide jobs in the tech industry for non-tech people like trainers/coaches etc.?
I understand have normal classes defaulting to not using slots, but data classes should have that as the default.