Congratulations! You rediscovered the well known fact that object orientation can be done without specific programming language support. It is basically the same way objects are introduced in Scheme in this classic text book. Note that Scheme does not have a class keyword or some kind of equivalent, and objects can be created without having even classes.
However, the object orientated paradigm was so successful that lots of languages - and Python is no exception - provide built-in support for it. This is simply to make it easier for developers to use the paradigm and to provide a standard form of object orientation for that language. It is essentially the same reason why lots of languages provide a for loop, though it could be emulated using a while loop with just one or two additional lines of code - simply ease of use.
In Python, we learn that in order to create a class you need to start off with the `class` keyword. But the reality is that we actually don't.
I've written an article on how this works. We take a deeper dive into data types in Python and explore how they work under the hood.
I explore how all data types are classes, and how they can all be derived from `type` which by the way can do more than tell you the type of an object! Check out the article below if this sounds intriguing.
https://medium.com/@Salaah01/creating-a-class-in-python-without-the-class-keyword-67ce84bae22
Edit: Oh, and don't worry. The point of the article isn't to say. "Hey guys, this is a new way to write classes, and this is what you should do from now on". In the article, I explicitly discourage that. Instead, it's to give an inside to how it works and why it works.
Congratulations! You rediscovered the well known fact that object orientation can be done without specific programming language support. It is basically the same way objects are introduced in Scheme in this classic text book. Note that Scheme does not have a class keyword or some kind of equivalent, and objects can be created without having even classes.
However, the object orientated paradigm was so successful that lots of languages - and Python is no exception - provide built-in support for it. This is simply to make it easier for developers to use the paradigm and to provide a standard form of object orientation for that language. It is essentially the same reason why lots of languages provide a for loop, though it could be emulated using a while loop with just one or two additional lines of code - simply ease of use.
I would agree that the first definition satisfies the three points your teacher made. I do not think we need the class keyword for anything. Under the covers, what else is an object but a data structure with with different types of data and functions to work with the data? Of course, the functions are data as well..
I would go even further and say that doing object oriented programming is not so much dependent on the keywords your language provides, you can do object oriented programming in C if you so wished! In fact, the linux kernel employs such techniques.
What you can infer from the class keyword here is, that the language provides support for this kind of construct out of the box, and you do not need to through all the hoops to re-implement the functionality yourself(which is pretty fun task in itself!). Not to mention all the syntactic sugar you might get as well.
I consider myself a nearly advanced-level Python programmer. From data processing and statistical analysis to web development and systems administration of large clusters, I do it all regularly.
I started using it in grad school for my research and now use it everyday in my job as a computational scientist. However, I simply do not use classes. I use functions for everything, often many small functions whose output I feed into another. For large highly parallel data processing tasks, I'll have one main worker function that does the heavy lifting on each item that I'll pass to a multiprocessing Pool.
So my question is: Given that I know how to get stuff done quickly, what am I really missing out on or shorting myself on by never using classes?
I like to read about cool python project blogs and articles. What I have noticed is that many python programmers uses classes even for small projects. Do we need to use classes for every python projects? Do python veterans recommend writing codes only with classes or we can avoid it?
This is not a brag, this is a call for help. I've never been able to get my head around what a Class is. People tell me it's a container for functions, then why can't you just use the functions without a class? I just don't understand the concept of a class and why I would use one. Could someone please help? I've watched numerous videos that just make Classes seem like glorified variables to me.
I'm a brand new python dev (actually a new dev altogether) and I'm trying to understand testing in python. My university testing was limited, only did a single unit on it in a single course and it was in a single language, so my understanding of testing in general is quite limited, especially in python which is a new language for me.
From what I understand, the way most testing works by default in python (with the built in unittest library) is using classes. I guess you run tests on methods that are part of classes (as opposed to classless functions).
The issue is, the project I'm working on at work isn't object oriented. We don't actually use classes. Which honestly is fine, object oriented has its benefits but sometimes its exhausting. So I wasn't complaining that we weren't taking an object oriented approach. but now i'm finding testing... challenging.
Is there a way to do testing without having things in a class? For now, all I can think to do is put everything inside a dummy class, wrap parts in static methods for testing, then comment out all the class specific codes after i'm done testing.
surely there's a way to do unit tests without classes?
Also, I'd rather keep to the default unittest library if possible. i understand there may exist other unit testing libraries/modules/packages inside python but my work generally wants me to avoid adding new dependencies.
Thanks for the help.