Is a class necessary?

Good day, my name is Paul (under protest), I am a self taught video game programmer, you can check out my latest project at store7697404[DOT]ecwid[DOT]com. This project recently grew to over 50,000 lines of code, however, it does not use a single class that I have written. As a matter of fact, I have not ever written a single class in my entire life, nor do I plan on ever writing one.

Although my project is 50,000+ lines of code, it has a startup time of about one to two seconds on my low-end laptop. All the functions are written in a single .cpp file. This very large and complex code structure is very easy to manage and maintain, because I am able to collapse the functions to their definitions. It does not seem necessary to add any classes, and I think the functions and data structures for custom data types is really an object oriented approach to programming. It seems to me that it is silly to use classes, as well as causing more pain than gain. I am not sure if anyone will agree with me. I have come to these conclusions through trial and error, and by trying to use a class someone else had written with terrible results.

The main problems I had with using a class was trying to follow the flow of the program's logic through multiple files. This was hard to do. Another problem was dealing with variable scope, but that is another discussion.

(You may also check out my game by searching "simcube game" on google.)
IDK why this was reported, but it would probably have been better posted in the Lounge.

That said, the answer to your question is... no.

OOP is useful in a few circumstances, but at the end of the day, it is not necessary.
There is a lively debate about it ongoing.
https://www.google.com/search?site=&q=oop+overrated

That said, I don't agree with your design strategy. You need better tools. And a better design if you cannot separate your code into logical components.
Although my project is 50,000+ lines of code,

First point, the more experience you get, the more you will feel embarrassed about your programs consisting of many lines of code. I remember when I first started, feeling very proud I had written about 20k lines of code in one program, then when I started a long painful process re-factoring it to be more organized, and modular, I ended up reducing it to less than 10,000 lines. The first and possibly most important advice I would give is to try and follow the DRY principle (don't repeat yourself).

The main problems I had with using a class was trying to follow the flow of the program's logic through multiple files. This was hard to do. Another problem was dealing with variable scope, but that is another discussion.


A nice thing about an object oriented approach, or at least a modular approach, is that you shouldn't have to follow the logic of a large complicated program. You should ideally only have to follow logic in one small uncomplicated thing at a time. The large complicated program then is much simpler, because most of the complicated internal implementation details are abstracted from you, and you can manage the larger program easier from a higher level (just like programming in C++ is easier to manage than machine code).

That said, you don't need classes for this, but IMO they are very useful for supporting this. Certainly, you should at least be able to move some of your functions into separate files, without the need to mess with them as you work on your main program.

Another problem was dealing with variable scope, but that is another discussion.

It think it's not good to be messing with one variable in many different places. This can vastly complicate things, lead to bugs, and make it very difficult maintain the code. This is another issue classes are intended to help with.

It may be that you started doing a lot of programming before learning very much, and developed your own way to be relatively effective in spite of your lack of programming knowledge, and as is usually the case in everything, it is difficult to break your habits or change your style of thinking. The same thing happened to me. My first program was about 10,000 lines of code all inside the main function using goto's, and at that point, I felt the same way you seam to now (that I didn't need anything else). But I'm glad I changed my mind as I got more experienced. You will probably start feeling the same as you begin to run into various issues and you try to resolve them, such as when you want to reuse some of your old code in a new project, or you want to significantly change some things and it becomes very difficult due to the complexity and chain reactions that a single change can cause.
Last edited on
Managing and maintaining code far exceeds the bounds of collapsing functions.
I'm not sure why you bothered to ask the question since you have already made your mind up that classes are not necessary.

When you understand data encapsulation and OOP, then you may feel differently about classes.
Try to imagine you are the OP and what reasons he may ask this question.
Is he...
-- trying to prove something to us heathens?
-- trying to understand why everyone is so keen on OOP when it appears totally unnecessary to him?


To improve on my answer, OOP is never necessary, but it is exceedingly useful.
It provides several important characteristics; a quick overview can be found here:
http://www.cplusplus.com/faq/intro/#oop

Hope this helps.
closed account (48T7M4Gy)
@Paul
Perhaps you could post a 50 to 100 lines sample. Of course make sure the sample doesn't compromise your IP rights.
Topic archived. No new replies allowed.