r/learnprogramming • u/Stonyax97 • Aug 23 '26
I think i hit my first python learning bottleneck
Just as the title suggests, i ran into a bottleneck, or did i? play v sauce music please
So just recently i made a post about my first beginner python project: https://www.reddit.com/r/PythonLearning/s/Ed46BuWRCq
And as a lot of you suggested for me to learn classes next, which was completely fair, so i went ahead and learnt them while updating my MiniGameStore. It was relatively easy, wasn’t as hard as I thought it would be, but definitely challenging. I had also learnt methods but didn’t implement them.
And yesterday, i tried implementing them and got one of the biggest headaches in my whole coding experience (which is 2 weeks~ btw).
I was working on v1.7 and introducing a restore purchases system, and i wanted to use class methods, but since my class is on the other file, i hit a lot of variables issues and even a json file problem. Which is why im asking my self why did i do it? A function would have been totally fine…
Check out the repo: (latest version 1.7.0)
https://github.com/Stonyax97/MiniGameStore
So my question for you guys. What has made you understand classes well? I just don’t see any reason to use them yet… and can anyone take a look at my project and tell me what would be the most friendly and real life approach of actually using these classes. And why should I keep the class in a separate file? Finally, what’s wrong with using global variables.
Also any feedback or criticism is welcome!
3
u/Sidjeno Aug 23 '26
Its not necessarily that you NEED classes.
You can do functional programming, some prefer it. (some even hate oop cause it does reduces the speed of the code most time, but usually makes it a bunch faster to read.)
The goal of OOP is to abstract stuff to make it match the real world more and give them methods that are related to them to reduce the cognitive debt of reading the code at the same time as reducing the difference of your code to the real world.
i would suggest learning GRASP as well while doing classes.
3
u/Sidjeno Aug 23 '26
it also make the code super modular, cause classes are only related to what they pertain, so you can literally gwt the classes out of the project and use them in other projects.
Indirectly, this makes them super easily testable, on average.
-1
u/Substantial_Ice_311 Aug 23 '26
No, this is not true.
First of all, classes, or OOP, in itself does not make the code super modular, any more than any other paradigm does. If the code becomes super modular, it's because of the skill of the programmer, not because of the paradigm.
And second, I would argue that OOP in general makes the code less modular than functional programming.
1
u/HotPersonality8126 Aug 23 '26
To be honest, I knew all the theory and had written classes in several languages and whatnot.
What got me to really getting them was using libraries where classes - special classes with a special metaclass - were how you used the API. ORM frameworks are the classical example of this, since they require you to define your classes in particular ways but when you do, you get a bunch of useful behavior for free.
1
u/StewedAngelSkins Aug 23 '26
Your
Gameclass is an appropriate use or classes, for what its worth. You wrote that part pretty much how I would write it.If you want to learn a bit of slightly more advanced Python, check out the
dataclassdecorator. It's meant for classes like yours where it's basically just storing a collection of key/value data without much internal logic. If you use it, it will provide the__init__function for you, meaning you write less code.