You Should Be Using This For Work/Research in Python | OOP Tutorial

Поделиться
HTML-код
  • Опубликовано: 3 июн 2024
  • In this video I give a brief overview of Object Oriented Programming in python and how it can be used to help organize complicated problems and make your work speed much more efficient.
    Code:
    github.com/lukepolson/youtube...
    Discord:
    / discord
    0:00 Video Introduction
    1:08 Beginner: How To Use Classes
    9:00 Beginner: Inheritance of Classes
    16:26 Intermediate Problem
    27:42 Advanced Problem
  • НаукаНаука

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

  • @viniciusraphaeldasilva3593
    @viniciusraphaeldasilva3593 2 года назад +83

    Dude, I must say: you're responsible for a significant part of my engineering degree

    • @alboz1327
      @alboz1327 2 года назад +3

      Same, dude's A geniuS

  • @Hacker-at-Large
    @Hacker-at-Large 2 года назад +42

    Nice introduction. Note: “self” is not a keyword, it’s just a convention (strongly encouraged), and super(), without parameters, is entirely sufficient to resolve the parent class.

    • @MrPSolver
      @MrPSolver  2 года назад +12

      Interesting, good to know!

  • @PabloElPianista
    @PabloElPianista 2 года назад +9

    This channel was great for me, I am finishing the degree in physics in Spain and I learned a lot about the Python necessary to overcome and analyze the data in laboratories such as Nuclear. Keep uploading cool simulations! :)

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

    These videos are really helpful. I like how you take time to discuss the details.

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

    This is great! Such a motivation video for making complex functions for my robotics project! Keep up the good work

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

    These videos are incredibly helpful. Thank you so much for your effort.

  • @AJ-et3vf
    @AJ-et3vf 2 года назад

    Wow! Awesome video! Thank you! Very timely and relevant especially for me. I've started learning and implementing Python classes in my code because I'm now dabbling with coding spline functions in Python e.g. Linear, Quadratic, or Cubic Splines and their several subtypes e.g. periodic, clamped, natural, not-a-knot, etc. Classes become necessary when coding these because you need to have a way to be able to hold on to the x and y inputs you give and then pass and manipulate them to form the spline function you want to use. Doing it by functional programming becomes tedious because you would then have to define a lot of functions in your name space, "polluting" the name space so to speak.
    Again, thank you very much for this.

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

    Your python tutorials are really helpful. Thanks a ton!!

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

    Really well explained! The scientific example certainly helps a lot. Cheers!

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

    I had this course for like a semester in my first year of undergrad, and then I forgot about it. And I've tried to learn this again multiple times over the past 8 years, and I just got more and more confused. And it all makes sense to me again. Thanks, dude. This is life changing.

  • @user-vx3jm1vi6p
    @user-vx3jm1vi6p Год назад

    Thank you so much

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

    Excellent explanation. Thanks a lot for giving us this!

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

    you are special. Different from several RUclipsrs out there.

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

    Thank you so much for uploading such wonderful videos….

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

    Thank you so much for such great videos. It would be awesome if you could make a on Monte Carlo using OOP approach.

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

    Great video ))
    Very very useful))

  • @joeheafner2495
    @joeheafner2495 2 года назад +12

    Great video as always. I think you used the electron’s mass rather than the proton’s mass. Only affects some of the numbers, but just to let you know.

    • @MrPSolver
      @MrPSolver  2 года назад +6

      Hahahaha of course I did 🤦someone needs to take away my MSc in particle physics

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

      I'd say nuclear engineering is not his perfect🎆 kind of job thing...

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

    I really like this video. Thank you.!!!

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

    Man, you are a boss! Thank you

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

    great video!

  • @Louis-ml1zr
    @Louis-ml1zr 2 года назад

    Cool vidéo thanks !

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

    Thanks you for your efforts.
    Please show tutorial on how to use python for denoise., to remove noise from audio.

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

    I do recommend testing the code in PyCharm. "Shadows name from outer scope" are only minor errors.
    For example:
    Keeping the name for the functions `move()` in class Particle and class Proton the same results in a warning:
    "Signature of method 'Proton.move()' does not match signature of the base method in class 'Particle'".
    Traceback errors follow on program execution.
    Ambiguity with inheritance can arise when the parent class and the child class have both a function with the same name,
    but are doing somewhat different things.

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

    Hey do you have OOP stuff using Numpy and Matplotlib, including object movement? Hundreds of us would find that useful for uni python class. The unit is super hard and it's refreshingly easy to understand and engage in your content. If not, PRETTY please?!

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

    Cool!

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

    Useful

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

    oh god another video i can watch more than 5 times to consume till the last grain

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

    You are a gem

  • @slimanebenlala2622
    @slimanebenlala2622 11 месяцев назад

    Why the use of self.something ? what is it exactly ?

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

    My deepest regret is that I didn't learn Python when I was an engineering student.
    Thanks for sharing your expertise mate.

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

    As a noob to python, I came in with some OOP experience, and I'm doing Angela Yu's python course on Udemy. She does more procedural programming, but I wanted to make all my code OOP, so for games in Tkinter or Turtle, I make a class for each object so I can change properties. So I just send attributes to a label function in the class, and it will add a label with all the attributes I want (location, text, font, etc.). It's taking me longer to finish the course, but I think I will finish with stronger skills than most people who complete the course. What do you think?

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

      Hi, dude! I'm also doing the same course and am a little stuck on the snake project and classes.

  • @Tensor-An
    @Tensor-An 2 года назад

    Yo, my guy, you are the best 😎

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

    Hi! Recommended Reading/Watching: Stop Writing Classes at ruclips.net/video/o9pEzgHorH0/видео.html
    Dataclasses: docs.python.org/3/library/dataclasses.html
    Classes are great for a lot of things. Most programming in Python doesn't need many classes. Regular python files are already "module" objects that gives you the thing.do_something() pattern that feels nice. You can also pass functions as arguments to other functions if you want flexible behavior.
    If you're working with complex data types, then classes are great. If you're creating new classes that are not datatypes, but rather express a lot of the behavior of your application or library, you might be getting on a rollercoaster that you can't get off of.

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

    DUDE! This is the most awesome stuff I've seen on youtube yet! Could I request a topic as a lowly medical / biology dude myself? I love the power of mathematics and I know how to program but for the life of me I cannot suffer through integrals and differentials on paper. But then I saw your videos! You can just outsource the boring stuff to python using Sympy??? Now my question, could you teach people like myself how to take a real-life problem and formulate it in a mathematically sound way using differentials and whatnot? Concretely I've tried today to figure out a solution for a problem where you have water flowing into a tank at a certain speed but it has a hole in the bottom where water flows out as well. The only progress I've made however is fill this tank with my own tears of frustration. Or another example let's say I want to try something crazy and apply the diffusion equation to images, how would I go from the conceptual idea to having constructed the basic math needed to kick off the sympy solver? Thanks anyways for the awesome content! Greetings from Belgium!

    • @4001Jester
      @4001Jester Год назад +2

      Just to say something about your diffusion equation comment-sympy is good at solving *ordinary* diffeqs, but the diffusion equation is a *partial* diffeq. as far as I know, you would have to solve it by hand, use an analytic solver more sophisticated than sympy, or come up with a scheme (like finite difference method) to solve it numerically.

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

      "problem where you have water flowing into a tank at a certain speed but it has a hole in the bottom where water flows out as well"?
      see Darcy equation for outflow, but you have inflow too, so make sure is there conservatoin of mass
      the reality is that you have to include soil props and aquifer props as well, but most ignore one of these
      amazing thing is that along the way you'll see that hydraulic heads move with the moon and sun tides, if your reservoir is big enuff

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

    The mistake I noticed in your Proton class is that you used the mass of the electron instead. The mass should be \(1.67\times10^{-27}\). So the displacements should be about a 1000 times less.

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

    why didnt you add self.q to a super class?🤔 15:37

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

    hey, you have written github in the description instead of discord channel I guess

  • @mirkodegliesposti4597
    @mirkodegliesposti4597 8 месяцев назад

    your movies are great and a very recent plesent discovery for me...thanks...but here at 30. 40. the "self.x, self.vx, self.y, self.vy = self.solution.y"...really do not understand the final ".y".... i missing something but i do not know what...thanks for any help

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

    Hmm. Functional programming constraints led to complicated code. Whodathunk? If you need to calculate a Fibonacci sequence, functional programming is fine but it tends to fall over when you get into real systems that need to maintain and transform state.

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

      There's plenty written about how promiscuous state sharing leads to essentially global state. The promise of encapsulation is a lie.

  • @0ferchen
    @0ferchen 2 года назад

    I would recommend not using a single or double character length variables because it becomes a hassle to follow all these letters.

  • @jhawar-ji
    @jhawar-ji 2 года назад +1

    I work with OOP in Python but still watching this 👀

  • @Makabaril
    @Makabaril 2 года назад +3

    No love for dataclasses?

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

    Dude, you mixed up the mass of the proton with the mass of the electron 11:28
    Not that it matters that much for this particular case though.

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

    Functional programming gang rise up

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

    I love Python, but the use of "self." has always driven me a little nuts. I know there's good reasons for it, it's just the vast majority of everything you do in a class, is altering that class's attributes, so why do we always have to specify that which should be the default? Wouldn't it make more sense if "self" was inferred while within a class, and only when accessing an outside object, variable or global, would we have to specify with some kinda tag, like 'global.'
    I've looked up why in the past, just still bugs me I end up with 'self.' all over the place. heh

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

    Naming a callable F in code dealing with kinematics is a bad idea. I saw it and just assumed it's a Force, until you explained it. Short names are bad, short names without comments, in situation where there's another entity that happens to have a similar short name are just terrible. Please call it `func` or something. Awesome otherwise!

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

    I avoid classes in Python like the plague had covid19.

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

    eew no, functional ALWAYS better than OOP. It's a dumb paradigm. Adds too much abstraction for no reason

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

    Puzzled over the trickery below for a while because `p1.solve_motion()` was constantly throwing errors.
    It's working now.
    Gonna test the algorithm a tad more thoroughly in PyCharm since it allows excellent tracing of variables and functions all the way into the Python core modules.
    # Solving a system of differential equations:
    self.solution = solve_ivp(dSdt, [min(self.t), max(self.t)],
    [self.x0, self.vx0, self.y0, self.vy0],
    t_eval=self.t, args=self.args)
    self.x, self.vx, self.y, self.vy = self.solution.y

  • @user-gh4lv2ub2j
    @user-gh4lv2ub2j 6 месяцев назад

    **Writes procedural code, calls it functional** WhY iS mY SpHaGeT nOt WoRkIn???

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

    OOP is not a good programming paradigm. If the functional code was larger than OOP then you have not refactored adequately.

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

      That's a pretty bold statement. According to who?

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

      @@MrPSolver Edsger W. Dijkstra (Pioneer of computer science)
      'Object oriented programs are offered as alternatives to correct ones…''
      Dr. Simon Peyton Jones. (Haskell)
      Joe Armstrong (The creator of Erlang)
      'The problem with object-oriented languages is they’ve got all this implicit environment that they carry around with them. You wanted a banana but what you got was a gorilla holding the banana and the entire jungle.'
      Linus Torvalds (the creator of Linux)
      OOP is a horrible limiting your project to C means that people don’t screw things up with any idiotic “object model” CRAP.
      Brian Will - "Object-Oriented Programming is just Bad".
      OOP _fails_ at the only task it was intended to address, to _manage the complexity_ of procedural codebases. In other words, it was supposed to _improve code organization._
      Good on paper , clean hierarchies of animals, dogs, humans, etc. Then falls flat when the complexity of the application starts increases. Instead of reducing complexity, it encourages promiscuous _sharing of_ mutable state and introduces additional complexity with its numerous design patterns. OOP makes common development practices, like refactoring and testing, needlessly complex.
      Even those who follow OOP generally implement it poorly.
      Jack Diederich - 'OOP Classes are overused'
      As for the refactoring statement. Functional Programming and Data-Oriented Design is demonstrablby more compact than OOP when implemented correctly, ergo repetition or bloat code not refactored.

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

      @@MrPSolver ruclips.net/video/QM1iUe6IofM/видео.html this one is somewhat 'famous' on ytb. But this notion seems to be pretty prevelant as of late.

  • @harp-692
    @harp-692 2 года назад +1

    why are you smart and good looking? sounds like a scam

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

    Sorry but I physically cannot look at your videos because of light theme. No offense.

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

    What you showed us on screen at 0:18 is NOT what functional programming looks like. If you think you're doing FP in python, you probably aren't (unless you're bending over backwards).
    Please stop using the words "functional programming" if you don't know what it means. Functional programming is more abstract, more expressive and cleaner than OOP, and it's apparently not at all what you think it is.
    The term you're probably looking for is "imperative programming", and yeah, that sucks. But it has NOTHING to do with FP. In fact, FP is the polar opposite of imperative programming, and OOP is much more closer to imperative programming than to FP.

  • @RameezRaja-qc9fi
    @RameezRaja-qc9fi 6 месяцев назад

    please make video series on numerical heat transfer and fluid mechanics .
    Always best regards,

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

    You do this sort of thing in PyCharm, and it will give you an Unresolved reference `m` error.
    def solve_motion(self):
    def dSdt(t, S, *args):
    # for vector `S=x, vx, y, vy` return the derivative.
    x, vx, y, vy = S
    return [vx, self.F(t, x, y, vx, vy, m, *args)[0] / self.m,
    vy, self.F(t, x, y, vx, vy, m, *args)[1] / self.m]
    It also thinks that defining the instant atribute `solution` outside __init__ stinks. The same holds true for `x`, `y`, `vx`, `vy`.
    Not to mention the triviality of shadowing variable names from the outer scope.