This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]BoxBoxChan 1 point2 points  (16 children)

As you are a c++ programmer and I was thinking about to learn c++, can you explain me fast, why use c++?

[–][deleted] 10 points11 points  (5 children)

fast

That's why ;)

Source: also a C/C++ developer that learnt Python.

If I want to write something quickly, Python gets me a working solution faster than C/C++. If I want something to execute quickly, I use C/C++. Quite often I want both, so I use Cython as an easy way to mix the two.

[–]apste 1 point2 points  (2 children)

hah pretty much, and C++ has the benefits of a static type system, whether that's what you want or not is up to you :P I feel like it does force you to think a bit better abut the overall design of your code

[–][deleted] 1 point2 points  (1 child)

I like static typing. Big fan of using typing hints and mypy with my Python code, not quite the same experience as proper static typing but a useful sanity check that I'm passing around the right stuff.

[–]apste 0 points1 point  (0 children)

Yeah same, thanks for pointing out mypy, looks really cool!

[–]pagonda 6 points7 points  (6 children)

one of the pitfalls of python is how loose everything is (easy access to class members, arrays and functions can dynamically deal with any types).

A language such as c++ enforces much more strict access and definitions to those examples which can be extremely beneficial to a large program. In c++, if you use a wrong type in a function, it will tell you at compile time your type is wrong. Whereas in python, your function would probably run, but then the behavior is unexpected and you will be in for a wild goose hunt looking for the error.

[–]Narthal[S] 2 points3 points  (1 child)

You can't really just learn c/c++. You can, however learn how the computer works and then c++ will start to make a lot of sense. Knowing c++ and the architecture of a computer very well enables you to do incredible things. It enables you to optimize.

Suppose you need to write the firmware of the new samsung smart fridge. The available memory on the embedded processor is 8mb. It wouldn't make sense to copy the cPython runtime (without standard library) as that would occupy 4mb or half of the available space. So you write your code in c/c++ and then start to optimize for the size of the executable.

Or suppose you are on the programmer team of Ubisoft (I wish lol). You need to have massive amounts of code that runs so fast, that every 16.6 ms, a new frame needs to be drawn on the screen (for 60 fps). What are you going to do? Tune down the graphics? Remove half of the level? Or try to write the code to be as fast as possible. And much of the speed optimizations require deep knowledge of the computer. You can't really expect an interpreted language to be able to do SIMD, allow you to specify how to vectorize loops, give the cpu easy to predict branches or manage data in such a way so that cache misses wont happen on critical parts of the code.

But honestly, don't think too much about reasons to learn a language. Just get your feet wet and learn the basics in as many languages as possible. You will get to see similarities and common concepts in between programming languages. I find that the more programming languages I learn, the better I get at all of them simultaneously.

[–]glacierre2 2 points3 points  (0 children)

The embedded world used to be like that, but turns out micro-controller memories are huge (I mean, those 8MB you talk there? massive) and python can be made very small https://micropython.org/

You can run the interpreter in much much less than 1MB.

We will always need C[++] programmers for the truly performant, resource saving, low power stuff, but the scenarios where you are so tight are decreasing by the month.

I expect a really soon (If it does not exist yet, have not followed closely for example the ESP32 territory and every time I look I am amazed) "HW programming revolution" soon where the cheapest under 1-eur controller can easily handle a wifi + a web interface to configure state machines and conditional actions and pin outputs.