M
M
Maxim Siomin2020-07-09 22:08:48
C++ / C#
Maxim Siomin, 2020-07-09 22:08:48

Auto in c++ - good or bad?

I once heard about the fact that python is slow, due to the fact that variables in it automatically determine their type. It allocates RAM and processor power. It turns out that if I use auto
it, the program will work more slowly?

In general, the question is:
Will the program slow down if I use auto?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Egorithm, 2020-07-09
@MaxSiominDev

Compilation will slow down a bit (but you won't notice it), but execution certainly won't.
Sometimes you can't do without auto (in template functions with decltype, with structural bindings, with lambdas...), but often the code is simply shorter and more readable.
Yes, Python has dynamic typing (i.e. full shit), but C++ doesn't. In C++ there is dynamic binding (for virtual methods), there is RTTI, but they are completely different things.
Python is slow because it is not compiled but interpreted. Those. it compiles on the fly every time.

A
Anton Zhilin, 2020-07-09
@Anton3

Short answer: no, it won't slow down. It will work exactly the same as if you manually typed in the type.
The difference from Python is that in Python the type of a variable can be different for different function calls. And in C++, the type is not written explicitly, but is fixed and is guaranteed to be restored at the compilation stage.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question