Friday 30 January 2015

Python vs C++

  1. C++ is a "statically typed" language, while Python is a "dynamically typed" language. In one case, the types of the main components of the set of instructions (the computer program) are explicitly declared while in the other case they aren't.

  2. C++ is "faster" than Python
    C++ is typically a "compiled" language while Python is typically an "interpreted" language. With C++, the instructions are very well understood with all types specified and so they are translated into machine code (they are compiled) and executed unambiguously by the computer ...while with Python a separate computer program has to figure out what the Python instructions really mean [2,3] and how to "interpret" them to produce an output. The overhead of running this extra program versus simply just running the well defined machine code typically ensures that C++ runs much faster than Python.

  3. Python is more concise than C++Though this is certainly not an absolute truth, the example also shows one of the reasons why Python code tends to be shorter than that written in C++ (i.e. there is no need to declare types explicitly and this literally saves space in written code). Smaller code size for the same task leads to "rapid prototyping" and this is partly why one would use something like Python when speed of development is important.

  4. Automatic memory management in Python, whereas there is an overhead in explicitly managing memory in C++.

  5. C++ is a general-purpose programming language regarded as middle-levelas it is a combination of both high and low-level language features. It is a much lower-level programming language than Python. Python is a high-level programming language.
C++ places considerable burden on the programmer by requiring that he delve into the intricacies of memory management, exception safety and the like. The resulting code is complex, verbose and often difficult to read. The learning curve for C++ is steep and there is a high barrier to entry.

Python with its "programming for everyone" idealogy, is ideally suited for scientific computing and quantitative finance, as it can be quickly adopted by people with no formal background in programming. Yet historically most of such systems were developed in C++.

Thus we have a gap that needs to be bridged, the gap between the core C++ code and Python.
This is where Boost.Python comes to the rescue.

It must be noted that Boost.Python is not the only technology for creating hybrid systems in Python and C++. There is also the "Simplified Wrapper and Interface Generator(SWIG)". Swig connects programs written in C and C++ with a variety of high-level programming languages, including Python.

References :

http://www.thalesians.com/finance/index.php/Knowledge_Base/CPP/Boost_Python_Step_By_Step#Python_versus_C.2B.2B

https://www.quora.com/What-is-the-difference-between-programming-languages-such-as-Python-C-C++-and-Java

No comments:

Post a Comment