Python's Class Development Toolkit

Поделиться
HTML-код
  • Опубликовано: 20 дек 2024

Комментарии • 117

  • @edmartian
    @edmartian 4 года назад +12

    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
    @jacobblanton7982 Год назад +3

    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.

  • @lionpersia
    @lionpersia 6 лет назад +102

    Reymond Hettinger and James Powell: I owe a great deal to these two men.

  • @ipsectunnel
    @ipsectunnel 11 лет назад +51

    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.

    • @rodrigobraz2
      @rodrigobraz2 2 года назад +2

      That's *what* part of his signature? You seem to be referring to something that was not actually said.

    • @Nathan-pl2cf
      @Nathan-pl2cf 2 года назад +13

      @@rodrigobraz2 The comment is from 9 years ago. It was probably before replies were a thing

    • @wduandy
      @wduandy 2 года назад

      @@Nathan-pl2cf 😔

    • @izd4
      @izd4 Месяц назад

      @@Nathan-pl2cfThe previous commenter had said 'excellent, but stop saying "who learned something new" it's tedious'

  • @AlbertKamu
    @AlbertKamu 11 лет назад +18

    One of the best performances on PyCon USA I've seen.
    Thanks a lot for upload!

  • @nishankbani3257
    @nishankbani3257 7 лет назад +5

    Raymond Hettinger style of delivery is fantastic and the content is very good delivered in a succinct manner.

  • @pavelivanov957
    @pavelivanov957 3 года назад +6

    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
    @akypar Год назад

    Having seen this video up to 20', I could easily replace Raymond's lectures over my netflix subscription

  • @justgivemethetruth
    @justgivemethetruth 9 лет назад +4

    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.

  • @shashvatshukla
    @shashvatshukla 7 лет назад +14

    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.

  • @ameyms
    @ameyms 10 лет назад +118

    "Who learned something new?"
    *I* did.

    • @justgivemethetruth
      @justgivemethetruth 9 лет назад +7

      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! ;-)

    • @johnc3403
      @johnc3403 4 года назад +1

      Not me, I'm drunk. I think this lecture calls for being sober...

  • @mountainhobo
    @mountainhobo 11 лет назад +54

    Brilliant delivery. Whether you are interesting in programming or not, it's worth watching, if just for the overall business process implications.

  • @OrotundBucket
    @OrotundBucket 4 года назад +9

    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

  • @w.r.7440
    @w.r.7440 5 лет назад +6

    Such a talented speaker, really interesting presentation to watch

  • @AdmiralMaur
    @AdmiralMaur 9 лет назад +17

    This was so entertaining that I'll swap out my movie tonight for this video. Thanks!

  • @IanSebryk
    @IanSebryk Год назад +1

    this was amazing. can't believe i hadn't come across this before. and i feel like an idiot for not having done so.

  • @brum293
    @brum293 11 лет назад +2

    I think it's good. :) It gives Raymond feedback so he can adapt the talk to the technical level of the audience.

  • @trombonemunroe
    @trombonemunroe 10 лет назад +19

    This is a must-see video for Pythonistas.

  • @CampaignsIlraon
    @CampaignsIlraon 8 лет назад +11

    This, is, incredibly thorough. Thanks so much.

  • @karsten1405
    @karsten1405 5 лет назад +7

    That moment when Raymond goes "..the opposite of privacy - [...] freedom" 37:42

  • @DrDeuteron
    @DrDeuteron Год назад +1

    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
      @izd4 Месяц назад

      type hints are the best

  • @swyxTV
    @swyxTV 4 года назад +10

    i dont even use python regularly and i watched this all the way through

  • @Anshumantiwarianstiwar
    @Anshumantiwarianstiwar 2 года назад

    Wow, this was really amazing, I definitely learned something new today.

  • @jimstanley_49
    @jimstanley_49 7 лет назад +4

    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.

  • @salkdjfasldkfjsdlk
    @salkdjfasldkfjsdlk 10 лет назад +1

    Great talk. Everyone I share this with gets a kick and yes, they learn something new.

  • @lizzie0196
    @lizzie0196 9 лет назад +25

    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.rangavittal
      @samarth.rangavittal 9 лет назад +1

      +John This is great, John. Thanks a bunch !

    • @EmanueleCagliero
      @EmanueleCagliero 8 лет назад +6

      Great work +John! I made some changes to adapt it to Python 3:
      github.com/EmanueleCagliero/py_class_toolkit

    • @hololightful
      @hololightful 7 лет назад +1

      John unfortunately, that link is dead now... but the link in the reply below on GitHub is working...

  • @mcan543
    @mcan543 4 года назад +3

    #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.

  • @MrTigerstyle80
    @MrTigerstyle80 4 года назад +1

    Flippin Big RH absolutely doing WORK back in the day. Guy’s a beast am I right?’

  • @jasmeet17mast
    @jasmeet17mast 4 года назад

    Great video/content
    thanks for recording it in 480p! 2013

  • @DavidCodes
    @DavidCodes 4 года назад +1

    amazing. learned something new!

  • @MsSuyash1995
    @MsSuyash1995 5 лет назад

    This was a fantastic talk...

  • @BeYakko1
    @BeYakko1 7 лет назад +18

    I learned something new

  • @tomislater
    @tomislater 11 лет назад +1

    Great video. Thanks Raymond.

  • @buybuydandavis
    @buybuydandavis 3 года назад +4

    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.

    • @rupen42
      @rupen42 2 года назад

      you don't need to inherent from object in python 3 now. writing "class NameOfTheClass:" implicitly does "class NameOfTheClass(object):"

  • @mirageowl
    @mirageowl 4 года назад +1

    I like how this makes me able to use Python just like Ruby

  • @FredDamstra
    @FredDamstra 6 лет назад +1

    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.

  • @solaxun
    @solaxun 7 лет назад +6

    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.

    • @twistedsim
      @twistedsim 7 лет назад +1

      Mark Woodworth Came here for that comment :p !

    • @twistedsim
      @twistedsim 7 лет назад +1

      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.

    • @MrHaste12
      @MrHaste12 2 года назад +2

      It works. Calling self.radius=radius in __init__ calls the setter, and initializes the diameter

    • @solaxun
      @solaxun Год назад

      Yeah - I'm not sure what I was originally confused about here... @@MrHaste12

  • @stoneshou
    @stoneshou 7 лет назад +3

    Raymond: if you wish hard enough, the fairy godmother appears .. I guess we all wished hard enough and so Raymond appeared

  • @ordinarygg
    @ordinarygg 11 лет назад +2

    Must see for every Python programmer))

  • @Tech-jc5gy
    @Tech-jc5gy 2 года назад

    7:06
    10:26 coding a reusable vs constant

  • @krasoffski
    @krasoffski 11 лет назад

    Awesome! Than you, Raymond.

  • @brianseroney854
    @brianseroney854 10 лет назад

    thanks Ray i love it it's awesome brother bigup

  • @anibaldk
    @anibaldk 4 года назад +1

    39:31 - shouldn't __init__ do *self.diameter* = radius * 2.0 ? Otherwise, you're violating your own ISO-222220

  • @dariofagotto4047
    @dariofagotto4047 6 лет назад +5

    "Properties are something you can do in a dynamic language but not in compiled ones"... Unless you use turbopascal

  • @kronosaurelius
    @kronosaurelius 5 лет назад +1

    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?

    • @theavo
      @theavo 5 лет назад

      Does it really matter? Accessing a member variable in Python is a function call anyway (__getattr__, __setattr__).

  • @tc14hd23
    @tc14hd23 Год назад

    What does he say at 11:13? "and upload it to ???"

  • @JonMW
    @JonMW 4 года назад +1

    I thought I knew how to make a class in python. This video showed me that I know nothing.

    • @rodrigobraz2
      @rodrigobraz2 2 года назад

      Is your last name "Snow"? :-)

  • @Daco812
    @Daco812 5 лет назад +2

    36:25 - 37:53 .__ == freedom

  • @mpgovinda
    @mpgovinda 5 лет назад +1

    If __init__ isn't a constructor. What's the actual constructor of python, is it __new__?

  • @futurepython6774
    @futurepython6774 3 года назад

    python/django/mysql新教程:
    python基础:ruclips.net/video/g6RnSRDjd5M/видео.html

  • @ChillingSpartan
    @ChillingSpartan 6 лет назад

    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?

    • @kyberzyler
      @kyberzyler 6 лет назад +1

      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.

    • @ChillingSpartan
      @ChillingSpartan 6 лет назад

      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?

    • @kyberzyler
      @kyberzyler 6 лет назад +1

      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.

    • @guyindisguise
      @guyindisguise 6 лет назад +1

      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).

    • @ChillingSpartan
      @ChillingSpartan 6 лет назад

      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.

  • @Oleksandr594
    @Oleksandr594 7 лет назад

    Is there any book with this kind of explanation? These videos are best tutorial.

    • @fergal9808
      @fergal9808 6 лет назад

      Krund
      Effective Python by Brett Slatkin has a similar type of explanations but less in depth then this lecture

  • @justgivemethetruth
    @justgivemethetruth 9 лет назад +6

    Kind of weird how much this guy looks like Ray Liotta.

  • @onlybrad8434
    @onlybrad8434 7 лет назад +1

    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

    • @AJpennster
      @AJpennster 7 лет назад +3

      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
      @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...

  • @etherwar
    @etherwar 7 лет назад

    I learned several new things, but it's the "proleptic gregorian calendar", not "apoplectic" or whatever he was trying to say :)

  • @willd0g
    @willd0g 5 лет назад +6

    “TRUE OR FALSE: is this my first Rodeo?”

  • @Asdayasman
    @Asdayasman 9 лет назад +17

    Camera guy fall asleep at the end or something?
    Show me the fucking slides, damnit!

    • @akshaydeshpande7382
      @akshaydeshpande7382 7 лет назад +3

      here is the link for slides : speakerdeck.com/pyconslides/pythons-class-development-toolkit-by-raymond-hettinger

  • @fridyair
    @fridyair 4 года назад

    can't do on a compiled language? swift does it. probably a bit better too.

  • @guerra_dos_bichos
    @guerra_dos_bichos 9 лет назад

    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_bichos
      @guerra_dos_bichos 8 лет назад

      ty :)

    • @j121212100
      @j121212100 5 лет назад

      he said that on different platforms math.pi is calculated to different precision. for example on a cray it is 128 bit.

  • @1over137
    @1over137 2 года назад +1

    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.rossburton1972
      @u.rossburton1972 2 года назад

      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.

  • @bigbud41
    @bigbud41 5 лет назад +2

    George Clooney of Python!

  • @sebastiannickel4377
    @sebastiannickel4377 8 лет назад

    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-om6zq
      @Alex-om6zq 8 лет назад +3

      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.

    • @sebastiannickel4377
      @sebastiannickel4377 8 лет назад

      oic! thanks!
      Do you need the @radius.setter annotation for that to work?

    • @Alex-om6zq
      @Alex-om6zq 8 лет назад +2

      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.

  • @akshaydeshpande7382
    @akshaydeshpande7382 7 лет назад +2

    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

  • @AyuPapaBonanza
    @AyuPapaBonanza 6 лет назад +1

    Great talk! I wrote down the code in the talk here www.lvguowei.me/post/python-class-toolkit/ for easy reference.

  • @hectorordonez5495
    @hectorordonez5495 3 года назад

    "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.

  • @ZapOKill
    @ZapOKill 4 года назад +1

    who needs more then 6 decimal_digits of pi?

  • @rishabhkatna8348
    @rishabhkatna8348 3 года назад

    He's like a way smarter Norm Macdonald

  • @CC-sr4zi
    @CC-sr4zi 7 лет назад

    I learned sth new

  • @MaxRoycroft
    @MaxRoycroft 6 лет назад +6

    hah, "consenting adult's language"

  • @arpitgaur4310
    @arpitgaur4310 3 месяца назад

    He speaks so fast

  • @FxAndrej
    @FxAndrej 4 месяца назад

    So am I the only one who struggled to follow because the lecturer talks too fast without pause?

  • @wanderingfido
    @wanderingfido 5 лет назад

    Wrong...you CAN make the instance variables private by prefixing them with two underscores: *self.__radius*.

    • @karelpeeters6240
      @karelpeeters6240 5 лет назад +2

      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.

  • @FlashManinSpace
    @FlashManinSpace 10 лет назад +1

    I learned nothing new from this.

  • @MrTweetyhack
    @MrTweetyhack 8 лет назад

    _init_. haha. python is a good joke.

  • @funprog
    @funprog 11 лет назад +5

    Excellent, but stop saying "who learned something new" its tedious

  • @ବିକାଶ_Biswal
    @ବିକାଶ_Biswal 7 лет назад

    Only theory demonstration. It's a very boring class.