Python and C++

What are the differences in python and C++?

Do you somewhat experienced C++ programmers use python too?

I asked the same question on but it seemed I got cocky answers back with people that disliked C++. I did however ask why would someone use python if C++ is more powerful though lol.

but i was under the impression that C++ IS more powerful...Is this correct or incorrect?
Last edited on
closed account (zb0S216C)
1) Python is interpreted; C++ is not.
2) Python is used for scripting and application extension; C++ is used as the core language of an application and isn't used for extending applications.
3) Python is obsessed with spacing; C++ is not.
4) Python is slow; C++ is not.
5) Python creates applications quickly; C++ doesn't.
6) Python reduces the chances of buggy code. C++ increases the chances dramatically.
7) Python is cross-platform; C++ is also (if you intentionally write cross-platform code).

Last edited on
From a language point of view, the main difference (aside from syntax, obviously) is that Python is dynamically typed and C++ is statically typed. What this means is that in Python a variable is a generic slot that can contain any type of data. In C++, on the other hand, variables don't exactly exist at run time; they're just names used at compile time for the same of the programmer. Variables in C++ do have types, and they types are used by the compiler to generate appropriate code.

Static and dynamic types offer certain trade-offs.
Static types can be verified by the compiler, which completely eliminates a whole category of programming errors (e.g. trying to do red+9). Dynamic types have to be checked at run time when they're used, which means that the only way to make sure a function call is correct with a given set of parameters is to actually make the call. This makes testing code with dynamic types a lot harder, because more execution paths have to be tested. Dynamic types also have a run time penalty because types have to be checked over and over again.
On the other hand, a function that takes dynamic types can be reused with different types of parameters without being recompiled (polymorphism), as long as the code inside can be applied to the parameters.
In summary, dynamic types are generally considered easier to deal with for the programmer but harder for the computer, while static types are more robust, but sometimes it's necessary to jump through hoops to get the compiler to accept perfectly valid code.

I'm not sure if Python supports metaprogramming, but it might. Also, I don't know to what extent it supports functional programming.

From an implementation point of view, the reference Python implementation is interpreted by a virtual machine that runs byte code, which makes it slow. In fact, the Python interpreter is notorious as one of the slowest interpreters around.
C++ is almost always compiled to native code, although one or two interpreters that implement a subset of C++ exist.

As for applications, Python is mostly used as a scripting, or "glue", language. That is, the top level script mostly calls routines written in C. This is useful when the logic can be written in terms of existing code that will do most of the heavy-lifting, for example text and regex processing and command line scripting.
C++ is mostly used in applications that require performance but also benefit from some abstraction built into the language. For example, simulations and GUI can be described intuitively in OOP.
IMO, C++ is appropriate for large projects, while Python performs well for one-off programs and things that won't run for a very long time.
Topic archived. No new replies allowed.