Jump to content

  • Log In with Google      Sign In   
  • Create Account


Considering move to C++


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
15 replies to this topic

#1 blewisjr   Members   -  Reputation: 616

Like
0Likes
Like

Posted 13 December 2012 - 07:38 AM

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?

Sponsor:

#2 Telastyn   Crossbones+   -  Reputation: 3718

Like
2Likes
Like

Posted 13 December 2012 - 07:47 AM

Expanded library support. std::function, the other smart pointers. Not sure how obvious those are, though they would serve non-OO C++ programmers well.

#3 Hodgman   Moderators   -  Reputation: 27690

Like
4Likes
Like

Posted 13 December 2012 - 07:59 AM

Templates, which gives you the "generic programming" and "template metaprogramming" paradigms.

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

Most cool parts of std also rely on templates, such as unique_ptr, and the above-mentioned function (which is great for callbacks, events, delegates, etc).

Edited by Hodgman, 13 December 2012 - 08:00 AM.


#4 LennyLen   Crossbones+   -  Reputation: 3355

Like
1Likes
Like

Posted 13 December 2012 - 07:59 AM

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.

#5 Poigahn   Crossbones+   -  Reputation: 516

Like
0Likes
Like

Posted 13 December 2012 - 08:10 AM

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 !!


#6 Bregma   Crossbones+   -  Reputation: 4766

Like
2Likes
Like

Posted 13 December 2012 - 08:28 AM

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

#7 Álvaro   Crossbones+   -  Reputation: 11891

Like
6Likes
Like

Posted 13 December 2012 - 08:31 AM

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.


#8 ifthen   Members   -  Reputation: 820

Like
1Likes
Like

Posted 13 December 2012 - 08:36 AM

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.

#9 Serapth   Crossbones+   -  Reputation: 5181

Like
-2Likes
Like

Posted 13 December 2012 - 09:57 AM

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.

#10 blewisjr   Members   -  Reputation: 616

Like
0Likes
Like

Posted 13 December 2012 - 02:05 PM

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.

#11 superman3275   Crossbones+   -  Reputation: 1976

Like
0Likes
Like

Posted 13 December 2012 - 09:44 PM

Object-Oriented programming hardly produces error-prone, mangled code. In fact, I would say (And this is someone who came from only procedural programming to C++ around two years ago) that object-oriented programming reduces errors, nevermind making your code far more understandable.

if (Object.size() < Object.MaximumSize)
{
Object.IncreaseSize;
}
This code makes sense, rather than having to use weird structs and arrays, or collections of values that require commenting to explain the correlation. I also recently wrote an article on The Auto Variable (A great new C++11 feature).

As a list, well, I'm not sure. Here are some (very useful) highlights:
  • The Auto Variable
  • Constexpr
  • Vectors
  • Objects, in General
  • auto pointers
  • weak pointers
  • etc.
There are just far too many great C++(11) features. C hasn't been updated since 1999, also, which means many C++ features that are commonplace in many programming languages now might never reach C (However I hope they make a new standard, it's definitely rejuvinate the language).

Edited by superman3275, 13 December 2012 - 09:44 PM.

I'm a game programmer and computer science ninja ph34r.png!

Here's Breakout:
Breakout!

Want to ask about Python and / or Pygame? What about HTML5 / CSS3 / JavaScript? What about C++ and / or SFML 2 (and 1.6)? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

Superman3275@Gmail.com

or Personal-Message me on here smile.png!


#12 ultramailman   Prime Members   -  Reputation: 1557

Like
2Likes
Like

Posted 14 December 2012 - 12:35 AM

C hasn't been updated since 1999

Well, there is the C11 standard, which came out in ... 2011.

#13 blewisjr   Members   -  Reputation: 616

Like
0Likes
Like

Posted 14 December 2012 - 04:29 AM

Object-Oriented programming hardly produces error-prone, mangled code. In fact, I would say (And this is someone who came from only procedural programming to C++ around two years ago) that object-oriented programming reduces errors, nevermind making your code far more understandable.

if (Object.size() < Object.MaximumSize)
{
Object.IncreaseSize;
}
This code makes sense, rather than having to use weird structs and arrays, or collections of values that require commenting to explain the correlation. I also recently wrote an article on The Auto Variable (A great new C++11 feature).

As a list, well, I'm not sure. Here are some (very useful) highlights:
  • The Auto Variable
  • Constexpr
  • Vectors
  • Objects, in General
  • auto pointers
  • weak pointers
  • etc.
There are just far too many great C++(11) features. C hasn't been updated since 1999, also, which means many C++ features that are commonplace in many programming languages now might never reach C (However I hope they make a new standard, it's definitely rejuvinate the language).


I am not saying OOP is error prone what I am saying is that OOP can lead to abstractions that go too deep which leads to harder to maintain code. You can find numerous threads here in the GDNet forums where people have a hard time finding certain bugs because their abstractions are far to complex for the problem they are trying to solve. The issue arrises because people tend to abuse inheritence. From a side node understandable is more of a personal preference. For instance I find it easier to understand and learn procedural libraries then heavily abstracted libraries. It is not that I have a problem with OOP I use it when it makes sense in Python all the time when writing scripts and such the issue with it have have is the over abstraction and abuse that comes from it.

Yes the C11 standard came out very close to the C++11 standard the issue with C at the moment is none of the compilers care to implement the newer C standards to this day the only full C99 compiler I know of is Pells and maybe Intel. GCC has some support and MSVC has terrible support.

It comes down to the fact for me that there are certain aspects of C++ in the new 11 standard that I really like and really wish were in C. In all honesty one feature that would make a world of difference in C is namespaces but they still don't exist in any compiler I have used.

#14 ifthen   Members   -  Reputation: 820

Like
1Likes
Like

Posted 14 December 2012 - 07:35 AM

Yes, OOP can lead to unnecessary abstractions in hands of an inexperienced programmer. Functional programming can lead to overcomplicated, not understandable and unclean code. None of these pitfalls is a reason not to use these paradigms, just a reason not to use libraries which abuse them.

Edited by ifthen, 14 December 2012 - 07:36 AM.


#15 Cromulent   Members   -  Reputation: 349

Like
0Likes
Like

Posted 16 December 2012 - 05:11 PM

Yes the C11 standard came out very close to the C++11 standard the issue with C at the moment is none of the compilers care to implement the newer C standards to this day the only full C99 compiler I know of is Pells and maybe Intel. GCC has some support and MSVC has terrible support.


Clang has the best support for both C11 and C++11 at the moment as far as I am aware. GCC is second place with C++11 support. MSVC has no support at all for any C dialect other than ANSI C and has poor C++11 support (comparatively speaking). Intel I have no idea about other than they have good support for C99. No idea about C11 or C++11.

#16 blewisjr   Members   -  Reputation: 616

Like
0Likes
Like

Posted 16 December 2012 - 05:30 PM

I agree Clang has the best support with GCC as a close second right now I use GCC for my toolchain through MinGW due to better windows support than Clang which requires a bunch of muck around to get to work properly. If I was running Linux or a Mac I would use Clang in a heartbeat but even on Linux it would require custom building of all your libraries. Microsofts compiler is great but they are just too slow to implement standards.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS