5 ms·
Speaking of Python, as a beginner I have tried to grasp Classes and Objects and watched countless YouTube videos and Reddit/StackOverflow comments to understand
by retskrad 3y ago
Speaking of Python, as a beginner I have tried to grasp Classes and Objects and watched countless YouTube videos and Reddit/StackOverflow comments to understand them better but I'm just banging my head against the wall and it's not sticking. The whole __init__ method, the concept of self and why it's used, instance and class variables, arguments, all of it. When learning something, when you simply cannot grasp a concept however hard you try, what's the course of action? I have tried taking breaks but that's not helping.
- switch007 3y agoClasses and objects exist in all object oriented program languages. Perhaps stepping back from Python and trying some more generic material might help?
- retskrad 3y agoThat's a good idea, I'll try that
- harrelchris 3y agoEither keep looking for explanations until it clicks, or try to break it down into more fundamental elements. Classes and blueprints have a simple analogy that I'm sure you are familiar with. Blueprints are instructions for how to build something, like a house. Once built, the house is a physical thing you can interact with. It has attributes, such as a height or color. It has things it can do or that can be done to it, like open a door or turn on some lights. Classes are blueprints - they tell a computer how to build something. An object is what is built by the class - it has attributes and methods.
- retskrad 3y agoThanks, I appreciate it
- ozzy6009 3y agoI was the same way when I was a beginner, I didn't really "get" python classes until years later and using other programming languages. I recommend SICP if you want a more first principles understanding: https://web.mit.edu/6.001/6.037/sicp.pdf https://web.mit.edu/6.001/6.037/sicp.pdf
- retskrad 3y agoThanks
- Zizizizz 3y agoTry out these Cory Schafer videos, I remember watching them 6 years ago and them being quite helpful. https://youtu.be/ZDa-Z5JzLYM https://youtu.be/ZDa-Z5JzLYM
- retskrad 3y agoThanks
- abecedarius 3y agoFirst, do you feel you understand OO in another language? So this is about how Python does it?
- retskrad 3y agoI'm a beginner and Python is the only language I'm familiar with
- abecedarius 3y agoOK. It might help to keep in mind a couple things: - Python started as a simple language, but it's grown over the decades, and professional programmers learned the new complications along the way. They don't naturally appreciate what it's like if you get hit with them all together, as sometimes happens -- it all seems simple to them. So to understand OO I would try to screen out the fancier bits like the class variables you mentioned -- you can come back to them later. - The original central idea of objects (from Smalltalk) is, an object is a thing that can receive different commands ('methods' in Python), and update its own variables and call on other objects. The way Python gives you to define objects (by defining a class and then creating an instance of the class) is not the most direct possible way it could've been designed to do this -- if it feels more complicated than necessary, it kind of is. But it's not too bad, you can get used to how it works for the most central stuff as I mentioned, and learn more from there.
- kzrdude 3y agoI think working with it in practice is the only way forward. Looking up info, build something, work more, and let it become a feedback loop. People work long with systems before they "get" them. Programming is not a "school" activity for me. It's a craft, you do stuff. That has eventually led to a depth of knowledge in various topics inside programming. (Digression: With that said - we should think of a lot more "school" stuff as skills and crafts - stuff that you don't read to understand but you get better at with practice. A lot of maths class is skills, not knowledge.)
- retskrad 3y agoGood advice, thanks
- WoodenChair 3y agoBuild a project where you purposely use a bunch of your own custom classes. Learning by doing is best if the reading materials are not clicking.
- montecarl 3y agoOthers have said something similar, but I will still chime in. It sounds like you may want to feel like you have a complete understanding of classes, objects, and the way the work before you can begin working with them. This can almost never work. I haven't come across a topic where just reading about the topic is sufficient to fully understand it or even become proficient in it. In my experience this is true for cooking, lab techniques in chemistry, electronics, and programming. Even when I have read something and felt that I understood it completely, as soon as I begin the activity I immediately realize that I had a fundamental misunderstanding of what I had read. That my brain had made some oversimplification or skipped passed some details so that I felt like I grasped the concept. So if I had to describe the way I learn a new concept it would look like this: 1. Read many different descriptions/watch many different videos of the topic to get used to the terms and concepts 2. Try to apply those concepts in real life (write software, build a circuit, cook a meal) 3. Figure out where my understanding fell short, and go back to step 1 You want to make this loop as tight as possible. When you become expert at something you can do this activity super fast. When you first start out you may have to do quite a bit of reading to even have the baseline needed to attempt a concrete task. However, it is important to get started towards a real goal as soon as possible or you will be wasting your time feeling like you are learning and moving towards you goal, but you are not.
- mixmastamyk 3y agoGo to school, with a good teacher. Yt videos are not a substitute for a proper course.
- IshKebab 3y agoI disagree on the school part. There are so many good resources available especially for Python programming. There's no way you need to pay for lessons. I don't think the kind of people you get teaching Python will be the most knowledgeable anyway. But I would maybe recommend a good book if you're struggling.
- mixmastamyk 3y agoCommunity college is still a thing, not expensive, and won’t make the mistake of teaching specifically Python. It also forces a schedule which is helpful in its own right. What you just proposed is exactly what isn’t working for this person.
- njharman 3y ago> When learning something, when you simply cannot grasp a concept however hard you try, what's the course of action? Learn by doing, don't learn by studying. Pick a (hopefully real) problem, solve it using classes. Repeat. Continue repeating. You will either learn what OO is good for, what it is not good for and how you can use it to write better code. Or, learn that programming is not something you can grok. If you don't have a "real" problem; Then write program to play tic-tac-toe; manage the and display board, take player inputs, detect when game is done (winner or draw). Then expand it to 8x8 board, then to 3 players. Those changes should be easy with good OO design (lots rewrites, code changes). And probably "harder" with bad OO or no OO design. btw this is 2nd interview question I and my team used for years.
- IAmGraydon 3y agoAs everyone else said, use it. Don't try to understand by reading. Understand by doing.
- _dain_ 3y agoHave you read this? It's one of the few I've come across that has the appropriate degree of empathy for the confused newcomer + actionable advice: https://death.andgravity.com/same-arguments https://death.andgravity.com/same-arguments And it doesn't fall into the "Dog inherits from Animal" taxonomic crap.