Python or C++?

Hi all,

I’ve got some questions about Python/C++ with Panda:

  1. What is more efficient with regards to system resources/memory/CPU usage/etc?
  2. Can one of them process data faster than the other? I.e. if you have code that does the exact same thing in both languages, will one be faster at executing it than the other?
  3. Can you use both Python and C++ when developing for Panda? Or do you have to stick to one language?

Thanks :slight_smile:[/list]

This was beaten to death and I’m sure you’d find lots and lots of other topics covering this question, if you briefly searched the forums. But in short:

Python is generally less efficient then C++, but speed is not always an issue. When codding gameplay you usually need to do it quickly and easily (design changes, you need to prototype, be flexible), and speed of the programming language used is unimportant, because you mostly just call Panda’s internal C++ methods anyway. For that Python is perfect – easy to write with and irrelevantly slower.

Yes, you can use Python and C++. The best drill is (generally, not always) to write everything in Python initially (for ease of prototyping and verifying algorithms), then locate bottlenecks and rewrite only the computationally intensive stuff to C++. That way you get the best from Python and C++.

Of course you can write everything in C++, but Panda is meant to be used with Python and, unless you’re really in love with C++, your life will be easier that way.

I actually Google’d it and found a huge variety of responses. It seems every time the question was asked, anybody who favors C++ would go on the defensive and insist it was better, but I couldn’t find much with specific reasons why.

Thanks for the info :slight_smile:

The reason I asked is that I’m actually familiar with C++, but I’ll give Python a shot. I’m going through the tutorials right now and so far it seems alright.

Experienced C++ users may get defensive since from a purely computational performance standpoint C++ is always equal or superior and for them the other aspects may be almost or completely irrelevant. For “the average user” though Python does hold a lot of good things like coppertop mentioned.

long story short.
resons to use c++:
-beeing an experienced c++ user already and feeling uncomfortable with python
-speed concerns (in 99,99% python’s speed is totaly fine, in the remaining 0,01% you can write a single c++ extension)

reasons to use python:
-“just works”
-faster development due to less language hassles
-no compile-time thus less waiting
-better documentation
-dynamic programming while the application is running
-easy to create platform independant packages
- lots more i guess

of course you can disregard all advices and see which language works best for you. since you know c++ , i’d recommend to take a sip of python and see if it suits your taste. should be easy to pick up so you can compare yourself.

What do you mean by this one?

Another question for anybody that can answer it - say I get a program working and I want to get somebody to test it. How the heck do I compile it with python so it creates an application I can just send to somebody instead of them having to install panda and python?

There’s a large section in the Panda3D manual, titled “Distributing Panda3D Applications”.

Ahh, alrighty. Haven’t gotten that far yet :slight_smile:

In short, you can make changes to the code while your program is running, and the changes will take place. This can greatly speed up the speed of your workflow.

How is that even possible? Doesn’t python read the entire code into memory when first executed like other languages do?

Yeah, but you can replace functions and methods by getting all instances of the old ones, and replacing them all by the updated function or method, whenever you make a modification to that function. I think that’s more or less how it works.

Both can be used on Windows, both can be used with .NET, and both are standardized languages.Python is easier to learn than C++ in my opinion. Python is the best so there is no doubts it. Because it provides interactive shell, where you can try syntax, create simple test functions.

Of course python because it is very easy compare to C++. Because Python supports procedure-oriented programming as well as object-oriented programming. While C++ is only object oriented language.It is High-level Language, Free and Open Source and Portable.

Cool, i didnt know this…so C++ does not support this: codepad.org/SblzLaT3 :wink:
Of course C++ is not only for OOP. By the way I am using C++ more than 5 years now and tried Panda3d
because it supports python. Python ist relative easy to learn compared to C++ but Python makes one really lazy and allows some real uggly hacks. So in Python I have to care not to become too frowsy. But with Python you can develope really faster. So just give panda3d + python a try :slight_smile: .

I’m a python fan because of its community. What other programming language can adapt so organically? Java has to support large legacy installations as well as support numerous Sun Certifications and C++ seems incapable of removing code from its base and just expands such that if you want a dictionary, you have 20 different libraries to look at and don’t know which is good. Outdated ideas persist in C++ and are eliminated in python. In 3.0 they change / so that 1/2 is a float not an integer(1//2 for an int). I’m not sure if this change is better or not but I love that they did it. It just shows how adaptable they are and I am sure there was a lot of discussion on the topic. btw pre 3.0 are still being supported and updating will not be required for a long time I’m sure.

As for hacks; python is generally more understandable because everyone uses the same tools that have been adapting constantly over a long time. Python does not have strict typing, although its easy to add asserts, but the scope is logical and stricter then JScript or PHP. The package system is simple and doesn’t require hacks. A map, slice[:], lambda or @decorator maybe be a bit complicated the first time you see it, but they are the same tools that you will see again and again and solve problems that in other languages may inspire hacks. You’ll most likely never see a python programmer use a macro.

It’s hard to point to specific things and say, ‘python is better because of this’. Python is better because of many many little things and it is that way, not because its interpreted but because of the adaptiveness, organization of its community combined with the its adoption in the corporate world.