Pong & Object Oriented Programming - Computerphile

แชร์
ฝัง
  • เผยแพร่เมื่อ 25 ก.ค. 2024
  • Using Pong to demonstrate the strengths of Object Oriented Programming. Dr Steve Bagley explains
    The Singularity & Friendly AI: • The Singularity & Frie...
    Chomsky's Hierarchy: • Chomsky Hierarchy - Co...
    How Bitcoin Works: • How Bitcoin Works - Co...
    AI Safety: • AI Safety - Computerphile
    / computerphile
    / computer_phile
    This video was filmed and edited by Sean Riley.
    Computer Science at the University of Nottingham: bit.ly/nottscomputer
    Computerphile is a sister project to Brady Haran's Numberphile. More at www.bradyharan.com

ความคิดเห็น • 532

  • @ButzPunk
    @ButzPunk 8 ปีที่แล้ว +115

    This really took me back to my Java/C++ classes. It's funny how knowledge can lie dormant and forgotten in your brain, but then with the right little push, you remember all this stuff you thought was long gone.

    • @spitalhelles3380
      @spitalhelles3380 5 ปีที่แล้ว +12

      funny how you can just access it without calling the memory function of an object of the subclass IT-class of the class lecture first.

  • @saintjerome8579
    @saintjerome8579 2 ปีที่แล้ว +6

    This is the best, clearest explanation for OOP I've ever heard. Of only my high school programming teachers had made it that clear.

    • @lepidoptera9337
      @lepidoptera9337 ปีที่แล้ว +3

      They shouldn't teach you OOP in high school to begin with. Chances are that they are screwing up your mind with all the wrong ideas about what OOP does.

  • @ArchAngelSlayer1
    @ArchAngelSlayer1 8 ปีที่แล้ว +47

    That was the greatest crash message ever.
    exception: blahblahblah
    kernelpanic: blahdiblahdiblah
    help!

  • @leonhrad
    @leonhrad 8 ปีที่แล้ว +459

    How about another video to demonstrate the weak points of Object Oriented Programming?

    • @betlamed
      @betlamed 8 ปีที่แล้ว +4

      +Leo S I think they already have something on paradigms.

    • @juneguts
      @juneguts 8 ปีที่แล้ว +63

      +Leo S So a video with nothing in it?

    • @edgeeffect
      @edgeeffect 8 ปีที่แล้ว +115

      +AnUntitledAbridger I think I could quite easily find 40,000 engineers, philosophers and scientists who would find your assertion that anything, anywhere has no weak points to be, at best, very naive.

    • @betlamed
      @betlamed 8 ปีที่แล้ว +36

      +AnUntitledAbridger FunctionalWeenie shitstorm in 3...2...1...

    • @Coolfolder
      @Coolfolder 8 ปีที่แล้ว +1

      +betlamed Oh awesome! I'd love to watch it, do you remember anything about the title of that video?

  • @ElagabalusRex
    @ElagabalusRex 8 ปีที่แล้ว +15

    I personally prefer using the bank account example that many authors like, because it's easier to explain certain things like inheritance, initialization, and mutators than in the GUI example.

    • @ihrbekommtmeinenrichtigennamen
      @ihrbekommtmeinenrichtigennamen 8 ปีที่แล้ว +4

      +ElagabalusRex
      I partially agree. A lot of typical programming class examples don't work out nicely when you try to implement them. Something I notice people often get wrong is a "contains" relationship because it means different things in programming and in reality. A car contains an engine, sure. But this often leads to the conclusion that the car-class should have a property pointing to the engine ("the car-class contains an engine-property"). One may want to implement it that way but whether that actually makes sense in that specific case depends on what the program should do.

  • @thetradefloor
    @thetradefloor 8 ปีที่แล้ว +86

    I was taught to think about objects as being similar to Pokemon ahah

    • @85set05
      @85set05 8 ปีที่แล้ว +21

      so if you add a method and you already have for you have to remove one also removing certin methods would require you to visit an old man

    • @85set05
      @85set05 8 ปีที่แล้ว

      ***** 151

    • @huehuehuehuehuehuehuehuehuehue
      @huehuehuehuehuehuehuehuehuehue 8 ปีที่แล้ว +1

      Dr. Steve Bagley is my favourite hamster.

    • @voussoirnet
      @voussoirnet 8 ปีที่แล้ว +37

      +TheUmbrellaCorpX7
      State: Level, EXP, attack, defense, speed, and other attributes
      Methods: Attacking, taking damage, healing, learning new moves
      Identity: Even if you have multiple of the same pokemon with the same level and the same moves, they are still separate entities and behave individually.
      That would be my interpretation of his pokemon analogy.

    • @Niki_0001
      @Niki_0001 8 ปีที่แล้ว +3

      +Voussoir And suddenly I feel enlightened :o
      I kind of understood objects before, but now I can actually see how useful they can be. Thank you!

  • @noxabellus
    @noxabellus 6 ปีที่แล้ว +9

    All you need to take away from OOP is the idea of associating a function with a type, so that you can call type_instance.function() easily. Everything else is more trouble than its worth. Especially classical inheritance.
    And I'm saying this as a game dev. If I can make a whole game with has-a relationships rather than is-a's then you certainly can for business applications.

    • @SeverityOne
      @SeverityOne 2 ปีที่แล้ว +2

      While I'm a great proponent of OOP, with this I have to absolutely concur. Inheritance is useful in a limited set of circumstances. I've yet to meet the first customer who wants me to write an application featuring Dogs and Cats, both derived from the Pet class.
      Without going into too much detail, I once had to deal with an application that was so incredibly full of is-a relationships, that a piece of code to read in data (exchange rates, although this is not relevant) had so much binding to other classes and libraries, that by trying to isolate just this class and adding the dependencies, I ended up with a class that calculated sunrise and sunset.
      Now this was from a developer who had some pretty set ideas, and although he was clever, this intransigence meant that the code was essentially impossible to refactor. The guy would write his own implementations of freaking everything, or at the very least a facade, even if a widely adopted standard existed. Like a logging framework.

  • @TheBedrockCreeper
    @TheBedrockCreeper 8 ปีที่แล้ว +39

    Ok, now you need to cover functional programming too! :)

  • @pehash
    @pehash 3 ปีที่แล้ว +2

    I would love a smart guy like this to stream or record a video of a simple game development, like pong for example, and explain everything he does in ample details and simplified in the same time. I would sit there for hours with a huge popcorn bag just listening to the guy.

  • @BlueDraEv
    @BlueDraEv 8 ปีที่แล้ว +10

    Great simplified explanation!

  • @Mistermatt-96
    @Mistermatt-96 8 ปีที่แล้ว +7

    I spent half a year of college doing object oriented programming in c++, this explanation has made things so clear! cheers!

  • @wesofx8148
    @wesofx8148 8 ปีที่แล้ว +3

    OOP really shines when you have Vector objects and Matrix objects that just know how to be multiplied and added together. So easy!

    • @lm1338
      @lm1338 5 ปีที่แล้ว +2

      That's nothing to do with OO, that's operator overloading

  • @justawatchin2
    @justawatchin2 7 ปีที่แล้ว +2

    I'm in the middle of redesigning my first proper Python program (a recordable looper for guitar/keyboard etc.) using classes. I typically have upwards of 20 loops running at once and before this I was making them all be nested dictionaries of variables and (ironically) classes coded by another person. It worked but was a horrible mess, and I only wrote them that way because I didn't understand Python classes enough to test them out. It's taking a bit of time to rewrite the program but it's so so so worth it. Code is so much easier to read and operate and is in some cases half the length.

  • @sierrabravo7368
    @sierrabravo7368 8 ปีที่แล้ว +1

    I knew that I should use getters and setters but the way it was explained in the video was really good

  • @NoahSpurrier
    @NoahSpurrier 2 ปีที่แล้ว +4

    The problem with OOP as implemented is that it’s not supposed to be difficult to wrap your head around; it’s not supposed to be more complicated; it’s not supposed to make programming harder. It’s supposed to help manage complexity; it’s supposed to be easier to understand; it’s supposed to make our jobs easier. We should ask why new programmers are intimidated by it. We should ask why has OOP not lived up to the promises.

    • @atlantic_love
      @atlantic_love ปีที่แล้ว +1

      For me I'm perplexed with semantics involving object design. Should the logic and user interaction come from within main(), or should my objects also have methods for input from user?

    • @bkucenski
      @bkucenski ปีที่แล้ว +1

      It has. People care more about patterns and copying and pasting code than making things easier. OO done correctly makes things easier and reduces code.

  • @SonOfMeme
    @SonOfMeme 8 ปีที่แล้ว +2

    Really helped me understand OOP! Thanks, Computerphile!

  • @manuelengel3680
    @manuelengel3680 5 ปีที่แล้ว +4

    4:56 Best Blue Screen/Kernel Panic ever

  • @Vekkq
    @Vekkq 8 ปีที่แล้ว +3

    In many functional programming languages, access to nontrivial data is also restricted to certain functions. However, FP emphases to keep data as simple and open as possible and functions as general as reasonable.

  • @Kylefassbinderful
    @Kylefassbinderful 6 ปีที่แล้ว +3

    I really appreciate how you visually explained Object Oriented Programming. This is the first time I'm starting to grasp it.

  • @spikeguy33
    @spikeguy33 8 ปีที่แล้ว +75

    I feel like there is no way I could have understood this video if I didn't already have basic understanding of 'object oriented programming'. I think these videos have to appeal to ~90% of the viewers, but all it did is explain how to program a pong game to a person who already has some idea of how to do it.
    (This is assuming the video meant to explain 'Object Oriented Programming' to the general public)

    • @MuradBeybalaev
      @MuradBeybalaev 7 ปีที่แล้ว +8

      >assuming the video meant to explain 'Object Oriented Programming'
      I think the title suggests otherwise.

  • @BlackFoxLovesYou
    @BlackFoxLovesYou 4 ปีที่แล้ว

    Did the Inheritance video he mentioned ever get made? Would love to watch that if it hasn’t!

  • @derstreber2
    @derstreber2 8 ปีที่แล้ว +17

    yay for data oriented programming

  • @minijimi
    @minijimi 8 ปีที่แล้ว +1

    Thanks for putting it into words.

  • @Cypeq
    @Cypeq 2 ปีที่แล้ว +1

    Brilliant... Such a great way to tech object oriented programming. It's so simple too. Make a fun simple game, not a school or other boring structure.

  • @marcusrossel4638
    @marcusrossel4638 8 ปีที่แล้ว +2

    How about videos on Protocol Oriented Programming, after this series concludes?

  • @pinklady7184
    @pinklady7184 7 ปีที่แล้ว +1

    As house is to blueprint, object is to class. Thanks for simplifying that.

  • @AndresRodriguezGuapacha
    @AndresRodriguezGuapacha 8 ปีที่แล้ว +4

    Can you do another video explaining Functional Programming?

  • @cbwatters
    @cbwatters ปีที่แล้ว

    SB's facial expression for objects, @5:09, just excellent 'of Objects'

  • @atlantic_love
    @atlantic_love ปีที่แล้ว +3

    One of my favorite channels. I'd like to see him talk about how to do OOD (Object Oriented Design). For instance I'm bogged down right now in making my own classes that represent things like Container, Random and Sort. I don't know whether I'm supposed to write my program such as interaction with the user comes from within main(), or if the user interaction should come from within in the objects. I'm using C++ and this is just a hobby of mine.

    • @Luca-tw9fk
      @Luca-tw9fk ปีที่แล้ว +1

      Agree and would love to a vid on OOD. I mainly program in java but here are my thoughts: to use sort as an example, I'd have a class that handles the sorting algorithms, with a method that accepts and returns a data structure for each. I'd then have a class that handles the set up of the GUI, stores user input in a data structure, and calls the appropriate method on it. I like to keep the amount of code in the main method to a minimum, and tend to initialize all of my objects in a seperate method within the same class that holds the main method

    • @atlantic_love
      @atlantic_love ปีที่แล้ว

      @@Luca-tw9fk in C++ I'm only doing console programming because it's not user friendly to set up C++ compilers to work with gui frameworks. Even I'm console programming I'm doing what you're suggesting:. A class for sorting, with static methods. Seems overkill to create an object that doesn't have any state or is passed around. Do you mean that within one of your classes you instantiate a number of classes?

    • @lepidoptera9337
      @lepidoptera9337 ปีที่แล้ว +1

      @@atlantic_love All of this can be done easily and without any confusion with libraries.

    • @atlantic_love
      @atlantic_love ปีที่แล้ว

      @@lepidoptera9337 What language are you talking about? Which libraries?

    • @lepidoptera9337
      @lepidoptera9337 ปีที่แล้ว

      @@atlantic_love Any language. A universal sort algorithm is nice, academically speaking... but in practice it doesn't matter. How many hundred different types are you sorting in a single application? And even if you want to sort different types with the same algorithm, then what does it really take? A few function pointers in C. That's it.

  • @groosalugg_
    @groosalugg_ 4 ปีที่แล้ว

    This is a brilliant explanation.

  • @SteamsNightcore
    @SteamsNightcore 8 ปีที่แล้ว

    We had to program a version of object oriented pong in my computer class using java. It was good fun, but very difficult, so when I saw this video, I had to watch.

  • @OrchidAlloy
    @OrchidAlloy 8 ปีที่แล้ว +1

    I taught myself how to program basic C++ and sometimes do stuff for fun. Some time ago I made a basic Pong on the Windows CMD. This video will be interesting!

    • @OrchidAlloy
      @OrchidAlloy 8 ปีที่แล้ว

      Noe Alvarez ~16. Does it matter? I just did it for fun! :) It was a challenge to test the limits of the Windows command console... It works pretty well for what it is. I wanted to further improve it, but got bored. Still, it was a nice, short, amateur project with decent results.
      Here's a link for the code: dl.dropboxusercontent.com/u/43721327/C%2B%2B/PongOld/Pong.cpp
      Or, also, the executable: dl.dropboxusercontent.com/u/43721327/C%2B%2B/PongOld/Pong.exe
      You stat the game with the spacebar. W and S control the left paddle, up and down arrowkeys control the right paddle. You have to press repeatedly to move, instead of holding down.

    • @noealva
      @noealva 8 ปีที่แล้ว +1

      i didnt know you could do this in the command console. what page did you learn this from? i only code maths and strategy oriented programs.

    • @noealva
      @noealva 8 ปีที่แล้ว +1

      ***** Thanks, I'll check it out.

  • @TechXSoftware
    @TechXSoftware 8 ปีที่แล้ว +2

    I program a lot it's easy for me to get my head around it, it actually makes things easier.

  • @WatsitTooyah
    @WatsitTooyah 8 ปีที่แล้ว

    This is great, more like this!

  • @nERVEcenter117
    @nERVEcenter117 8 ปีที่แล้ว +2

    2:28 We could literally stop here, represent the paddles and the ball as maps, and represent their movement on the canvas (new paddles at their new positions) as functions of those maps. Then a game function that uses tail recursion to loop endlessly and call those functions. That's it. No need for OOP, no need to worry about memory at all!

    • @DFX2KX
      @DFX2KX 8 ปีที่แล้ว +1

      +nERVEcenter117 true, but that doesn't make it a less intuitive example to demonstrate the principle. OOP's upside is when you're interfacing with a game engine that has 1,000-1,500 functions in it, and only a small fraction of those are going to be needed for any one task. You do pay a tidbit in resource load for the convenience, but I haven't met TOO many people who are willing to take the loss.

    • @nERVEcenter117
      @nERVEcenter117 8 ปีที่แล้ว +2

      DFX2KX I don't understand how there would be a disadvantage here in functional style. Languages like F# and Clojure have very convenient namespace semantics, including ways to reference just one or a few functions out of a namespace. Browsing such large codebases tends to be easier than OO languages, because you don't need to look at giant object signatures for the one that contains the methods you want, nor do you have to instantiate that object and deal with referencing it. You just call a function.

  • @ghelyar
    @ghelyar 8 ปีที่แล้ว +1

    I got a youtube error at 4:57, where it talks about crashing and shows a BSOD, and thought it was part of the video.

  • @rstriker21
    @rstriker21 8 ปีที่แล้ว +31

    Such a simple game with not as simple code.

    • @noahhall2302
      @noahhall2302 8 ปีที่แล้ว +19

      Nah it's p. simple

    • @MazelTovCocktail
      @MazelTovCocktail 8 ปีที่แล้ว +5

      They really did a lot a ground breaking work to make that game. Pong seems simple now but it was a feat of engineering and science back in the day. Really ingenious stuff.

    • @AlexanderBollbach
      @AlexanderBollbach 8 ปีที่แล้ว +5

      +youdontknowxpand he said "not as simple code". compared to a ball bouncing back and forth it is "not AS simple".

    • @Tfin
      @Tfin 8 ปีที่แล้ว +1

      +Alexander Bollbach
      It barely qualified as "code" at all. It's like calling a wiring diagram code.

    • @AlexanderBollbach
      @AlexanderBollbach 8 ปีที่แล้ว +2

      what qualifies as "code" to you

  • @realraven2000
    @realraven2000 8 ปีที่แล้ว +3

    Do one on JSON :) that one makes objects really easy. Coming from C++ originally what I like about JavaScript is that the classes are already instances:
    pos = {
    x: 5,
    y: 7,
    moveVert: function myMoveVert(n) { this.y += n; }
    }
    pos.moveUp = function() { this.moveVert(1); }
    pos.moveDown = function() { this.moveVert(-1); }

    • @godfather7339
      @godfather7339 2 ปีที่แล้ว +2

      I think that's called prototype based programming rather than class based.

  • @edgeeffect
    @edgeeffect 8 ปีที่แล้ว +187

    "I used to be enamoured of object-oriented programming. I'm now finding myself leaning toward believing that it is a plot designed to destroy joy." - Eric Allman
    "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." - Joe Armstrong

    • @code-dredd
      @code-dredd 8 ปีที่แล้ว +46

      +edgeeffect The first quote really says nothing about OOP, and the 2nd seems to be more about programmers than the method they use to program.

    • @1yaz
      @1yaz 8 ปีที่แล้ว +7

      Seems like the only people who are not for OOP are the people who do not understand it.
      Not trying to say OOP is always recommended.

    • @thefauvel7558
      @thefauvel7558 8 ปีที่แล้ว +4

      +Yazen Alzaghameem A lot of people aren't for OOP.

    • @1yaz
      @1yaz 8 ปีที่แล้ว +1

      CaesarGamer Explain to me how inheritance is generally bad. Polymorphism + Implementation Independence is bad?

    • @code-dredd
      @code-dredd 8 ปีที่แล้ว +2

      +Yazen Alzaghameem Inheritance does not give you the independence you mention (unless you're implementing interfaces). Inheriting from other classes generally violates encapsulation because the child relies on the parent's implementation details.

  • @MM-sc5ux
    @MM-sc5ux 8 ปีที่แล้ว +8

    Very helpful video! Could you please explain the MVC paradigm visually the next time?

    • @edgeeffect
      @edgeeffect 8 ปีที่แล้ว +3

      +Tai Le MVC is hardly a paradigm... it's just one simple case of OOP... a design pattern.

    • @MM-sc5ux
      @MM-sc5ux 8 ปีที่แล้ว

      say this to my college professors

    • @dexter9313
      @dexter9313 8 ปีที่แล้ว +1

      +Tai Le Maybe you didn't listen to your college professors carefully enough, because edgeeffect is right.

    • @boenrobot
      @boenrobot 8 ปีที่แล้ว +2

      +Tai Le Many people (not just college professors) use the word "paradigm" as a synonym for "approach", which is the real problem. Both "design patterns" and "programming paradigms" are "approaches to solving problems"... But they aim to solve different categories of problems. Nevertheless, due to a simplified vocabulary, it's easy for anyone to get confused. It's like how in physics there's "technically" a difference between "speed" and "velocity" (I'm not sure what it was, but I remember a few Sixty Symbols videos about the fact it was a thing...), but in every day speech, we use the two words as synonyms.

    • @juggernaut93
      @juggernaut93 8 ปีที่แล้ว +2

      +boenrobot Velocity is a vector and speed is its modulus IIRC

  • @mohammadshahabrafiq
    @mohammadshahabrafiq 11 หลายเดือนก่อน

    Excellent video.

  • @U014B
    @U014B 8 ปีที่แล้ว +6

    Is this what runs the machine that goes "PING!"?

  • @kranser
    @kranser 8 ปีที่แล้ว +1

    To make the paddles object orientated, you would need data inside the paddle to store the keys for moving up and down and also operations to allow these key values to be set from outside the object. Also an undraw operation would be helpful.

    • @stensoft
      @stensoft 8 ปีที่แล้ว

      +kranser You don't need undraw, you just redraw the board (but you need the board object).
      The keys should not be handled by the paddles but by some input system (what if you wanted to use joystick or Wii?). Which should have its own object.

    • @kranser
      @kranser 8 ปีที่แล้ว

      +Jan Sten Adámek Thanks for the information. If the input is an object in itself, how can the paddle object be duplicated to make 2 objects (same data structure and operations, but unique reference)? I guess the input object would reference the individual paddle objects by unique reference number, correct?

    • @stensoft
      @stensoft 8 ปีที่แล้ว

      kranser Yes, that are the identities he was talking about. The input object will have two references, one for each paddle's identity.

  • @peteBS147
    @peteBS147 8 ปีที่แล้ว +1

    Thank you Dr Steve, your video was clear and very helpful. However, there is one thing that is confusing me?
    Given that both the paddle and the ball have an X,Y position, does the:-
    paddle look out for whether it has hit the ball or
    the ball look out for whether it has hit the paddle?
    Perhaps they are equally valid?
    Many thanks,
    Pete

    • @asz1029
      @asz1029 7 ปีที่แล้ว

      I would say the container object (which was forgotten in the video, and has 'Width', 'Height', and 'ContainedObjects') should look out for any two objects which are contained in it colliding either with each other or the container's wall.

    • @mikicerise6250
      @mikicerise6250 2 ปีที่แล้ว

      If the ball is below the paddle when you try to move the paddle down, wouldn't the paddle and ball need some logic to avoid one being drawn over the other? Where would that logic go?

  • @JuusoAlasuutari
    @JuusoAlasuutari 8 ปีที่แล้ว +73

    Directly referencing an object's data without using its interface? That's a paddlin'.

    • @pumpkinot9900
      @pumpkinot9900 3 ปีที่แล้ว +2

      I don’t get it.

    • @hognosemyan
      @hognosemyan 3 ปีที่แล้ว

      ​@@pumpkinot9900
      public int a;
      return this.a;
      vs
      private int a;
      public int getA() { return this.a; }
      make everything as private as possible

  • @kametrixomtikara8726
    @kametrixomtikara8726 8 ปีที่แล้ว +1

    Much better than the first video on OOP haha

  • @verifiedpurchase3486
    @verifiedpurchase3486 8 ปีที่แล้ว

    +Computerphile The jump clips in the endroll are not linked to the videos they show.

  • @jasevl
    @jasevl 8 ปีที่แล้ว +7

    I like to think of objects as something like a television. You interface with the TV through a remote and can change channels etc. However you don't need to know all the work the TV is doing internally to display an image and change the channel etc All you need to know are the functions of the remote..

    • @kristupasantanavicius9093
      @kristupasantanavicius9093 5 ปีที่แล้ว

      This has nothing to do with objects or object oriented programming. This is just engineering. You take a complex process, and you create a simple interface for the said process.

  • @boenrobot
    @boenrobot 8 ปีที่แล้ว +4

    9:07 - 9:11 THIS! In my experience (primarily in talking to university classmates and in forums...), the only way people REALLY start to get it is when you START the explanation with this, because that IS what it boils down to. To the uninitiated, OOP sounds like "this complicated, yet magical thing that you can't do without", when in reality, it's more like keeping your room tidy - you still have the same toys, it's just that having them all ordered gives you a different feeling... And chicks dig it better (in general)!

  • @ojamamask
    @ojamamask 8 ปีที่แล้ว +2

    please explain declarative programming

  • @tgckpgAtgmail
    @tgckpgAtgmail 8 ปีที่แล้ว

    Can you do an introduction about AOP? Wikipedia said it is patented by Xerox. And there isn't much information or resources out there.

  • @srinidhiskanda754
    @srinidhiskanda754 7 ปีที่แล้ว

    thank you oop vs functional which is better in what situation

  • @rogernevez5187
    @rogernevez5187 5 ปีที่แล้ว +2

    8:40 "We write the code not in terms of data manipulation, but in terms of telling this object to move up or down."
    This could be easily done with *procedural language* + contexts.
    Still, I don't see why migrate to OOP.

    • @SeverityOne
      @SeverityOne 2 ปีที่แล้ว

      Because a bat has an immutable Y-position. You cannot do that in a procedural language, because every part of the program can access every piece of data. That's why.

    • @atlantic_love
      @atlantic_love ปีที่แล้ว

      @@SeverityOne Yes, you can do it in a procedural language. Using while loops, and separate variable names representing state for each paddle and the ball. You'd then have a function that specifically accesses each of those variables and changes their values. By having distinct variable names you mimic immutability. PaddleA_posX, PaddleB_posX.

  • @AmeshaSpentaArmaiti
    @AmeshaSpentaArmaiti 8 ปีที่แล้ว

    why did it take so long to reach this topic of discussion? it's usually one of the first things CS oriented channels cover.

  • @Maver1ck101
    @Maver1ck101 7 ปีที่แล้ว +2

    Forgive me for saying this, but Prof. Bagley reminds me of Bob from the Tekken fighting game franchise.

  • @suicidalbanananana
    @suicidalbanananana 4 ปีที่แล้ว +3

    "Its probably not going to be more then a few hundred lines long"
    Honestly that sounds like way to much code, even if you'd go completely overboard with OOP

  • @MikelNaUsaCom
    @MikelNaUsaCom 5 ปีที่แล้ว

    having a deterministic size for the objects make garbage collection much easier to automate. IE making them strongly typed objects - especially if all your primitives are derived from a single base object.

  • @HadrianDan
    @HadrianDan 6 ปีที่แล้ว

    Then in base, of Object Oriented Programming, the shapes or models are the objects or shapes inside shapes are objects of other objects and whatever is then in manipulate are the operations on the objects or something, correct if wrong. Where the object is a program in itself as well and each object has its own identity with own set of rules. A class is a blueprint to all of that also and stuff is and then the computer interprets and then does compile if it makes sense or whatnot.

  • @LincolnBerryIII
    @LincolnBerryIII 6 ปีที่แล้ว +1

    *To move player 1 paddle "up":* paddle1._ypos = paddle1._ypos - 1

  • @aloluk
    @aloluk 6 ปีที่แล้ว

    By the way, the screen would not be only represented by the computer, because what happens to the ball when it goes off the top/bottom of the screen?

  • @logancapes
    @logancapes 5 ปีที่แล้ว

    geez, what kind of razor does dr bagley use? skin so smooth i thought he was computer generated. 6:54

  • @YouHolli
    @YouHolli 8 ปีที่แล้ว +25

    There is one crucial object missing in this example: the board itself.

    • @vuurniacsquarewave5091
      @vuurniacsquarewave5091 8 ปีที่แล้ว +9

      +YouHolli Why is that needed? The ball would know when it hits a wall once its Y coordinate is less than the upper wall or more than the lower wall.

    • @SheikahZeo
      @SheikahZeo 8 ปีที่แล้ว +5

      +za909returns None of the classes are needed. You give a perfectly good rule for the ball hitting the wall, but it's irrelevant. The questions you're answering when you define a class are who should have to know the rule and who gets to change the rule, not what the rule is.

    • @YouHolli
      @YouHolli 8 ปีที่แล้ว +24

      +za909returns The ball is not supposed to know anything about it's surroundings.What if you want to support boards with different shapes or sizes?

    • @grantcivyt
      @grantcivyt 8 ปีที่แล้ว

      +DC I think we agree. In addition to its position, it probably should know its shape as well.

    • @XLsDiary
      @XLsDiary 8 ปีที่แล้ว +1

      +YouHolli Pong is actually perfect to show strength and weaknesses of OOP at the same time. DrawYourself is easy in OOP. Detecting collisions is ugly. Whom are you going to ask, if every object only knows it's own position and shape?

  • @yash1152
    @yash1152 2 ปีที่แล้ว

    12:34 to which video was the audio in sync with??

  • @SyedRizvii
    @SyedRizvii 8 ปีที่แล้ว

    a little demo code in C or Java or any suitable language would be much appreciated. It would help in consolidating the concept. Great video though! cheers.

  • @RealCadde
    @RealCadde 8 ปีที่แล้ว +1

    Difficult to get your head around it?
    I started off with Basic, then QBasic, then i had a long pause from programming (regrettably) and then dabbled some with VB 4, 5, 6.
    My interest in programming only ever took off for real when i started messing with VB.Net and later i converted to C# and only now have i come to some sort of grasp with non object oriented languages.
    I must say, object oriented programming is what got me into programming for real to begin with.

  • @davef21370
    @davef21370 6 ปีที่แล้ว

    I like to the analogy of Space Invaders and Galaxian. Space Invaders could be programmed using a bunch of arrays, x-y values and speed. Galaxian needed a simple AI for the groups to break off and swoop down. That would be far easier using OO.

  • @chrisjohnson7255
    @chrisjohnson7255 8 ปีที่แล้ว

    Say I was programming a checkers game in object oriented Design, how could the piece know if it jumped another piece.assuming that the pieces know their location.

    • @DaggetDoofus
      @DaggetDoofus 8 ปีที่แล้ว +2

      You'd have, on a larger scope, a checkers board object holding the position (square) of each piece.

  • @andrewmorris483
    @andrewmorris483 8 ปีที่แล้ว

    They need to do one in the BSOD. I wonder why it isn't green or red for example. Also the origin of it

  • @ToniT800
    @ToniT800 8 ปีที่แล้ว

    But how does the ball object interact with paddle object?
    Do they share common variables?

    • @aiman4036
      @aiman4036 8 ปีที่แล้ว

      +Toni T800 The design Dr. Steve came up with was very minimal. But how it'd be done is via adding another operation (they're in fact technically referred to as methods, not operations) for the pad class; e.g: "handle_collision". In your code, you usually then do:
      pad1.handle_collision(ball)
      pad2.handle_collision(ball)
      The handle_collision method will reach out to see the ball's position and size, and see if the ball intersects with the box its position and size makes. If true, the operation will reverse the x-speed there.

    • @TheUglyGnome
      @TheUglyGnome 8 ปีที่แล้ว +1

      +Toni T800 Definitely not shared variables. One way to do this:
      There's object 'Pong' which is in charge of gameplay
      1. 'Pong' asks paddle, if it collides with ball
      2. Paddle asks ball it's position
      3. Paddle now knows if it collided and tells result to Pong
      4. If collision happened, Pong tells ball to change it's direction

  • @tomeubank3625
    @tomeubank3625 8 ปีที่แล้ว

    You neglected to mention an essential property of the ball: its direction of movement, ie, it's a vector. Also, if it were a real ball, it would have mass, momentum, and a surface area with a coefficient of friction, generating a constantly decelerating force that would interact with the downward force of gravity to continuously alter its direction and velocity. And an even more real ball would have rotational inertia, etc. OOP makes it possible to encapsulate all of this data and processing into a single block of code. As you pointed out, OOP may be overkill for Pong, but not for more realistic simulations involving numerous entities with similar properties. For a more immediate example of OOP, the screen image we are reading is generated from literally hundreds of objects each with its own properties and methods.

  • @ChristopherGaul
    @ChristopherGaul 8 ปีที่แล้ว +11

    Good explanation though it leaves out one of the main reasons for Object Oriented Programing, to allow software mills to turn programmers into modular, expendable, commodities. aka objects.

    • @AlqGo
      @AlqGo 8 ปีที่แล้ว

      Aye! To reuse code and, therefore, to cut down costs.

    • @ChristopherGaul
      @ChristopherGaul 8 ปีที่แล้ว +1

      antiHUMANDesigns
      First, I mostly agree with you.
      However, one other issue I have is that OOP is also used by software sweatshops to allow more parallelism in the coding. That is dumping of different sections and even objects to different coders or teams. I personally question the performance and quality of code that results from this practice.
      Either they don't spend time developing coding _and_ documenting coding standards. In which case they spend the time later making it work and inter-operate. Or they _do_ have the standards, which also act as a restraint on the programmers, keeping them from coding the best, most task optimal, least bloated code possible.

    • @antiHUMANDesigns
      @antiHUMANDesigns 8 ปีที่แล้ว

      Christopher Gaul Yes, those are valid concerns. But is none OOP really going to guarantee taht none of this happens? And can you feasibly do the same things and in about the same time without OOP?
      Of course, I have no experience working with a large team, so I don't know what naturally happens, other than "rumors" I hear about it, which I must assume is slightly based on confirmation bias, or "circling the hits, but not the misses".
      Even though I don't have the experience of large teams, I still like the idea that you can have one team separately working on one "module", while another one works on some other, and as long as they agree on an interfacce, it'll work. Without this possibility, I just don't see how you can be as efficient/productive. If you have to actually care about *how* other people wrote their implementation, then it's going to be slow *and* overwhelming.
      Abstraction fixes this. Of course, perhaps abstraction isn't strictly exclusive to OOP, I'm not expert on the terminology, but it would seem like abstraction is an OOP style idea.

    • @UltimaWeaponz
      @UltimaWeaponz 8 ปีที่แล้ว +3

      +Christopher Gaul I disagree. I've been working as a developer for a couple years now and what you say about turning programmers into modular and expendable people is exactly what you want. You want the code to be self documented. You want any experienced programmer to be able to read and understand the code, and expand upon it. Sure, it might not be the most optimised code in the world, but it develops fast and if tested properly, works. I think OOP was the major breakthrough that has allowed the fast evolution of the digital world.
      Also, as a developer, I don't want my work to be something only I can understand, which is what happens in my spaghetti code imperative languages. I want to be able to move to other projects, companies, and have my work last and be improved by others. I think you have never actually been a developer to say those things.

    • @mlhbro
      @mlhbro 6 ปีที่แล้ว +1

      Yes, you're so right. The only purpose of code reuse is to cut down costs. What a genius take.
      I mean, seriously, is there ANY programmer who, when they realize a repeated section of code needs a change, absolutely adores having to go back and make the changes in several places? What programmer has ever wanted to perform this sort of busywork?

  • @silkwesir1444
    @silkwesir1444 6 ปีที่แล้ว

    2:35 of course, this is not what this video is about, but I would be interested in a video about that subject.
    the way it is shown there, to just adjust the position linearly while the key is pressed, is a kind of naive approach which won't work out as a proper replacement for the paddle controllers where you could turn the knobs and determine yourself how far and how fast you turn it.
    however, now you want to make a Pong game that is playable and fun with key presses, which only can be ON or OFF, nothing inbetween.
    usually, the way it is attempted to "solve" this, is by adding some kind of acceleration, so if you only tap the key quickly, it moves just a little bit to allow for fine movement, however the longer you hold it down, the faster it will go.
    however, what kind of function to use for this acceleration? there are many possibilities.
    i think this really is an "unsolvable" problem, meaning there is no "proper" way to solve it, but a lot of ways one can go about it which might be "good enough".
    is there one that is the best?
    are there differing opinions?

  • @betlamed
    @betlamed 8 ปีที่แล้ว

    Hmmm... interesting background there!

  • @fobusas
    @fobusas 8 ปีที่แล้ว

    How OOP is related to APIs? On the surface they seem to be very much related concepts, with main difference being scale?

    • @boenrobot
      @boenrobot 8 ปีที่แล้ว

      +Vaidas Šukauskas In simple (if not over-simplistic) terms, the word "API" refers to the actual "thing" that everyone sees out of your program/library from the outside ("outside" often being "their program/library"), whereas OOP is one way in which this thing could work on the inside.In slightly more technical terms, an API could be just a set of functions (which is not OOP), whereas OOP is how structures like "classes" and similar ones work (and that's another way to create an API).

    • @DFX2KX
      @DFX2KX 8 ปีที่แล้ว

      +boenrobot and now and again, you'll have APIs that take a bit from both collums, which is arguably more confusing then it needs to be....

  • @HemmligtNavn
    @HemmligtNavn 8 ปีที่แล้ว

    I think the statement at around 11:50 that the rest of the program doesn't need to know anything about the object's behaviour should be prefixed by "for a single threaded program" ....

    • @ihrbekommtmeinenrichtigennamen
      @ihrbekommtmeinenrichtigennamen 8 ปีที่แล้ว

      +Hemmeligt Navn
      I think that's a bit far-fetched, especially for beginners. It should be documented whether a class (or any element of a program) is thread safe.
      If it's not thread safe and you use multithreading anyways then all bets are off anyways.
      If it's thread safe then the behaviour should be basically the same as without multithreading. Every call to the "move up" operation moves the paddle up. Calling that operation twice on one thread or once each on two different threads won't change that.

  • @sawilliams
    @sawilliams 5 ปีที่แล้ว

    Don’t forget the “stage “ object, that manages all the objects on the screen aka stage.

  • @zebroidalWorld
    @zebroidalWorld 8 ปีที่แล้ว

    Could the volume of these videos be ANY lower?

  • @srinagrao1
    @srinagrao1 8 ปีที่แล้ว

    why does the paddle go up at 2:47 ?

  • @reallyWyrd
    @reallyWyrd 8 ปีที่แล้ว

    Greater abstraction leads to greater complexity -- more memory consumption and / or more processor time spent running through all the layers of abstraction.

    • @raykent3211
      @raykent3211 8 ปีที่แล้ว +3

      which is exactly why we should write in binary machine code. Pardon the sarcasm, I'm not wanting to be really nasty.

    • @DFX2KX
      @DFX2KX 8 ปีที่แล้ว +1

      +I. Wyrd the trick is using the least amount of abstraction that you can while still having a modular project. done correctly, it's practically unnoticeable on anything made after the 90's.
      Taken to extremes, however, and we get Unity.....

  • @glitchsmasher
    @glitchsmasher 8 ปีที่แล้ว

    Wouldn't the ball have either a Velocity variable that also stores the balls direction? Or even a separate direction variable alongside speed?

    • @wesofx8148
      @wesofx8148 8 ปีที่แล้ว

      It would probably have a velocity vector. A speed variable could be used as a factor for the velocity, or you'd simply just increase the size of the time-steps to make the ball and paddles move faster

    • @glitchsmasher
      @glitchsmasher 8 ปีที่แล้ว

      +Willy Goat Speed with direction? That's velocity. You just said my point.

    • @wesofx8148
      @wesofx8148 8 ปีที่แล้ว

      glitchsmasher By speed I mean a speed factor. If you multiply the velocity vector by the speed factor, you can increasing the speed of the ball over time by increasing the speed factor over time. In pong, it's common for the game to get faster and faster.

    • @wesofx8148
      @wesofx8148 8 ปีที่แล้ว

      glitchsmasher
      Speed * Direction = Velocity
      So maybe we mean the same thing

  • @david2sdad
    @david2sdad 6 ปีที่แล้ว

    What is your get opinion of putting get in front of all accessors. This practice comes from Java Beans, but makes the grammar very strange. All of your nouns (and adjectives) turn into verbs: “Get would you like fries with that?“, “What is your get height?”, “if get name equals "root" then …”

  • @VinceOfAllTrades
    @VinceOfAllTrades 8 ปีที่แล้ว +1

    I know this wasn't the point of the video, but since both paddles are instances of a single object, how are the controls uniquely defined?
    Off the top of my head, the most reasonable solution is to create an operation which prompts for contols (which would probably be passed when the object is created).
    And a supplementary question: It seems like letting "draw" be an operation of the individual object would lead to a lot of visual desync and clutter. Wouldn't it be better to let "draw" be a property of the board so that all objects are updated and drawn simultaneously each frame? In essence, the "draw" operation has to erase the old instance and create the new instance, which usually means the background needs to be re-drawn anyways. I get that you don't always want /all/ of your objects drawn all the time for efficiency, but it would be pretty easy to exclude things based on distance (or any number of other factors).

    • @DFX2KX
      @DFX2KX 8 ปีที่แล้ว

      +VinceOfAllTrades in OOP, when you create an object, you get an instance ID. That instance ID essentially contains the pointers to the individual chunks of RAM it's unique variables are stored in. To give each it's own uniqe controls, you'd just load one 'Paddle' id into a 'var_Left' and the other into a 'Var right' and then have Q and Z do the 'Var Left.moveUp()" and 'var_right.movedown()' respectively. ditto for the other paddle.

  • @Flankymanga
    @Flankymanga 7 ปีที่แล้ว

    I think its not a bad idea to make a video about aspect oriented programming.

  • @TheMrTape
    @TheMrTape 8 ปีที่แล้ว +17

    If you don't have a proper overview and handle of your program, that's the problem, so don't solve it by using OOP; that will obfuscate the overview further and thereby lessen the ease of modifications and complex code writing. OOP breeds carelessness, half-assed code, and worse comprehension of the underlying logic (making assuming facts and solving problems according to that understanding much more difficult/impossible). If you use the same constant several times, define the constant and share it; not doing so is amateurish and counterproductive to begin with. If you have too many variables to keep track of all the names, give the names a prefix fitting their purpose, eg. DB_EntriesNum or GFX_DisplayWidth (notice usage of capitals for easier readability, might tickle your lowercase variables OCD a little; also notice the very specific and non-cryptic naming so you don't have to go bonkers with comments). Finally, always/rigorously use functions instead of repeating the same code over and over within separate code segments. Simply make sure that you only have to change/modify specific constants/functionality in one place (unless it becomes counter productive, like defining a constant for two adjacent obvious usages of the same number), then you remove the problem that otherwise forces the burden of OOP onto you (less control, less overview, less potential, less production efficiency, less comprehension, less skill development).

    • @Eeroke
      @Eeroke 8 ปีที่แล้ว

      +TheMrTape
      Hear, hear. OOP is a burden unless it's something truly big and complex like an operating system kernel, a game enfine or a desktop environment.
      In other words, if there's black box, with a lot of internal state with various relations, then it's worth it, not in an application with internal state equivalent to an elevator controller.

    • @normannormiemates4844
      @normannormiemates4844 8 ปีที่แล้ว

      +Tanooki100 so what languages are there for these simpler apps? They all seem to be object orientated

    • @Muzer0
      @Muzer0 8 ปีที่แล้ว +2

      +TheMrTape Completely disagree. OOP massively improves type safety, and in fact I find makes it significantly easier to comprehend programs.
      You provide some vague statements at the beginning and end of your post without explaining any of them. How about actually giving an example of how OOP would breed carelessness, or forces you to have less control or less overview. OOP gives you MORE overview, as it's much easier to see how the basic elements of the program interact with each other.
      And yes, I do have plenty of experience in both OOP and non-OOP languages. I enjoy programming in C, but I would never make a big end-user desktop application in it. I would in C++, if the low-level access and performance of C++ were desirable.

    • @SephirothITM
      @SephirothITM 8 ปีที่แล้ว +5

      +TheMrTape In my experience, Object Orientation pays for itself in terms of ease of maintenance. As a program grows, the time wasted by interference between pieces of code that are conceptually unrelated increases and OOP is the best tool to prevent this from being a problem. In fact, I can go a step further and state that object orientation becomes worthwhile for any project that is being developed my multiple people; as simple, well defined interfaces between objects allows two programmers to work completely independently and still create a working product. So, essentially all commercial/academic applications should be written using OOP. The ability to write a program in modules that can be exchanged with one another seamlessly through abstraction is one of the most appealing aspects of object orientation in my opinion; Getting away from having to learn a program before you can improve it is another.

    • @Eeroke
      @Eeroke 8 ปีที่แล้ว

      +T Riddle
      All the languages. You just try to refrain defining a horde of your own objects and their hierarchy "just in case", unless a truly object like subset starts to emerge in your variables and code. Following YAGNI -principle.
      I generally follow principle that small rewrite once a paradigm is emerging is a lesser evil than adhering to a paradigm that's ill-suited or unnecessary.
      There's nothing bad in using objects written by others. Done right, they are a fine abstraction for libraries. Even old school languages such as C do OOP on this level all the time.
      The difference is that in old school languages one generally doesn't think of inheritance before it truly becomes necessary to.

  • @bjzaba
    @bjzaba 8 ปีที่แล้ว

    I'm pretty glad that web front-end development is moving away from OOP to stuff like React and Elm... encapsulated state is pretty nasty to reason about in large scale codebases.

  • @isaacc7
    @isaacc7 8 ปีที่แล้ว

    It sounds like OOP has advantages because it allows a kind of modularity in the program itself. On the other hand, it seems like it could be more verbose and maybe not the most efficient way of running a program. I'd think that OOP on really limited hardware might be too slow. Do you think they used OOP on that original pong console?

    • @stensoft
      @stensoft 8 ปีที่แล้ว

      +isaacc7 Well, it all depends on how strongly the programming language enforces the rules (or in other words: how easily you can break them). E.g. C++ does not check the rules when the programme is running which allows it to have almost no overhead so if you programmed the game in C++, it can run on the original console. By contrast, Java checks the rules all the time which has quite a lot of overhead so it won't be possible to run it on such limited hardware. On the other hand, if you make an error in C++, because the rules are not enforced, it may do very weird things which makes it quite hard to figure out what happened. In Java, the programme will crash just as your code tried to break the rules so it's much easier to debug.

    • @raykent3211
      @raykent3211 8 ปีที่แล้ว

      +Mike Meyer ooh, someone mentioned arduino! I love it. in context, you understand, cos I can program the chip (uno) at assembler level, but it's a really pragmatic combination, and, as you say, a bit classic C and a bit OO. Avoiding the megabrain scariness of c++.

    • @raykent3211
      @raykent3211 8 ปีที่แล้ว

      ***** I forgot to ask... what kind of project?

    • @raykent3211
      @raykent3211 8 ปีที่แล้ว

      ***** I really don't want to pester you, I assume that if it's an electric motor drone then the energy requirement of the processor is negligeable. I'd be fascinated to hear more, if you have got the time.

    • @DFX2KX
      @DFX2KX 8 ปีที่แล้ว

      +Mike Meyer There's not that much C++ in the Aurdino libs, and plenty of sketch writers avoid classes entirely just to squeeze a tiny bit more out of the abysmally small RAMspace.

  • @grahammurray8707
    @grahammurray8707 6 ปีที่แล้ว

    BTW pong was an arcade game and we encountered it in the UK first as ping for obvious reasons.

  • @SB-hs4yn
    @SB-hs4yn 8 ปีที่แล้ว

    If you want to learn more about OOP, i'd suggest going with a language such as Java, or C#. C++ is fine, but it's not exactly beginner friendly (Considering you are a beginner).

    • @astronot1997
      @astronot1997 8 ปีที่แล้ว

      Scratch is the best choice for beginners

    • @astronot1997
      @astronot1997 8 ปีที่แล้ว

      sloan boyce Yeap

    • @raykent3211
      @raykent3211 8 ปีที่แล้ว

      +Bahadır Onur Güdürü I've only seen one example of scratch, involving a cartoon cat, so I don't know how flexible it is. Would you recommend it for a beginner who wants to make a robot respond to a whistle, for example?

    • @astronot1997
      @astronot1997 8 ปีที่แล้ว

      Ray Kent I have made a two-player 2D soyuz docking simulator and a basketball game which uses a physics algoritm also made by me. Without any programming experience I made those in 3-4 hours. I am not sure about what it can do, I am not that experienced but I am sure that no-other program can provide you that easyness. I have read somewhere that an arduino can be programmed by Scratch but again I am not sure. So if you want to make games, yes it's useful but if you want to do other programming things it is not apropriate.

    • @raykent3211
      @raykent3211 8 ปีที่แล้ว

      Bahadır Onur Güdürü fantastic! Well done, I'll look into it.

  • @slap_my_hand
    @slap_my_hand 8 ปีที่แล้ว

    You also need an angle variable for the ball.

    • @il2xbox
      @il2xbox 8 ปีที่แล้ว

      +StarTrek123456 Not necessarily, all you need is integer values for x and y positions, and the x and y components of velocity. Then moving the object around the screen or finding out where an object is is very easy, you don't need an angle.

    • @slap_my_hand
      @slap_my_hand 8 ปีที่แล้ว

      il2xbox If you don't have an angle variable, the ball could only move at 45 drgrees or some other specific angle.

    • @il2xbox
      @il2xbox 8 ปีที่แล้ว

      StarTrek123456
      No, you can change the x and y components of the velocity to change the angle

    • @il2xbox
      @il2xbox 8 ปีที่แล้ว

      StarTrek123456
      That works, but in my opinion it's easier to just use the x and y components of the velocity rather than storing the angle because then you have to use Math.sin() and Math.cos() to convert it to x and y anyway, which probably slows down the program. But with any programming problem there are always different ways to do the same thing, usually they're all perfectly valid. For a simple game like Pong it doesn't really matter anyway.

  • @Terrendum
    @Terrendum 8 ปีที่แล้ว

    Is there any advantage of classes over C's object files?

    • @Terrendum
      @Terrendum 8 ปีที่แล้ว

      +Vector Hacker I'm aware of the fact that they are not the same, if they were I wouldn't have asked the question. It's just that I've yet to come across an example of something in object oriented code I can't do as easily with what C provides. I presume that these examples are just to simlified for a fair comparison, so I was hoping someone could give me a better example of a situation were object oriented programming has a clear advantage.

    • @DFX2KX
      @DFX2KX 8 ปีที่แล้ว +1

      +Terrendum here's an example of where it's handy. Doable in C, but a bit handier:
      have a class called Quarternion. Has a struct of x,y,z,w. you can also pack in some of the more common math functions into the class so you don't have to search too much
      Quarternion QuartA = Vec4(0,0,1,90);
      Quarternion QuartB = Vec4(0,1,0,60);
      QuartA.MultiplyWith(quartB);
      QuartA.normalize();
      stuff like that. or being able to pack all of your graphics routines into a Display object, so that if you ever add OpenGL or DirectX to a project built on the other, it'd be possible to just add a single function to change modes, abstract the change inside the class, and leave the rest of your project untouched.
      You do pay some for that convenience, however, so it's best to wield it like a scalpel and not a jackhammer.

    • @Terrendum
      @Terrendum 8 ปีที่แล้ว

      +DFX2KX Thank you for the example.
      In C I would define a Quarternion type as a struct of x,y,z,w. Your code example would be:
      Quarternion* QuartA = Vec4(0,0,1,90);
      Quarternion* QuartB = Vec4(0,1,0,60);
      QuartMultiply(QuartA,QuartB);
      QuartNormalize(QuartA);
      To keep it all organised I'd put all the Quart functions in a file together.
      The Display object becomes a file with a couple of includes and maybe some global variables for things like settings/modes.
      Compile it all to an object file and link it to the main project.
      Correct me if I'm wrong but other than maybe a pinch of syntactic sugar I don't see the advantage.

  • @CatnamedMittens
    @CatnamedMittens 8 ปีที่แล้ว +1

    I missed Steve Bagley.

  • @jadduajones
    @jadduajones 8 ปีที่แล้ว

    I don't know much about programming; I just kind of do it. So I'm curious, is this like a class or an object in something like Java?

    • @RhapsodyAfternoon
      @RhapsodyAfternoon 8 ปีที่แล้ว

      +Jaddua Jones Java is probably the canonical example of an object-oriented language.

    • @jadduajones
      @jadduajones 8 ปีที่แล้ว

      I see! Thank you all for clearing that up!

    • @DFX2KX
      @DFX2KX 8 ปีที่แล้ว

      +Jaddua Jones the difference between Java, and say, C and C++, is that Java more or less enforces you to do things via Classes and methods in said classes, whereas you can program an entire C application and only use structs and methods (functions in C). There's some debate as to which approach is better.

    • @jadduajones
      @jadduajones 8 ปีที่แล้ว

      DFX2KX Thanks for clearing that up!

  • @rob45311
    @rob45311 8 ปีที่แล้ว

    I

  • @minxythemerciless
    @minxythemerciless 8 ปีที่แล้ว

    Bad example to choose.
    Pong - or at least pong clones - were done with hard-wired TTL logic with a few up-down counters and a clock. It was so simple a copy could be made in a shortish evening on the kitchen table. Nary a computer in sight.

  • @noctavel
    @noctavel 6 ปีที่แล้ว

    what about inheritance?

  • @hanniffydinn6019
    @hanniffydinn6019 8 ปีที่แล้ว

    It's get interesting when you are compiling OOP into assembly language. It all needs to work like that in the end....

    • @raykent3211
      @raykent3211 8 ปีที่แล้ว +2

      Yes! OOP is about how the human mind works. With optimising compilers it ends up looking, to the machine, not much different to hand written assembler code. Maybe 20% bigger, maybe 20% slower than the very best achievable by a skilled artisan programmer, but for many applications who cares? There are far more important considerations, in many cases.

    • @raykent3211
      @raykent3211 8 ปีที่แล้ว

      Hanniffy Dinn yeah, I think I agree with all the points you made. But, forgive me if you think this is irrelevant, but where are the job opportunities? Most of software development is now human to human skills. Arithmetical calculating got mechanised years ago. Next up? Programming. It's just translation from one language to another, and the target language has no ambiguity. Easy. All of this argument for and against oop will vaporise, just like the manual skills of spinning. OOD (design) will last longer because it pays more attention to humans than to their arbitrary inventions.

    • @raykent3211
      @raykent3211 8 ปีที่แล้ว

      Hanniffy Dinn Fascinating! Thanks for that. I'm retired, not "in the market" anymore, but when I was I saw a gradual downgrading of programmers, except for very specialist areas, such as cryptography/security, which scared the management so much that they'd pay a fortune for a proven specialist! Personally, I think that the trend away from making humans talk binary towards allowing them to describe their requirements in other ways will continue, but it's not a simple path. Interesting to hear that there's a huge demand for c++ programmers today, and I'd be interested in hearing your guess about 5 years in the future...

    • @raykent3211
      @raykent3211 8 ปีที่แล้ว

      Hanniffy Dinn Thanks for all the info. I'll look into swift and nim out of interest, hope they're both open-source, or whatever. In recent years I've only done a bit of hobby arduino stuff (C-like) on microcontrollers. No more big scale dev for me!

    • @hanniffydinn6019
      @hanniffydinn6019 8 ปีที่แล้ว

      Ray Kent NIM is really interesting and cool, as you can have all the modern features and it compiles into C. So it means you can even program micro controllers if you wanted !
      ;-)

  • @gogopie64
    @gogopie64 8 ปีที่แล้ว +27

    I feel like this channel needs to have more advanced material. Everything is either a superficial look at stuff being done in the realm of computer science or explanations of super basic concepts. Why can't this channel be more like numberphile where it actually gets into the nitty gritties of things?

    • @pumpkinot9900
      @pumpkinot9900 3 ปีที่แล้ว

      nou

    • @abstractapproach634
      @abstractapproach634 3 ปีที่แล้ว +4

      Numberphile most cirtianly does not get rigourous with mathematics; maybe it just feels that way because of your skill set? I do agree that computuerphile is shallow as well though. With my ameture understanding of computer science that may show they simplify tghings a little worse here.

  • @runecreed2265
    @runecreed2265 8 ปีที่แล้ว

    Something that puzzles me with this is that for the game of Pong for example - the draw methods associated with Objects specify 'how' this object is supposed to be drawn, since the actual drawing happens outside of the object, by means of the encapsulating program (in this game, the screen/main class); Am I right in assuming that there should be a draw() method in the encapsulating environment that invokes each individual's object's draw method?
    Public void Screen() {
    public static void main() {
    Ball theball = new Ball(x,y,size,...)
    Paddle paddle1 = new Paddle(x,y,....)
    Paddle paddle2 = new Paddle(x,y,...)
    draw();
    }
    draw(){
    theball.draw();
    Paddle1.draw();
    paddle2.draw();
    }
    }
    Does this make sense? [yeah the draw should be in an updating method that constantly runs, of course]

    • @JB940
      @JB940 8 ปีที่แล้ว +1

      Yes and no. You could have a board have an array of objects, with a function that draws them all ( like you described but more expandable), but there could also be another class that keeps a board, and an array of objects, and does object.draw(board), then the board does not need to know of the objects

    • @runecreed2265
      @runecreed2265 8 ปีที่แล้ว

      +Jordy Brinks But don't you want the board to be responsible for drawing the pieces onto it? Take for example a chessboard with cell objects that form the grid - the cells themselves are valid X/Y locations that may be occupied by pieces (also objects). How would you organize the drawing of these elements?
      How I'd do it is have a main Board Object with a draw method that draws all cells - and each individual cell has a draw that may (if need be) call the draw method of a piece that occupies it (boolean probably), which then drops the X/Y position from that cell into the draw method of the piece.
      In essence what I'm struggling with is the drawing itself - should you encapsulate only the 'way of drawing it' rather than 'where to draw it' for each object's draw method; and have the 'where' be specified by some mainframe that assigns locations - possibly via a constructor?

    • @JB940
      @JB940 8 ปีที่แล้ว +1

      Kevin Cleijne​ they're both valid, and both have merits. It makes sense to have a piece know if it's location. It makes sense to have a piece know it's "pixels". It makes sense the board instead keeps track of positions, and draws the shapes.
      It all boils down to the same actually. You could say a chessboard cell is an object, and the way you describe the board would be the encompassing class making the piece draw on the cell -> IE the piece gets a cell object and draws itself on it. Or you could say the board draws the object instead. It depends on the perspective.
      In this video you could say the objects draw themselves onto the board, or you could look at it from the "class that makes this happen" as the main perspective and say it is drawing the objects. 

    • @runecreed2265
      @runecreed2265 8 ปีที่แล้ว

      +Jordy Brinks Yeah, in essence it's the same. I just wonder if it wouldn't be best to have an overseer class taking care of some behavior. Should the Ball be aware of it's collisions, or should the overseeing class handle those events instead? The ball shouldn't really know what it collided with since that breaks encapsulation right? Instead I'd want an overseeing class that takes care of collisions, some entity that knows all positions of all elements that are being drawn. It only makes sense then to have that entity take care of the places where objects are drawn.

  • @gownerjones2
    @gownerjones2 8 ปีที่แล้ว +22

    My teachers and peers always praise OOP and hail it as the "only right way" to code, the moment you take off your training wheels, you'll be doing OOP.
    But I can't be the only one who doesn't like this, right? It seems like it limits one's abilities more than it aids them.

    • @yyny0
      @yyny0 8 ปีที่แล้ว +4

      I agree. Most of these people don't even know what Functional programming is...

    • @localatticus4483
      @localatticus4483 8 ปีที่แล้ว

      +HOLyPumpgun | Gaming | I don't quite like it, no. I use "OO" languages (I have yet to find a pure OO language, if that says anything about OO) but that's only because I'm extremely used to them. I'm actually designing/writing my own programming language that's procedural, though it MIGHT contain some less OO class kinda things.

    • @gownerjones2
      @gownerjones2 8 ปีที่แล้ว

      Kai Kyouretsu Well hat sure sounds interesting. You have a name for it yet?

    • @jakejakeboom
      @jakejakeboom 8 ปีที่แล้ว +3

      take a look at a functional language like clojure, f#, or Scala. there's definitely a steep learning curve to functional languages coming from an OOP background but I promise it's worth learning FP.

    • @localatticus4483
      @localatticus4483 8 ปีที่แล้ว

      HOLyPumpgun | Gaming | calling it Score

  • @Eeroke
    @Eeroke 8 ปีที่แล้ว

    Request: same pong exaple, but in purely functional take on it!

    • @Eeroke
      @Eeroke 8 ปีที่แล้ว

      +Mike Meyer
      As in "functional programming", I mean. Scheme or Haskell or what ever more newfangled languages have you. Pure functional means immutable variables, amongst other things.

    • @Eeroke
      @Eeroke 8 ปีที่แล้ว

      +Mike Meyer
      I have to guess "one set of parentheses" and you are going to reply "not even close"?
      They did make the paradigms video all the way in 2013 though.