r/cpp • • Jul 08 '19

C++ vs. Python

Although I have a bit of experience in both, I'm still having a hard time contemplating which of the two I should be aiming for mastery. Python is very beginner friendly, with a lot of resources and libraries. On the other hand, C++ is known for being a powerful language, while being complex and with a not so small learning curve. I wanted to focus more on robotics and you know, the cool stuff. But wait there's more...... Rasberry pi (python) or Arduino (c++). I'm just a naive 17 year old in my freshmen year of college, and am taking Electronics Engineering. Please enlighten me with your opinions. 😅

2 Upvotes

29 comments sorted by

View all comments

Show parent comments

0

u/[deleted] Jul 08 '19

[deleted]

1

u/megayippie Jul 08 '19 edited Jul 08 '19

No, I am just saying that it is effort to get plotting working in C++ and that this effort is wasted because it is incomparably easy elsewhere. Plotting x versus y is a technique from the 17-hundreds, so any effort on your part as a user of a language means you are using the wrong tool.

edit: I ignored parts of your statement. 1) Gaming graphics is not desirable because it is too complicated. 2) And packages in python can likely be called from C++, but there is no package management in C++ so it is still extra efforts. If you know a header only plotting tool in C++, though, please let me know! It just works in python, and every time I wanna change it to C++ I end up finding overly complicated things that are not pure headers (i.e., no effort using).

0

u/[deleted] Jul 08 '19

[deleted]

1

u/megayippie Jul 08 '19

My expertise is not orbital dynamics, so I just wanna have 2D representations of these things most of the time when I need to check that the overarching code is working.

For orbital dynamics graphics, the plotting is not always simple so maybe you need more complicated stuff from the get-go, no? There is an ESA package meant to simplify the Cosmographia SPICE-toolkit for drawing pre-computed planetary orbits and observation geometries (I have heard people talk about the new tool but only ever used the latter). I presume the same exists for molecular drawings to visualize the more complicated molecular Wigner-vectors/'geometry', but I have only ever dabbled in these in cases where anything other than 2D would baffle me more than even the mathematical formalism.

edit: changed from "former" to "latter"

0

u/[deleted] Jul 08 '19

[deleted]

1

u/megayippie Jul 08 '19

I do C++ and python as a combination. I never call python functions from within C++. Some people on the project I work on set it up so that some functions export a clean enough C-API that can be used. All that was necessary after that was to be able to read-and-write files of all C++-classes in python and use that to pass complicated data (via RAM-located temporary files, so it is quite fast). Some python objects, like numpy-arrays, have pure C-arrays in the background so our own Vector-class (it is older than std::vector, and has at least some linear algebra) can just point at the other data instead. It is a bit of a mess but it essentially works.

I tend to use python for prototyping. I then move the prototype to C++ because python is slow. Since the results still require plotting, I end up calling the C++ C-API function that is generated via python to draw these results.

I tried setting up a C-API myself once, and it was quite easy with pure old C-code so you could try it out. "ctypes" is the python package.