I have been programming regularly in Python for a few years and I keep watching this Video. Again and again I get something new from it.
@jacobblanton7982 Жыл бұрын
Every programming class should be taught this way. I love how this is implemented in a project-style manner. I wish I learned OOP this way.
@mountainhobo10 жыл бұрын
Brilliant delivery. Whether you are interesting in programming or not, it's worth watching, if just for the overall business process implications.
@lionpersia6 жыл бұрын
Reymond Hettinger and James Powell: I owe a great deal to these two men.
@SanataniAryavrat5 жыл бұрын
agree... 100%
@l_combo4 жыл бұрын
+ David Beazly!
@ipsectunnel11 жыл бұрын
That's part of his "signature", I actually took almost 80 hours of training from Raymond Hettinger and that's one of the teaching techniques he continuously uses throughout his classes to reinforce ideas and concepts, and let me tell you it is very effective, definitely one of the best courses I've ever taken.
@rodrigobraz22 жыл бұрын
That's *what* part of his signature? You seem to be referring to something that was not actually said.
@Nathan-pl2cf2 жыл бұрын
@@rodrigobraz2 The comment is from 9 years ago. It was probably before replies were a thing
@wduandy Жыл бұрын
@@Nathan-pl2cf 😔
@izd4Ай бұрын
@@Nathan-pl2cfThe previous commenter had said 'excellent, but stop saying "who learned something new" it's tedious'
@AlbertKamu11 жыл бұрын
One of the best performances on PyCon USA I've seen. Thanks a lot for upload!
@nishankbani32576 жыл бұрын
Raymond Hettinger style of delivery is fantastic and the content is very good delivered in a succinct manner.
@pavelivanov9573 жыл бұрын
Thank you for excellent explanation of what certain functions are meant for in Python and not just explaining how they work! Just cleared out a lot of very important topics! Just great!
@akypar Жыл бұрын
Having seen this video up to 20', I could easily replace Raymond's lectures over my netflix subscription
@justgivemethetruth9 жыл бұрын
This guy is a great teacher ... at least 8 minutes into the video. I like what he has to say ... and always good when you hear what lots of people think that is wrong too.
@shashvatshukla7 жыл бұрын
Wow this was an amazing lecture! Great for someone who knows some python, and wants to learn all about classes in Python. Apart from the summary slide at 45:00, some of the main things I learnt were: 1) See how people use your code (through fast feedback loops), and make sure new changes don't break their code. Think especially about people who will make subclasses from your classes. Expect that there is a good way to meet new requirements while not breaking old user code 2) Add just what you need as part of the Agile process. It seems that Python is great for Agile development because you can get up and running with very simple code, and add more functionality in the future without changing the API. 3) Python is different from Java or C++. I guess each language has their own style, and it is a good idea to learn to do things the right way in any language you learn, rather than bring the old habits along.
@ameyms10 жыл бұрын
"Who learned something new?" *I* did.
@justgivemethetruth9 жыл бұрын
Amey Sakhadeo All I learn from this kind of video is just how clueless I am about the guts of a language and how hard it is to focus on on WTF he is talking about! ;-)
@johnc34034 жыл бұрын
Not me, I'm drunk. I think this lecture calls for being sober...
@w.r.74404 жыл бұрын
Such a talented speaker, really interesting presentation to watch
@AdmiralMaur9 жыл бұрын
This was so entertaining that I'll swap out my movie tonight for this video. Thanks!
@OrotundBucket4 жыл бұрын
God damn it, I almost spit out my coffee when he said, "Reproducible results? Oh, that's a new feature in science. How often do you get that?" 16:04
@brum29311 жыл бұрын
I think it's good. :) It gives Raymond feedback so he can adapt the talk to the technical level of the audience.
@IanSebryk Жыл бұрын
this was amazing. can't believe i hadn't come across this before. and i feel like an idiot for not having done so.
@trombonemunroe10 жыл бұрын
This is a must-see video for Pythonistas.
@swyxTV4 жыл бұрын
i dont even use python regularly and i watched this all the way through
@CampaignsIlraon8 жыл бұрын
This, is, incredibly thorough. Thanks so much.
@MrTigerstyle804 жыл бұрын
Flippin Big RH absolutely doing WORK back in the day. Guy’s a beast am I right?’
@karsten14055 жыл бұрын
That moment when Raymond goes "..the opposite of privacy - [...] freedom" 37:42
@salkdjfasldkfjsdlk10 жыл бұрын
Great talk. Everyone I share this with gets a kick and yes, they learn something new.
@jimstanley_497 жыл бұрын
I learned something new! Now I have to go change all the getters and setters I thought I needed because I wanted to do more than just store the property.
@Anshumantiwarianstiwar2 жыл бұрын
Wow, this was really amazing, I definitely learned something new today.
@lizzie01969 жыл бұрын
Here are the contents of the slides with comments in the form of an IPython Notebook. nbviewer.ipython.org/urls/dl.dropboxusercontent.com/u/5095342/IPython%20Notebooks/Python%27s%20Class%20Development%20Toolkit.ipynb
@samarth.rangavittal8 жыл бұрын
+John This is great, John. Thanks a bunch !
@EmanueleCagliero8 жыл бұрын
Great work +John! I made some changes to adapt it to Python 3: github.com/EmanueleCagliero/py_class_toolkit
@hololightful7 жыл бұрын
John unfortunately, that link is dead now... but the link in the reply below on GitHub is working...
@FredDamstra6 жыл бұрын
Would area() be better as an @property, as well? Seems like that would be a more python-like implementation and would make the calling code easier.
@mirageowl4 жыл бұрын
I like how this makes me able to use Python just like Ruby
@stoneshou7 жыл бұрын
Raymond: if you wish hard enough, the fairy godmother appears .. I guess we all wished hard enough and so Raymond appeared
@DrDeuteron Жыл бұрын
17:30 so classic python. Now we have ppl demanding type ints. I do not feel icky not knowing what types are being passed.
@izd4Ай бұрын
type hints are the best
@tomislater11 жыл бұрын
Great video. Thanks Raymond.
@buybuydandavis3 жыл бұрын
Summary: Toolset for New-Style Classes 1. Inherit from *object()* 2. *Instance Variables* for information unique to an instance. 3. *Class Variables* for data shared among all instances. 4. *Regular Methods* need "self" to operate on instance data. 5. *Class Methods* implement alternate constructors. They need "cls" so they can create subclass instances as well. 6. *Static Methods* attach functions to classes. They don't need either "self" or "cls". Static methods improve discoverabiity and require context to be specified. 7. *@property* lets getter and setter methods be invoked automatically by attribute access. This allows Python classes to freely expose their instance variables. 8. *__slots__* variable implements the Flyweight Design Pattern by suppressing instance dictionaries. 9. *__DoubleUnders__* for class level references.
@rupen422 жыл бұрын
you don't need to inherent from object in python 3 now. writing "class NameOfTheClass:" implicitly does "class NameOfTheClass(object):"
@MsSuyash19955 жыл бұрын
This was a fantastic talk...
@BeYakko17 жыл бұрын
I learned something new
@dariofagotto40476 жыл бұрын
"Properties are something you can do in a dynamic language but not in compiled ones"... Unless you use turbopascal
@ross8254 жыл бұрын
Or Ada
@DavidCodes4 жыл бұрын
amazing. learned something new!
@mcan5434 жыл бұрын
#KeyTakeAways 7:15 If you don't have variables don't belong to that instance use class variables. Not instance variables. 7:55 __init__ is not constructor. It is initializer. 9:00 Python classes are not similar to the C++ or Java classes. They are more like namespaces or dictionaries. 11:48 YANGNI 18:47 Exposing variables and changing them outside of the class is common and normal in Python world. 21:30 When you create an object and call a attribute or method ( including __init__ ) Python first looks called class itself. Then looks parent classes recursively. 21:56 Extending and overriding. 26:26 Alternative constructors with @classmethod decorator 32:00 @staticmethod decorator 33:50 Creating a private variable and assign the method to that private variable. It is a good way of protecting your subclasses. 35:35 Better way of protecting your subclasses assigning the method to a dundervariable. 39:26 Accessors and mutators. When you set circle.radius = 5, @radius.setter decorated function runs ----> www.python-course.eu/python3_properties.php 41:44 __slots__ and lastly, how to do an engaging presentation.
@ordinarygg11 жыл бұрын
Must see for every Python programmer))
@jasmeet17mast4 жыл бұрын
Great video/content thanks for recording it in 480p! 2013
@JonMW4 жыл бұрын
I thought I knew how to make a class in python. This video showed me that I know nothing.
@rodrigobraz22 жыл бұрын
Is your last name "Snow"? :-)
@kronosaurelius5 жыл бұрын
Code is read more than is written. So next time you are reading a piece of code and see obj.radius = 3 Do you know if you are setting a variable or calling a function?
@theavo5 жыл бұрын
Does it really matter? Accessing a member variable in Python is a function call anyway (__getattr__, __setattr__).
@etherwar7 жыл бұрын
I learned several new things, but it's the "proleptic gregorian calendar", not "apoplectic" or whatever he was trying to say :)
@justgivemethetruth9 жыл бұрын
Kind of weird how much this guy looks like Ray Liotta.
@krasoffski11 жыл бұрын
Awesome! Than you, Raymond.
@solaxun7 жыл бұрын
I think the final few examples (39:45ish) using @property and @setter are incorrect because the self.radius should be self._radius, otherwise the init will try to call the setter for radius, and since no diameter is bound, it will error.
@twistedsim7 жыл бұрын
Mark Woodworth Came here for that comment :p !
@twistedsim7 жыл бұрын
I tought of that and I think it will work since the setter is always call when the object is initialized. The getter is never called.
@MrHaste122 жыл бұрын
It works. Calling self.radius=radius in __init__ calls the setter, and initializes the diameter
@solaxun Жыл бұрын
Yeah - I'm not sure what I was originally confused about here... @@MrHaste12
@mpgovinda5 жыл бұрын
If __init__ isn't a constructor. What's the actual constructor of python, is it __new__?
@anibaldk4 жыл бұрын
39:31 - shouldn't __init__ do *self.diameter* = radius * 2.0 ? Otherwise, you're violating your own ISO-222220
@Tech-jc5gy2 жыл бұрын
7:06 10:26 coding a reusable vs constant
@brianseroney85410 жыл бұрын
thanks Ray i love it it's awesome brother bigup
@onlybrad84347 жыл бұрын
I really can't see the problem with self.perimeter() methode inside area()... this is what I would have done in another programming language like Java because "this" will always use the method of the class of the object if it exist
@AJpennster7 жыл бұрын
The problem is that when an instance of Tire calls self.area(), self will refer to the tire instance. So inside the area method, self = Tire instance. Therefore when self.perimeter is called, python checks for a perimeter attribute inside of the Tire instance first, which it will find and use; however, that is the extended version of perimeter so the area would be different than expected.
@MRBADGUY0027 Жыл бұрын
@@AJpennster but for Tire instance it should take the extended perimeter method??? Inside the Tire class the perimeter method returns Circle.perimeter(self) * 1,25. So what's wrong? I can't see the problem, too...
@Oleksandr5947 жыл бұрын
Is there any book with this kind of explanation? These videos are best tutorial.
@fergal98086 жыл бұрын
Krund Effective Python by Brett Slatkin has a similar type of explanations but less in depth then this lecture
@willd0g5 жыл бұрын
“TRUE OR FALSE: is this my first Rodeo?”
@tc14hd23 Жыл бұрын
What does he say at 11:13? "and upload it to ???"
@ChillingSpartan6 жыл бұрын
The first two things I did understand. After that I didn't understand anything. Is there a way to learn what subclasses are and when to use, what instanciate really means and when to use these class methods and static methods?
@kyberzyler6 жыл бұрын
Sparta Best way to learn, is to experiment - perhaps in the python shell. Consider a class to be like a factory mould (a form) that you pour molten metal into to create an 'instance' of whatever you are manufacturing. Every instance is the same as every other instance, the same as the class, but what you do with them is up to you. (Perhaps if the mould if for a cooking pan, you cook very different things in each - they end up containing different ingredients, or attributes in Python terminology.) A sub-class is something that inherits all of the characteristics of the parent class but then has some differences. Imagine a class for pets. Cats and dogs share many characteristics (fur, four legs, etc) but make different sounds (one meows, the other barks). You use one class for everything that is the same, and sub-classes for the things that are different (e.g. food, exercise, training, sounds, etc.). As described in the video, a static method is simply a function included in a class definition for convenience. Instead of just writing func(parameters) you write class.func(parameters) when you use it, avoiding any confusion with any other function of the same name that might do something different.
@ChillingSpartan6 жыл бұрын
Stuart - Well, I think I understand. For example I could build a class 'Vehicle' with some variables likes tires = 4 and doors = 2 and lights = 2. I also could build some functions like 'accelerate' and 'brake'. After I build all I could use this class as a car or a subclass 'truck' with tires = 6. Is that right?
@kyberzyler6 жыл бұрын
Yes. Note that functions that refer to the instance (by convention, using self) are called methods and variables that are part of an instance or class are called attributes. I strongly recommend you just experiment in the python interactive shell. Then you get instant feedback pin what works and what doesn't.
@guyindisguise6 жыл бұрын
Check out the OOP tutorials from Corey Schafer here on youtube. They are clear and to the point. Helped me understand pretty much all the points you mentioned. (subclasses, class methods, static methods and more).
@ChillingSpartan6 жыл бұрын
guyindisguise - Thanks a lot. I already watched two videos from Corey and they are really great. His videos are even better to understand than videos in my own native language.
can't do on a compiled language? swift does it. probably a bit better too.
@Asdayasman9 жыл бұрын
Camera guy fall asleep at the end or something? Show me the fucking slides, damnit!
@akshaydeshpande73827 жыл бұрын
here is the link for slides : speakerdeck.com/pyconslides/pythons-class-development-toolkit-by-raymond-hettinger
@hectorordonez54952 жыл бұрын
"Is python about privacy? No is a consenting adult language" says after explaining how to workaround the fact that python does not have private and protected methods and hack a private method "There must be a better way" Yea, real private and protected methods.
@guerra_dos_bichos9 жыл бұрын
ok I'm confused (i'm very new to python), I understand that you should use reusable components, but what's the point of using Math.pi? It wont ever change (can I modify it on a large scale inside Python?) and if I ever need to have higher or lower precisions I'd have to rewrite the application all the same, wouldn't it make more sense to just have a Pi object where we could both have the hability fiddle with its precision without adding overhead?
@guerra_dos_bichos8 жыл бұрын
ty :)
@j1212121004 жыл бұрын
he said that on different platforms math.pi is calculated to different precision. for example on a cray it is 128 bit.
@akshaydeshpande73827 жыл бұрын
A great reddit thread discussion on the same : www.reddit.com/r/Python/comments/2zp0jy/probably_the_best_lecture_ive_seen_raymond/?st=jbsytpb3&sh=deb8db8c
@bigbud415 жыл бұрын
George Clooney of Python!
@sebastiannickel43777 жыл бұрын
When switching from radius to diameter, doesn't he need to change his __init__ method to `self.diameter = radius * 2.0`? (Especially after settings __slots__ = ['diameter'].)
@Alex-om6zq7 жыл бұрын
No. Since radius is property, when radius occurs on the left side of assignment, setter is called and result of expression on the right side of assignment passed as second argument (getter is called when property occurs on the right side of assignment). So result of executing is the same as `self.diameter = radius * 2.0`. But using properties we don't need change every place where radius is used.
@sebastiannickel43777 жыл бұрын
oic! thanks! Do you need the @radius.setter annotation for that to work?
@Alex-om6zq7 жыл бұрын
Yes, that's where all the magic happens). There is more information at official docs: docs.python.org/3/library/functions.html#property. Worth mentioning, properties are descriptors: docs.python.org/3.6/howto/descriptor.html.
@1over1372 жыл бұрын
I still find it amusing that Python programmers actually think they write real code. They actually think python is object orientated or functional. Python is none of those things, it's a script language. It's for solving problems too simple to bother a real language and project with. __init__ cannot initialise instance variables because python doesn't really have instance variables. It has a "self" thing with a dictionary in it. Initialise just adds a dict entry. You could of course just have set it yourself in the members dict. It's not a class, it's a dictionary and a bunch of function pointers. It can't be OOP as I don't think it correctly implements any of the corner stones of OOP, so just can't be classed as an OOP language. I mean PHP's OOP implementation was probably more complete than Pythons. It's only OOP to stop OOP programmers whining. It suffers the same as all "next generation" language suffer. It starts out with a clear, clean, simple ethos. It's successful and get adopted enough to survive. Then immediately all the people who adopted it start trying to use it to do everything... because oddly a lot of programmers strive to be single tool, single trick ponies and so they try and adapt their language of choice well outside of it's original ethos, add a bunch of junk which basically breaks the ethos and it becomes a bloated mess. I'll give you 3 reasons nobody uses Python for anything serious. Dynamic typing - untestable. Interrupter language - untestable. Once your application gets to a certain size, python becomes unmaintainable. Once your data/processing gets to a certain size python becomes non-performant. It's fine for it's intended purpose as a "quick", "convenient", "intuitive" utility language. Maybe a new Perl. Watching python programmers bigging themselves and their language up on the grand scheme of software engineering is actually quite cute. Awww.
@u.rossburton19722 жыл бұрын
I come from a C++ background. I wouldn't say Python is horrible, but there are some real gotchas that come from its design. Like you said, great for small programs or scripts, but there are too many exceptions to the rule and inconsistencies for my taste. If it weren't for that fact that so many employers ask for Python, I would have dropped it after I learned about the issues with it.
@rishabhkatna83483 жыл бұрын
He's like a way smarter Norm Macdonald
@AyuPapaBonanza6 жыл бұрын
Great talk! I wrote down the code in the talk here www.lvguowei.me/post/python-class-toolkit/ for easy reference.
@MaxRoycroft6 жыл бұрын
hah, "consenting adult's language"
@ZapOKill4 жыл бұрын
who needs more then 6 decimal_digits of pi?
@tissuepaper99623 жыл бұрын
That's not the point.
@CC-sr4zi7 жыл бұрын
I learned sth new
@arpitgaur43103 ай бұрын
He speaks so fast
@FxAndrej3 ай бұрын
So am I the only one who struggled to follow because the lecturer talks too fast without pause?
@wanderingfido5 жыл бұрын
Wrong...you CAN make the instance variables private by prefixing them with two underscores: *self.__radius*.
@karelpeeters62405 жыл бұрын
He specifically says that's not what they're intended for at 37:28, and they don't even work, people can still access them if they really want.
@FlashManinSpace10 жыл бұрын
I learned nothing new from this.
@guerra_dos_bichos9 жыл бұрын
+Flash Man good for you!
@funprog11 жыл бұрын
Excellent, but stop saying "who learned something new" its tedious
@MrTweetyhack8 жыл бұрын
_init_. haha. python is a good joke.
@ବିକାଶ_Biswal7 жыл бұрын
Only theory demonstration. It's a very boring class.