Considering move to C++

Started by
14 comments, last by blewisjr 11 years, 4 months ago
This is probably a rather pointless topic but I will go for it anyway and see where it goes.

Many here know I am a huge proponent of C. As of late I am considering a move to C++ due to some of the C++ 11 features. One such feature is std::unique_ptr.

Keep in mind I am not a huge proponent of OOP way to easy to abuse and mangle the ability to maintain code. What other advantages besides the obvious would I gain?
Advertisement
Expanded library support. std::function, the other smart pointers. Not sure how obvious those are, though they would serve non-OO C++ programmers well.
Templates, which gives you the "generic programming" and "template metaprogramming" paradigms.

For a real-world example of the benefits, C++'s [font=courier new,courier,monospace]std::sort[/font] is a lot faster than C's [font=courier new,courier,monospace]qsort[/font], due to the fact that the optimiser can massage it a lot more at compile-time.

Most cool parts of [font=courier new,courier,monospace]std[/font] also rely on templates, such as [font=courier new,courier,monospace]unique_ptr[/font], and the above-mentioned [font=courier new,courier,monospace]function[/font] (which is great for callbacks, events, delegates, etc).
The STL containers/iterators are very useful too. Sure you can implement them yourself in C but having them built into C++ makes them far easier to work with and are more likely to be better optimized than what most people could come up with on their own.
Although I am no Master at C++, I have done some programming in the lanquage. Besides being widely used ( This is the reason I am making an honest effort to switch ), I do not think that OOP is strictly enforced ! ? If you do not want to Isolate routines so that you do not want keep re-writing the code over and over vs Cut and paste. (personally I find that to be much faster in setting up a knew program, especially if I Already solved that routine say 6 times already ) you really do not have to do OOP.
I have been using OOP from my Pascal days. But I have found that larger programs runn faster in C++.

Your Brain contains the Best Program Ever Written : Manage Your Data Wisely !!

C++ is a multi-paradigm language. It supports you if you want to do OOP. It supports you if you want to do imperative. It supports you if you want to do metaprogramming. It supports you if you want to do functional programming. It gets out of your way of you choose not to use those paradigms.

The biggest and best thing about C++ is it supports the RAII paradigm (which requires a certain amount of OOP). That alone makes C++ stand head and shoulders above C or Java and any other language with non-deterministic destruction. You can use RAII using only std::unique_ptr and lambdas if it's important that you avoid the appearance of using classic OOP.

Stephen M. Webb
Professional Free Software Developer

I don't like OOP myself. It's like nail-oriented roofing. Objects are useful constructs, but they aren't the only tool around.

C used to be my primary language, but I have been using C++ for about 11 years now. The things I couldn't live without if I were to go back to C are:

  • std::string
  • Containers (primarily std::vector, std::map, std::unordered_map)
  • RAII
  • Operator overloading for math classes, like vectors and matrices.
std::string and std::vector. I cannot overestimate their importance in managing code. String gives you a lot of clean functions (eliminates the most of buffer overruns), has its operators overloaded (that means no more concat) and is not zero-terminated (you can store whatever you like there). (C++ streams are also good for these reasons excluding the last one.) Vector gives you an easily resizable array and it stores its size for you, so no more arraysize integers. Both of them most definitely ease the development process.


OOP is great, but not everything is an object. That is why I do not like languages thet shoehorn OOP to situations where it does not work. C++ does not force you, however – it lets you choose.

There is clearly no reason nowadays why would not someone want to use C++ (except in circumstances where the STL is nonexistent). I would recommend you to switch.

I don't like OOP myself. It's like nail-oriented roofing. Objects are useful constructs, but they aren't the only tool around.

C used to be my primary language, but I have been using C++ for about 11 years now. The things I couldn't live without if I were to go back to C are:

  • std::string
  • Containers (primarily std::vector, std::map, std::unordered_map)
  • RAII
  • Operator overloading for math classes, like vectors and matrices.



It's funny that your list from C to C++, reads almost identical to one I would create about what I miss going from C# to C++... :)

  • .NET class libraries, vastly superior string handling
  • generic containers and LINQ, especially LINQ, also not having to deal with C++ terrible template syntax and error handling
  • sensible automatic memory management
  • operator overloading I'm rather meh towards. So instead I will go with the lack of multiple inheritance and existence of interfaces.



With C++ 11, I think there are a number of things you can add to the list. lambda functions, automatics, those would be useful in non-OO programming.
Thank you very much everyone. The info was very helpful. So many features I could find use for. It has been quite a while since I touched c++ at all. I will have to give the plunge a go as I think it would be excellent for my programming style. I can only help to remember what it is like to not have to manage tedious void* casting to get the right effect. I think std::function is my biggest turn on at the moment.

This topic is closed to new replies.

Advertisement