tags:

views:

448

answers:

8

My personal opinion is that any programmer should learn (procedural) C/C++. You can only benefit from learning it, even if you don’t use it regularly.

But is it worth programming with OOP in C++? Are there any advantages that you can gain from doing this?

What do you think?

+19  A: 

Question: Is it worth it to learn paradigm X?

Answer: Yes. Paradigm X will show you new ways to think about things far beyond the limits of paradigm X. It can help you write better code in paradigms Y an Z as well. Also, (I believe that) knowledge is inherently a good thing, and that having more of it is always something to strive for, and therefore learning paradigm X will make you a better person, however infinitesimally small the improvement may be.

Just change "paradigm X" to whatever paradigm you like (object-oriented, procedural, functional, logic) in the above, and it will still be true.

Chris Lutz
I think that the point was about doing OOP in C++, rather than in Java, C#, Python, name-your-language-of-choice-here...
Francesco
The same principle applies. It's worth learning C++, Java, Ruby, Python, C#, Smalltalk, and Objective-C because each can give you new perspectives on the others. Even though they're both descended from C, and are both "Object Oriented", C++ and Objective-C are miles apart, and will each force you to think in new ways.
Chris Lutz
Still, that's true only with unlimited learning ressources.
peterchen
Relevant: "Actually I made up the term "object-oriented", and I can tell you I did not have C++ in mind." - Alan Kay, inventor of OOP.
Alex
@peterchen - True, but I think most programmers have enough time in life for at least two languages. Learning C++ OO isn't going to harm anyone. I'm not defending C++ as the paragon of OO-ness, but learning a) one of the most widely used languages in the industry, b) one of the most widely influential languages in the industry, and c) the language responsible for making object-oriented programming mainstream is probably worthwhile.
Chris Lutz
A: 

It probably depends on what field you're working in. I find that OOP helps getting more elegant solutions and OOP helps decreasing the gap the requirements and the code. This gives me more maintainable code. So for me, I like to let objects do the work and where suited with polymorphism.

stefaanv
+5  A: 

If your goal is to learn OOP you might consider going with a language which is build for OOP from ground-up so you would be learning OOP and not its implementation.

If you know OOP well and just curious about using it in C++ by all means do that - new knowledge like that is rarely harmful

Ilya Kochetov
I definitely agree. Although C++ also provides an interesting perspective on both OOP and procedural programming... since it was sort a transitioning point between both. In that way it actually helps you understand more about two paradigms.
Jarsen
+1  A: 

For some part I agree with Chris Lutz, but allow me to make some counter points.

Some people become physicist and others become biologists. If OOP programming in C++ does not appeal to you, pick something that does. It's good to dip your feet into a wide range of topics and it's also good to specialize in a couple. There's more than enough knowledge out there to keep you busy for the rest of your life. Pick the ones that interest you.

Alternatively, if you are really asking whether there are benefits to using OOP in C++, then sure there is. Things are a little rough around the edges, but if you have other good reasons for using C then why wouldn't it be? The only disadvantage I find to programming in C++ is that people get preoccupied with classes and appear to forget all about modular design, but that's a problem with the paradigm.

Reasons for using C could be something like this:

  • System/high performance programming
  • Language interoperability

Reasons for using C++:

  • System/high performance programming
  • Many additional libraries to take advantage of
  • Additional expressive power of templates and classes
Rehno Lindeque
how do you know if something "appeals to you" before you've learned it? Should a carpenter refuse to ever use a saw because it "doesn't appeal to him"?
jalf
If you know what the uses of the saw are, and it doesn't fit into your needs (maybe you just plan on carving things), then don't use it - even if you've never tried it. For example I never plan on programming in .NET. I recognize that it has it's uses, but they aren't what I need - so it doesn't appeal to me. Rehno clearly outlines some of the good uses of C++, and then suggests that he make a decision based off a knowledge of the uses of C++.
Jarsen
+2  A: 

Sort of.

OOP, the paradigm, isn't terribly useful in C++. In most cases, it has largely been superseded by generic programming and bits and pieces of functional programming.

However, to pull these off in C++, you typically need to use a few OOP constructs. You need classes, and they should be reasonably designed. You might occasionally (although not as often as many OOP programmers expect) need runtime polymorphism too.

And kind of like Chris Lutz said, this is true for any paradigm. If you learn OOP, then even if you don't write OOP code, you can use the tools you learned from it in other paradigms. The same is true for old-school procedural code. Or for generic code. Or functional. Once you learn it, you can either use it in its own right, or apply bits and pieces of it to another paradigm.

jalf
+1  A: 

Depends on what you are doing. I find OOP pretty useful for GUI programming, and most C++ UI frameworks are object oriented (not to the same extent, though).

If your focus is on system programming, OOP will arguably be much less useful to you.

Nemanja Trifunovic
+1  A: 

If you are going to be using C++ then it would be beneficial to understand the procedural and OO paradigms, as some applications in C++ will be better modeled by OOP, such as many games.

Pick the paradigm that helps you to best model what you are doing, which will make it easier to write the application.

But, to do that it would be best to learn OOP in C++ so that you can see how to apply it.

James Black
+2  A: 

It's worth pointing out that not all solutions to programming problems fall into OOP or procedural. In fact, often within the same project or library, you can find a sensible mix of techniques used.

The trick is to identify when OOP is the better approach and when procedural is the better approach (not always easy).

Therefore if you're going to be using C++, it's definitely worth learning OOP.

markh44