Thread: Do you use classes?

  1. #1
    Registered User DedicatedGamer's Avatar
    Join Date
    Mar 2016
    Posts
    21

    Do you use classes?

    Good day, today I want to bring up a topic that I think a lot about, and am very passionate about, and it is the use of classes.

    Are classes really necessary? Do you use classes? Do you think using classes makes a program faster or slower? Do you think using classes makes writing a complex application easier or more confusing and tedious?

    Thoughtful responses are welcome!

  2. #2
    Registered User DedicatedGamer's Avatar
    Join Date
    Mar 2016
    Posts
    21
    I do not use classes. I think they are slow and confusing. However, in order to contain a lot of code, I must use an advanced IDE environment like Microsoft's visual studio.

  3. #3
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Obviously you mean "make your own classes" since you presumably using string and vector, for example, which are classes.

    To use C++ libraries it is often necessary to create a class as a subclass of a given library class, or to pass an object as a parameter (functors, for example).

    You're just a beginner. If you continue with C++ programming you will create your own classes.

  4. #4
    Registered User DedicatedGamer's Avatar
    Join Date
    Mar 2016
    Posts
    21
    Yes, thank you for the clarification, however, I thought that was obvious. Although maybe not, since not everyone is required to tame the window class instance every windows application needs to run.

  5. #5
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    If you hate writing classes, perhaps you'd be better off with C, instead of C++.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by DedicatedGamer View Post
    Are classes really necessary?
    Yes.

    Do you use classes?
    Yes.

    Do you think using classes makes a program faster or slower?
    Neither. Classes are tools. It all depends on how you write your code.

    Quote Originally Posted by DedicatedGamer View Post
    Do you think using classes makes writing a complex application easier or more confusing and tedious?
    Easier by a huge margin.

    Quote Originally Posted by DedicatedGamer View Post
    I do not use classes. I think they are slow and confusing.
    Classes are not slow. The code you write can be slow, but that isn't related to classes at all.
    If you find them confusing, then you had better start understanding them better. Classes are bread and butter in today's programming world because it's a value tool that makes code organization a lot easier.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User
    Join Date
    Dec 2010
    Location
    Trinidad, CO (log cabin in middle of nowhere)
    Posts
    148
    Might be interested in this link, as its from a game development forum...

    https://hero.handmadedev.org/forum/c...g?limitstart=0

    Another good link is this "OOP An Expensive Disaster Which Must End"

    Object Oriented Programming is an expensive disaster which must end | Smash Company

    From what I gather Linus Torvalds only allows C code in the Linux kernel specifically to keep C++ coders out. Ken Thompson tried C++ but doesn't care for it. Lot of other examples.

    OOP has been tremendously oversold. A whole generation of coders have been brainwashed into believing its the ultimate coding paradigm of all time. For myself I've found it to be a useful tool for organizing code in some if not many places. However, I have to say I've made a pretty good career out of taking failed OOP based enterprise solutions and rewriting them in tight procedural code which actually works.

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Note that Linus Torvalds is an anti-C++ guy. He just hates the language and is biased. I wouldn't take him seriously in this regard. Many of his anti-C++ arguments just shows that he clearly doesn't understand C++ as well as he thinks he does.

    As for classes... they're tools. OOP is one way of putting these tools to use. However, I don't think OOP is strictly defined such that you must design a system in a specific way. One can probably do it in many different ways, which just means that saying "OOP is bad" is ignorant. Some ways are bad, some ways are better. Like any tool.

    I think classes provide a natural way of providing access to tools such as data encapsulation and data abstraction, two very important techniques.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Quote Originally Posted by freddie View Post
    From what I gather Linus Torvalds only allows C code in the Linux kernel specifically to keep C++ coders out. Ken Thompson tried C++ but doesn't care for it. Lot of other examples.

    OOP has been tremendously oversold. A whole generation of coders have been brainwashed into believing its the ultimate coding paradigm of all time. For myself I've found it to be a useful tool for organizing code in some if not many places. However, I have to say I've made a pretty good career out of taking failed OOP based enterprise solutions and rewriting them in tight procedural code which actually works.
    Watch out, we have a badass over here.

    Linus is entitled to run his projects the way that he wants, and it doesn't really mean anything how he does it. Though I agree - C++ people can be annoying, but I feel like C++ and its evangelists have calmed down over the years. Or maybe I care less.

    Are classes really necessary? Do you use classes?
    Yes, they are. To be fair, I think nearly all of the problems people have with OOP surrounds how difficult it is to write new classes. In C++, to write a good, new class you basically have to know everything about them. It doesn't help that there is a new standard so often, and you might be in a startup that wants to use the bleeding edge in standard C++ features - meaning you have to deal with a specific (probably Microsoft-centric) implementation. That implementation might be incomplete.

    So by no means are aspects of OOP development easy. But no one complains about using the std::string type, or std::vector to do things either. If you're constantly making new, complex classes instead of using older stuff, I think you are OOPing wrong.

    It's important to remember when you are new that you will probably write classes no one needs to use.

  10. #10
    Registered User
    Join Date
    Dec 2010
    Location
    Trinidad, CO (log cabin in middle of nowhere)
    Posts
    148
    I enjoy seeing threads like this simply because ten or fifteen years ago the question never would have been asked. Now I see it being asked a lot. That shows that intelligent newcomers to coding are questioning accepted ways of doing things.

    OOP in my opinion represents an excellent example of what I would call the 'Law Of Unintended Consequences'. When PCs first started gaining popularity back in the 1980s - way before computers went mainstream, a very large percentage of the folks who bought them learned programming with what would be considered primitive programming tools nowadays - such things as gwbasic - Bill Gates 1st BASIC interpreter. But programming was considered 'hard' nonetheless. OOP was to change that. With the new paradigm, new tools, and new ways of thinking about the programming endeavor, it would be easier to code solutions. But that isn't what happened at all. When OOP finally completely took over - casting about for some date - lets say 2000 or so, programming became such a complex endeavor that mostly only professionals did it - just read a bit of the Smash Company link above concerning the complexities. Very few new folks buying computers nowadays would even consider coding - they know its that complex. That's what I mean by the 'Law of Uintended Consequences'. And in my opinion its largely OOP that is responsible.

    And I can see where someone might want to counter my argument above by stating that computer systems are way more complex now than they were back in the 16 bit DOS era of the 1980s. That is certainly true, but the types of issues I see new C++ coders struggling with in this and other C++ forums are the same issues folks struggled with back in the 80s, that is, learning the basics of parsing strings, converting strings to numbers and vice versa, basic algorithms, etc., but now folks are bogged down to a greater extent than we ever were in the past due apparently to trying to integrate doing these things in an OOP fashion with classes. I'm just expressing an opinion here, because I've thought much of these things. Not wanting to offend anyone. Personally, I use classes a fair amount. Not as much as some perhaps, but a fair amount. I have my own String Class which I started working on 15 years ago, my own ODBC Database Class, a templated multi-dimensional array class I use in lieu of C++ Std. Lib. vectors, and some others. My code won’t compile in C. So I wouldn't view myself as an enemy of OOP.

  11. #11
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    the types of issues I see new C++ coders struggling with in this and other C++ forums are the same issues folks struggled with back in the 80s, that is, learning the basics of parsing strings, converting strings to numbers and vice versa, basic algorithms, etc., but now folks are bogged down to a greater extent than we ever were in the past due apparently to trying to integrate doing these things in an OOP fashion with classes.
    How much of that is really OOPs fault, and how much of that is just people learning how to program though? I find new people to be the worst example in talks like these. If it's hard to teach newbies how to X, it should be hard to teach it in language XYZ too.

    I would actually argue that people need to learn about sorting and searching in detail. Implementing a few algorithms yourself is good practice. True, if you want to make it easy you reach for a generic option (std::sort, std::stable_sort, std::partial_sort, std::binary_search). But people do encounter searching and sorting problems in the wild, and need some idea of what makes a good algorithm. The API does not always accommodate.

    I'll give you a great example. Recently I was involved in a thread on twitter. Another programmer had a question about Unity, asking why he couldn't specify a rectangle of pixels in a Texture2D with GetPixels32(miplevel). Because you can in SetPixels32(x,y,w,h). The answer was probably that it was easier for the original engineers to give you the whole mip. You would perform your custom search/edit, and then put the pixels back as a block. Your own search would be better or faster than something generic.

    Personally, I use classes a fair amount. Not as much as some perhaps, but a fair amount. I have my own String Class which I started working on 15 years ago, my own ODBC Database Class, a templated multi-dimensional array class I use in lieu of C++ Std. Lib. vectors, and some others. My code won’t compile in C. So I wouldn't view myself as an enemy of OOP.
    Here you are being an example of the point I made in my last post. People have classes as building blocks that they use in bigger and better things. This object-based programming is the every day experience with OOP. I just don't see how this translates into the beast of a problem OOP is claimed to be.
    Last edited by whiteflags; 03-31-2016 at 02:38 PM.

  12. #12
    The Negativity. LAURENT*'s Avatar
    Join Date
    May 2012
    Posts
    68
    Well personally the 2 main things I use are struts and classes. I know their pretty much the same but I like use them for conceptual naming convinces.
    UPDATE! As of 10/6/2014

    https://www.dropbox.com/s/2sj6qwpfbb...t%201.zip?dl=0
    Just find the application file and double click it. Controls are (Arrow keys) (Z) (Z + arrow key) (Spacebar)
    Don't play this crappy update. Wait for the newest one which is far more impressive.

    Official Sonic character poll hosted by some guy at Sega..... Sega of America. Vote for blaze because she OP.
    http://blogs.sega.com/2015/08/28/the...down-heats-up/

  13. #13
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    In C++ the struct keyword is just another way to declare a class. If you want, you can make all your classes just a collection of stuff (no methods), but then you'll end up writing things like this:

    Code:
    Person p = make_person("SomeFirst", "SomeSurname");
    cout << "Person 1: ";
    print(p);
    cout << "\n";
    Person q;
    copy_person(p, q); // Copy Person p to Person q.
    cout << "Person 2: ";
    print(q);
    cout << "\n";
    cleanup(p);
    cleanup(q);
    If you make Person a class with member functions, then its use becomes part of a common interface (i.e. you use it just like everything else):

    Code:
    Person p("SomeFirst", "SomeSurname"); // Use constructor.
    Person q = p; // Use copy constructor.
    cout << "Person 1: "<<p<<"\nPerson 2: "<<q<<"\n"; // Use operator<<.
    // Use destructor for automatic cleanup.
    Personally I think the second version is better than the first.
    Last edited by c99tutorial; 04-02-2016 at 09:03 AM.

  14. #14
    Guest
    Guest
    I tend to use struct / class to differentiate between "dumb" aggregates of data ("POD") and self-sufficient objects that encapsulate functionality.

  15. #15
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    I have decided that using Classes in C++ is the way I plan to write my code in the future attempts at learning C++.
    I figure once I get to writing large C++ programs the reason to write my own C++ classes will make itself clear to me.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array of classes with classes inside
    By questionmark in forum C++ Programming
    Replies: 3
    Last Post: 10-04-2013, 03:39 PM
  2. Conversions between base classes and derived classes
    By tharnier in forum C++ Programming
    Replies: 14
    Last Post: 03-18-2011, 10:50 AM
  3. Classes access other classes local variables
    By parad0x13 in forum C++ Programming
    Replies: 6
    Last Post: 01-14-2010, 04:36 AM
  4. Classes with Other Classes as Member Data
    By njd in forum C++ Programming
    Replies: 2
    Last Post: 09-27-2005, 09:30 AM
  5. Help accessing classes and derived classes
    By hobbes67 in forum C++ Programming
    Replies: 8
    Last Post: 07-14-2005, 02:46 PM