-4

Suppose you have written a prototype for an application in python, now you want to rewrite it in c++ for speed reasons and to make a real software out of it.

What are things to consider before starting to do this?

I read a couple of posts about "Big Rewrite", but i am unsure if this is the same or different topic?

Is it a good strategy to try to copy every function as similar as possible and rewrite function for function?

For every special purpose library like the logging module/pandas/etc. Do you look for a similar library in C++?

  • What is wrong with this question? – user3680510 Jul 03 '20 at 20:50
  • 2
    see [Why do 'some examples' and 'list of things' questions get closed?](https://softwareengineering.meta.stackexchange.com/a/7538/31260) – gnat Jul 03 '20 at 20:51
  • @gnat i don't understand this. The highest voted question is https://softwareengineering.stackexchange.com/questions/46716/what-technical-details-should-a-programmer-of-a-web-application-consider-before why is this question better than this question. Do you need to make it more narrow? – user3680510 Jul 03 '20 at 21:03
  • 5
    @user3680510 Unfortunately, votes are more an indication of a heavily viewed question than a good question; that question is 12 years old and would almost certainly be closed if it were asked today. – Philip Kendall Jul 03 '20 at 21:13
  • 3
    In my experience, it's not worth porting *everything* to C/C++. Instead, create a Python wrapper that transforms the data into an easy to use format, then launch your C++ program as a subprocess. Also, use your Python version to generate test cases for individual functions in your algorithm – don't try to do a “big bang” integration where you test only at the end. For many problems, numpy/pandas will be just as fast as a version ported to C++, but it depends on the exact algorithm. – amon Jul 03 '20 at 21:25
  • 1
    Or, write performance-sensitive parts of the code in C/C++, and make them callable from Python. Leave the "big parts" e.g. skeleton, I/O in Python. – rwong Jul 04 '20 at 00:10

1 Answers1

2

Figure out where speed is actually needed.

Rewriting all your code is almost certainly not necessary as it is only going to be in a few places (likely) where speed is really needed. Also remember that many attempts to increase speed would be more appropriately solved with things like a queue. You can create wrappers to just run the Python code from your C++ program which will save a heck of a lot of time.

Also, if you just require more speed, see if you can get the speed from just a better Python implementation. There are so few use cases where C++ is actually required to make a difference.

ScrumSucks
  • 197
  • 3
  • You *really* don't want to be doing any intensive numerical calculations in pure (C)Python - Python's built in numeric types are incredibly slow. Of course, NumPy already exists for letting you push those calculations done into native code. – Philip Kendall Jul 04 '20 at 09:56
  • But should the main program be c++ and call python for some stuff or the other way around? – user3680510 Jul 04 '20 at 20:09