Sign in to follow this  

C++ really needed?

This topic is 4865 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey people, I've been reading up about python and it's integration with C lately, and have figured that there's not much point in me continuing coding straight C++ when the speed difference is negligible, and it's much easier to code the programs in python. My question is, is there much point in me using C++ with python, when i could just use straight C? And what differences in terms of program design does Python and C have relative to pure C++?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
In a large game setting (read: mmorpg), a game coded entirely in python would be extremely slow (read: laggy). Python is an excellent language to combine _with_ c++, but alone it isn't much good when you get into high performance games.

Share this post


Link to post
Share on other sites
malune - You can write code in C++, taking advantage of the C++ library, and yet expose a pure C interface to python if you want to. Even if you just write procedural C++, the library can be useful.

You can also write C++ code and use boost::python (hey, thedevdan, see, more Boost goodness [grin]) or SWIG and have them take care of the interfacing.

But other than that, you are right, it's generally easier to use Python to do the high-level design and C (or C++) to do the low-level optimizations than it is to use C++ everywhere. The only difficult point left is the actual interfacing code, and even then, it's not overly complicated, just tedious (and be careful to keep your reference counts right).

As for differences in design, spend some time programming in python and you'll quickly realize how different it is from C++. [grin]

If you have more specific questions, feel free to ask.

Share this post


Link to post
Share on other sites
Quote:
Original post by thedevdan
How about this: why use C when you can use C++?


Sorry, by C i mean procedural C++. Why would i need to use OOP C++ when Python already includes the same design constructs, that was my point. -- sorry for the confusion :P
And as for the speed issue, I wouldn't be coding everything in Python, i'd be extending it with C, not embedding, would this still be too slow for games programming?

[EDIT] -- Woops i replied at the same time as you Fruny :P. That's quite interesting, does the interfacing code slow down the overall program? Or does this not add much overhead?

Share this post


Link to post
Share on other sites
Quote:
Original post by malune
[EDIT] -- Woops i replied at the same time as you Fruny :P. That's quite interesting, does the interfacing code slow down the overall program? Or does this not add much overhead?


Yes, it slows things down somewhat, but it'll still be faster than 'pure python'. Python is a dynamically-typed language, C++ is a statically-typed language. There are checks and conversions to be done when passing objects from python to C++ which, when done properly, do carry an overhead.

I can only reiterate my prior advice: try it out and see if it suits you. It works fine for me because I tend to spend much more time in C code than doing python/C transitions: I manipulate large multidimensional numeric arrays with the numarray library. So, while each element of the expression triggers a python/C transition, I do spend enough time looping over the array to compensate for that.

And even if you stay in 'pure python', python itself is still implemented in C (or Java, or MSIL - depending on the version you pick up) so, at some level, that 'overhead' is a non-issue. By implementing more complex functionality in C++, you incur that overhead only once instead of for each elementary python operation that may need such a check.

So, get started in python, it really is an easy language to learn, then start delving in python/C (or python/C++) interfacing -- I haven't found the online tutorials on this specific topic to be *that* helpful; much less, at any rate than the corresponding section of "Python in a Nutshell" (handy reference, by the way). Even if you decide not to use it in the end, you'll have learned something new and useful.

Share this post


Link to post
Share on other sites
I would say that with the appropriate binding, it's still a lot easier to use OOP-C++ than to drop down to purely procedural C. You would use C++ for speed rather than to code things that can't be done in Python, so you use whatever is the most effective tool at the time, which is often C++ classes.

Share this post


Link to post
Share on other sites
There are many ways you can design a system. You are not forced to use OOP even when using C++ so do not feel that you must.

If you can sensibly design a system using another paradigm, feel entirely free to do so.

Share this post


Link to post
Share on other sites
Quote:
Original post by flangazor
There are many ways you can design a system. You are not forced to use OOP even when using C++ so do not feel that you must.

If you can sensibly design a system using another paradigm, feel entirely free to do so.


Yeah, i could probably design a better system at the moment procedurally, but since i have time, i'd like to learn how to properly use OOP as well, seeing as it's meant to have so many benefits.

Share this post


Link to post
Share on other sites
Quote:
Original post by malune
Quote:
Original post by flangazor
There are many ways you can design a system. You are not forced to use OOP even when using C++ so do not feel that you must.

If you can sensibly design a system using another paradigm, feel entirely free to do so.


Yeah, i could probably design a better system at the moment procedurally, but since i have time, i'd like to learn how to properly use OOP as well, seeing as it's meant to have so many benefits.
You don't sound convinced that OOP will be a silver bullet.

Share this post


Link to post
Share on other sites

This topic is 4865 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this