I also think this would be cool, but would be hard not making it too long while staying informative. It seems like many TH-cam channels favor having a 5 hour crash course. Beginners don’t have the attention span (imo) because they’ll have so many questions.
This would be actually what I need ! Focus on real world professional prduction-code. Either to be better qualified for a job or to particiapate in big projects like pandas, numpy etc.
Thank you for this valuable video! Before watching your video, I assumed dataclasses were just a Python version of C structs, for cases where you didn't want to add functions in a class but didn't want a raw tuple either. After watching your video, I learned that dataclasses are much more sophisticated than that.
I have been looking for such tutorials (unique less known concepts for intermediate programmers) for years now. This channel is an absolute gem! Great work James!
I love the way you start by explaining and go to the solutions. Most people just start by showing what it does and how to do it, without ever mentioning why we really need it. Keep going, your style of teaching will reach millions of people.
I don't think my jaw has ever dropped from a coding video before. The beauty of being an engineer is you learn something new every day. So much hidden utility in python its amazing!
You definitely need classes for OOP, but classes can be used for other programming paradigms besides OOP, though I guess you are right in that usually classes are introduced in the context of OOP.
@@mCoding Yeah, I have seen classes used in programs, where no OOP was involved. In those programs, classes were used just to pack data into one structure. However, I've not seen @property, __hash__, or how to make them immutable so I thought they were covered in OOP.
About 2 years ago I came over from writing bare C to having Python as my daily driver. I've grown to really enjoy the language. 95% of the time it suits my needs and videos like this just illustrate how absolutely brilliant it can be. Thanks for the new trick up my sleeve!!!
As someone who has been slowly getting into the nitty gritty of writing classes, this video was informative, scary, and then relieving. Not only have you showed me what I have yet to learn, but also why it's something that should understood, but hopefully never written.
I'm starting to realize how damn useful class and method decorators are. I have the cumbersome Learning Python book by Orielly but these videos offer a lot of value due to how terse they are. @cache and @dataclass all day baby
@@maltml the human brain tend to work in a way - that if you didn't use it, you will forgot it....thus reading the book without goal is just a waste of time. Better to lvl the skill in ability to search for information you actually needed and when you need it. It's like - i'm watching this vid; yep cool stuff, standard lib. But if you would have a hundreds of classes, transforming each via class decorator would eat performance on module load.
I have just started experimenting with Python to use animation libraries from Grant Sanderson / 3Blue1Brown and have seen your videos pop up. Your organization and presentation of these tips is great for both initial learning and reference. Very concise, straightforward examples without cryptic foo / bar based variables, etc. New subscriber!
I love that you called out the issue with __slots__ The default dict instance representation has turned my implentation into a massive memory hog, tuple instance representation fixed that! Maybe __slots__ and other memory optimization and profiling techniques could be the topic of a future video!
Best video on dataclasses I have ever seen by far. Loved the approach of firstly doiny an example implementation, then showing the issues found, and finally solving them using the feature displayed.
as a beginner with some basic knowledge it is the content I started peeking in, some professional stuff that I can learn actually makes life much easier!
So basically this is python's equivalent of lombok's @Data annotation in java and python supports this out of box Thanks for sharing it Your videos are amazing. You always get to the point without wasting any time
I remember doing project for school in java where the professor didn't let you use any libraries, so if you wanted something to be comparable you had to type every thing out... my God. This brings tears to me eyes that dataclasses in pyton will automatically do all of that for you.
I actually left typing noises in on purpose because they sound satisfying... not sure if others agree or would rather not hear me clicking and clacking.
This is great! You do a great job of explaining these features. I always found classes to be annoying to deal with in Python and have stayed away from OOP because of that, but this approach might change my mind.
To get the nice syntax using the `attrs` library, use `auto_attribs=True` in the decorator and you'll be able to get the same syntax ability of mixed defaults in `dataclass`.
When I first came across decorators and understood that the dectaror takes the function or class as an argument, I thought this will have so many uses. Data classes are gold
This is the perfect intermediate to advanced python concepts I would like to see covered in a single comprehensive course. Your explanations are very punctual and I seem to really get a lot out of your videos. I am glad I found this channel. You should really consider, as others have suggested, to make such a course.
I am watching all your videos since a random youtube recommendation. Some of the best coding videos I have seen yet, very clear, easy to follow and often about topics and features I would never thought that I will benefit from. Thanks!
Really liked this. I'm building a library for Kivy-based apps that provides an interface for working with TastyPie on a Django-based server, and this is exactly what I need for storing information related to each model schema exposed through the API. So much simpler and readable. Always good to learn more about Python, thanks for the vid!
I took CS in bachelors, CS in masters and have PhD but never have I crossed this, thanks a lot man, this is actually pretty helpful. it shows how dumb down the CS degrees are right now, No one is doing any code and doing shit that is outdated and have no real life usage.
I really like your style of videos and have watched most of them already. But I'll admit I'm not sold on dataclasses... With your first example, you know exactly what python will do in each use case. With dataclasses, you've wrapped your code with an opaque magic cloak that you can either simply hope that it does what you want, or you will have to test every corner of its behavior, or analyze all the corners of the dataclass code itself. And newer coders will not understand it -- I know because someone at my work uses them and even after explaining them to me I had no clue what he was talking about or what they did, and I've been writing python for 10 years.
Wow. After this video I think I really got the gist of Python dataclasses. And so many ideas popped up in my head to refactor some code. Thanks a lot! 😃
If your use-case requires more capability than dataclasses can provide, I highly recommend looking into pydantic instead of attrs. We switched from attrs to pydantic in a project of ours that makes heavy use of these dataclass-like patterns for things like packet handling, and pydantic has been a huge step up from attrs. It has much more powerful validation mechanisms, cleaner and less quirky syntax, integrates very nicely with typing and provides a lot of useful mechanisms for generating objects from data you receive remotely (say as JSON) rather than creating them yourself, or that you need to transmit to other external services/components. It even has built-in support for automatically generating JSON schemas from the pydantic classes, which can make it much easier to provide a machine API for interfacing with your classes or generate a GUI using something like json-editor.
I didnt know this so thanks for the video. One thing I missed was the speed comparison. You made the Manual class larger by giving the performance as an excuse(not equal and all sorting methods) but when discussing dataclass you never mentioned the performance overhead. The size of the code probably justifies it’s slower anyways but its not mentioned :(
Performance overhead is it probably 3x's to 10x's most operations. If you are going for pure speed, you may want to avoid wrapper classes and just use tuples. (See my video on how fast python's sort it, I compare tuple vs dataclass speed there). However, the vast majority of code is not limited by the operations you do on class objects, so for most code the impact would be minimal.
Omg I just finished a Python OOP assesment at uni, where was this library! (I am also just stupidly happy I understood this video) I had all these issues so I will be using this in the future. Thanks so much, keep up the great work!
A "Production Python Code" course by you would be a hit. These are the things I never picked up as a mostly self taught programmer. Great stuff.
Thanks!
I also think this would be cool, but would be hard not making it too long while staying informative. It seems like many TH-cam channels favor having a 5 hour crash course. Beginners don’t have the attention span (imo) because they’ll have so many questions.
@@logankillen2669 this isn't beginner content, it's intermediate content for programmers who want to improve.
@@johnr3936 which are the hardest tutorials to find!
This would be actually what I need ! Focus on real world professional prduction-code. Either to be better qualified for a job or to particiapate in big projects like pandas, numpy etc.
I love that you show WHY you would want to use this rather than just what it is. It really drives home the actual usefulness of this
I think that's what's really the important part.
Totally agree! Happy TH-cam recommend me your channel!
Thanks! The WHY is the part that is missing almost everywhere else. Subscribed and hoping for more :-)
Agree 100%
Agreed! Context matters.
Update: as of python 3.10, slots are now supported in in-built dataclasses with the ``slots`` argument
what is that?
Thank you for this valuable video! Before watching your video, I assumed dataclasses were just a Python version of C structs, for cases where you didn't want to add functions in a class but didn't want a raw tuple either. After watching your video, I learned that dataclasses are much more sophisticated than that.
Glad it was helpful!
I have been looking for such tutorials (unique less known concepts for intermediate programmers) for years now. This channel is an absolute gem!
Great work James!
Thanks so much for your kind words!
I love the way you start by explaining and go to the solutions. Most people just start by showing what it does and how to do it, without ever mentioning why we really need it. Keep going, your style of teaching will reach millions of people.
Yes
I don't think my jaw has ever dropped from a coding video before. The beauty of being an engineer is you learn something new every day. So much hidden utility in python its amazing!
I'll remember this. I don't know much about OOP so I didn't understand much. When I'll learn, I'll re-watch this video.
You don't need to know about OOP to understand classes! You are simply making your own class that holds an int and a str!
@@mCoding Classes are the very basics of OOP. If you don't know about OOP, chances are you don't know how classes work either.
You definitely need classes for OOP, but classes can be used for other programming paradigms besides OOP, though I guess you are right in that usually classes are introduced in the context of OOP.
@@mCoding Yeah, I have seen classes used in programs, where no OOP was involved. In those programs, classes were used just to pack data into one structure. However, I've not seen @property, __hash__, or how to make them immutable so I thought they were covered in OOP.
I strongly recommend that you learn Python and OOP immediately.
About 2 years ago I came over from writing bare C to having Python as my daily driver. I've grown to really enjoy the language. 95% of the time it suits my needs and videos like this just illustrate how absolutely brilliant it can be. Thanks for the new trick up my sleeve!!!
As someone who has been slowly getting into the nitty gritty of writing classes, this video was informative, scary, and then relieving. Not only have you showed me what I have yet to learn, but also why it's something that should understood, but hopefully never written.
Best Python videos on youtube. Or maybe most valuable? Covering so many useful and unique topics no one else seems to.
Wow, thanks!
@@mCoding thank you very much for your videos. I know something new every video.
I'm starting to realize how damn useful class and method decorators are. I have the cumbersome Learning Python book by Orielly but these videos offer a lot of value due to how terse they are. @cache and @dataclass all day baby
Books actually contain a lot of useful stuff! Lucky for me I love reading terse literature (high signal-to-noise-ratio).
@@mCoding Do you have some book recommendations?
@@maltml the human brain tend to work in a way - that if you didn't use it, you will forgot it....thus reading the book without goal is just a waste of time. Better to lvl the skill in ability to search for information you actually needed and when you need it.
It's like - i'm watching this vid; yep cool stuff, standard lib. But if you would have a hundreds of classes, transforming each via class decorator would eat performance on module load.
don't diss lutz ;p
I have just started experimenting with Python to use animation libraries from Grant Sanderson / 3Blue1Brown and have seen your videos pop up. Your organization and presentation of these tips is great for both initial learning and reference. Very concise, straightforward examples without cryptic foo / bar based variables, etc. New subscriber!
This is actually one of the best CS-related channels I've watched
But its not c sharp, its python
@@aa-nw8hk CS = computer science
**Note: As of Python 3.10 data classes DO support slots.**
Thanks for adding it to the description, this video is gold!
Of course! Thanks for watching!
@@mCoding It's been 3 hours and I am still watching your videos! I was just watching another video!
👏😮 that means a lot, thanks! Glad you enjoy my videos so much!
I love that you called out the issue with __slots__
The default dict instance representation has turned my implentation into a massive memory hog, tuple instance representation fixed that!
Maybe __slots__ and other memory optimization and profiling techniques could be the topic of a future video!
I'll cover slots eventually, but that's a more technical topic!
I think NamedTuple from typing module used slots by default. Also seem to work with @property.
I use slots to avoid typos. Particularly important if your class has writable properties.
as for now, slots are available in dataclasses too (since python 3.10)
Best video on dataclasses I have ever seen by far. Loved the approach of firstly doiny an example implementation, then showing the issues found, and finally solving them using the feature displayed.
Awesome, thank you!
What makes this video really useful is thay you show why you need it rather than what does it do.
Thank you for introducing me to dataclasses! Using a dataclass has just considerably simplified a module that I'm working on right now.
C# dev here learning python for my Software Engineering thesis. I love your videos, directly to the point and with a lot of useful information!
Well explained without sounding fancy. It's one of the reasons I like your videos: you know how to get to the point.
Seen a few Python dataclasses videos but this one is the clearest and most informative in a short time. Well done!
This is the type of stuff classes should teach. I really appreciate your content.
Cool functionality. Thanks for sharing
@ 3:32 the dead pan to the camera... Lol !
Love the dry humor
I will slowly dial up the humor moving forward.
@@mCoding its absolutely perfect the way it is!
3:30
Wow, this is an outstanding video! Thank you so much. I just found out you’ve got a Python course, I’m in
Nice
as a beginner with some basic knowledge it is the content I started peeking in, some professional stuff that I can learn actually makes life much easier!
Glad to peel back the curtain for you!
So basically this is python's equivalent of lombok's @Data annotation in java and python supports this out of box
Thanks for sharing it
Your videos are amazing. You always get to the point without wasting any time
Thanks for such kind words!
I remember doing project for school in java where the professor didn't let you use any libraries, so if you wanted something to be comparable you had to type every thing out... my God. This brings tears to me eyes that dataclasses in pyton will automatically do all of that for you.
Well - the professor did the right thing - get you to actually use the language.
Highly recommend checking out pydantic. It's a huge extension to normal dataclasses, adding serialisation, better validators, forced typing and more!
I'll check it out! Thanks for the suggestion.
The new mic has arrived!
Indeed it has! Let me know if the audio quality sounds good or if I've messed something up!
@@mCoding its perfect :)
It sounds much better. Though it sounds like there's a little bit of reverb somehow
@@mCoding Your voice sounds perfect, but you can hear some vibrations from keyboard sounds in the audio
I actually left typing noises in on purpose because they sound satisfying... not sure if others agree or would rather not hear me clicking and clacking.
Your videos are extremely information rich, yet not "dense" in terms of accessibility of the ideas.
LMAO That pause and eye contact after he read "I just subscribed". I FELT THE PRESSURE MAN!
:D subliminal messaging
These are really great videos! I'm just learning Python for work and they're extremely helpful with simple and clear explanations.
This is great! You do a great job of explaining these features. I always found classes to be annoying to deal with in Python and have stayed away from OOP because of that, but this approach might change my mind.
To get the nice syntax using the `attrs` library, use `auto_attribs=True` in the decorator and you'll be able to get the same syntax ability of mixed defaults in `dataclass`.
When I first came across decorators and understood that the dectaror takes the function or class as an argument, I thought this will have so many uses. Data classes are gold
This is the perfect intermediate to advanced python concepts I would like to see covered in a single comprehensive course. Your explanations are very punctual and I seem to really get a lot out of your videos. I am glad I found this channel. You should really consider, as others have suggested, to make such a course.
Noted!
Dataclasses are a beautiful idea, and hearing "There's gotta be a better way!" reminds me of Sir Raymond's classes. Great stuff 👍!
I am watching all your videos since a random youtube recommendation. Some of the best coding videos I have seen yet, very clear, easy to follow and often about topics and features I would never thought that I will benefit from. Thanks!
Great to hear!
Subbed to this channel at like 300 subs and now 2 weeks later you're at 12.3k. you're going places my dude, keep it up, great content
Appreciate it!
I've being doing python for a while now and a lot of things here are new to me. Thanks for making this
Glad it was helpful!
This video gave me goosebumps...
This feat is amazing!!!
Great video! Very succint and useful!
Thank you so much!
I am way too noob for this video but I'll watch it whole and watch it again after 6 months. Thanks!
Very cool. I can see this saving alot of time. Python never ceases to surprise me
I know it saves me a lot of time!
Ey this is cool. My college classes made me design my own cpu but never actually taught me any useful stuff like this.
Both of those things are actually useful. Sucks that your college only taught you the former.
The fact that I was lost 10 seconds in is a testament, I need to get back to this. I'mma just save this to the list. (30-40 hrs into learning python)
Thanks for putting the time and effort to explain dataclasses thoroughly. You're the best!!
Thanks for shining a spotlight on these very useful Python modules with a good, concise tutorial. Great comparison between attrs and dataclasses, too.
Wow, I commented and asked for a dataclass vid a week ago and you actually delivered. Nice :)
Hope you enjoyed it!
Really liked this. I'm building a library for Kivy-based apps that provides an interface for working with TastyPie on a Django-based server, and this is exactly what I need for storing information related to each model schema exposed through the API. So much simpler and readable. Always good to learn more about Python, thanks for the vid!
I took CS in bachelors, CS in masters and have PhD but never have I crossed this, thanks a lot man, this is actually pretty helpful. it shows how dumb down the CS degrees are right now, No one is doing any code and doing shit that is outdated and have no real life usage.
U got me with the “I just subscribed “ look lolol
This is the first video I've watched on this channel. I love this guy! Great work!
Wow, thanks!
Higher than my current level, but when I get there, this will be even fantastic. THANK YOU !!!! :D
It's important to talk about __post_init__ because real code WILL need it, dataclass cannot do all the __init__ most times.
I really like your style of videos and have watched most of them already. But I'll admit I'm not sold on dataclasses... With your first example, you know exactly what python will do in each use case. With dataclasses, you've wrapped your code with an opaque magic cloak that you can either simply hope that it does what you want, or you will have to test every corner of its behavior, or analyze all the corners of the dataclass code itself. And newer coders will not understand it -- I know because someone at my work uses them and even after explaining them to me I had no clue what he was talking about or what they did, and I've been writing python for 10 years.
3m30... That is the new Deathstare!! Awesome, Subbed. Great vid and Mitch appreciated.
I'm a beginner, but I started using data classes more ad more just because it was easier to keep things organized and understandable.
James u deserve an award for being the greatest python teacher of all the time! the PYTHON GOAT
Wow thank you for the praise!
Your vids are the perfect thing for me, I usually get lost in long videos. Yours are short, simple and actually demonstrate applications of it
Great to hear!
Wow. After this video I think I really got the gist of Python dataclasses. And so many ideas popped up in my head to refactor some code. Thanks a lot! 😃
I have no idea what's happening
You never fail to amuse me.
Didn't know that fields thing
Thx!
If your use-case requires more capability than dataclasses can provide, I highly recommend looking into pydantic instead of attrs. We switched from attrs to pydantic in a project of ours that makes heavy use of these dataclass-like patterns for things like packet handling, and pydantic has been a huge step up from attrs. It has much more powerful validation mechanisms, cleaner and less quirky syntax, integrates very nicely with typing and provides a lot of useful mechanisms for generating objects from data you receive remotely (say as JSON) rather than creating them yourself, or that you need to transmit to other external services/components. It even has built-in support for automatically generating JSON schemas from the pydantic classes, which can make it much easier to provide a machine API for interfacing with your classes or generate a GUI using something like json-editor.
that little pause at 3:30 made me subscribe 😂
Good intermediate YT content is hard to come by, subbed! Amazing post 😁
Amazing video, love it! (loved the "hinting eye contact" @ 3:30 ;)
HOLY SHIT. Why didn't I just learn this ages ago? It's fantastic!
I've just used these for my users in flask. Great explanation
3:31 the pause and cold look after "I just subscribed" :D
😇
Most valuable 9 minutes of my python career
Thanks for the kind words!
That 3:29 was hillariously sneaky! Good video btw
I shouldn’t watch this so close to going to sleep. This is going to give me weird dreams.
I will try my best to not appear in your dreams.
I heard learning before going to bed is efficient because you'll process what you learned in your sleep. Source: Idk, probably read it in the morning.
One of the best Python OOP videos I've ever seen. Thanks!!
Glad it was helpful!
This channel is a goldmine.
Many thanks! I appreciate your kind words.
7:33 attrs allow u to specify validators & converters
wholly molly, thats awesome and exactly what i needed.
u earned a sub - i guess this is first video of u i am actually watching
youtube pushed other vids before, but never got time
This is really cool and I just learned that you can put decorators on classes :) thank you!! You have earned yourself a subscriber.
Thanks for subbing!
The *slaps table* is very important in the "There has to be a better way."
I'll do this in the future :)
Apart from the amazing video, you're acting skills are on point :D
What a nice and clear explanation! I will try to implement this in my thesis project!
Go for it!
*You* my friend are the new Cory Schafer! Thank you for contributing to free education :D
That was soo awesome .. I saved a lot of time writing code for json responses ! Really awesome stuff 😁
For dataclasses, there is direct support for __slots__ (added to python in 3.10). Just as an update.
My search is over, @dataclass put me in a whole new level.
Subscribed. Really great one. Will be following more of yours tutorials.
Great stuff man! Im new to the channel but I've already learnt a lot from your videos! Keep churning out these high quality content!! :D
Thanks! Will do!
I didnt know this so thanks for the video. One thing I missed was the speed comparison. You made the Manual class larger by giving the performance as an excuse(not equal and all sorting methods) but when discussing dataclass you never mentioned the performance overhead. The size of the code probably justifies it’s slower anyways but its not mentioned :(
Performance overhead is it probably 3x's to 10x's most operations. If you are going for pure speed, you may want to avoid wrapper classes and just use tuples. (See my video on how fast python's sort it, I compare tuple vs dataclass speed there). However, the vast majority of code is not limited by the operations you do on class objects, so for most code the impact would be minimal.
Insanely clear and valuable tutorials dude! Subbed in a millisecond
Hey, thanks!
This is basically like lombok's @Data and @Value for java. Nice stuff!
Omg I just finished a Python OOP assesment at uni, where was this library! (I am also just stupidly happy I understood this video)
I had all these issues so I will be using this in the future. Thanks so much, keep up the great work!
Glad I could help!
you just explained private vs public attributes in like 5 seconds, something that i didnt understand after years of coding lol
The medic channel for self-taught devs
wow bro this is amazing. Thanks for doing what you do man!
I'm hooked to this course bro, a huge thanks for this.
No problem 👍
When he read the comment "I just subscribed" and looked at the camera I immediately gave in.
Ty ty you've fallen for my tricks
I'm adding a second comment. This vid taught me more useful stuff in 8 mins than any other I remember ever before in that time.
Wow! Awesome!
WHAAAAAA
THIS HELPS SOOO MUCH WITH MY AST NODES
THANK YOU SO MUCH
You are very welcome 😊
You have a very deep insight into the python source code
Great video! Rare material in TH-cam. Thank you!
Glad you enjoyed it!
Never heard of dataclasses. They look super useful! BTW, I really like your channel.
Awesome, thank you!