V
V
Vika Marmeladka2018-02-04 11:22:24
Programming
Vika Marmeladka, 2018-02-04 11:22:24

Please explain to a newbie which is better: static typing or dynamic typing?

I just can’t understand why a static one is needed when there is a dynamic one, is there less trouble? Or is it better to manage the RAM with static? Or does it somehow affect the speed of compilation?
Sorry for stupid question(

Answer the question

In order to leave comments, you need to log in

5 answer(s)
J
Jaroslaw Goszowski, 2018-02-04
@homsi959

This affects the presence of logical errors in the project. With dynamic typing, it's very easy to "do business" and then a bug in production.
The statics at the compilation stage will show an error and will not let you compile / upload to production.
Yes, a little more code to write, but it's worth it ;)

O
OnYourLips, 2018-02-04
@OnYourLips

Various tasks.
Dynamic typing is convenient when you need to do something quickly on your knee.
However, maintaining such projects for a long time is very painful and expensive.

I
InoMono, 2018-02-04
@InoMono

If some type of typing was obviously the best , then today it would remain in proud victorious loneliness.
Dynamic typing allows you to make mistakes. And no matter how brilliant an attentive programmer you are, you will make them. And they will come to light only at the launch stage, or maybe they will not be noticed at all for several weeks or months.
Static typing allows you to identify a certain (and common) type of errors immediately and immediately cut them off. Even before the very first launch of the application.
The second feature of static on modern fast hardware is not critical. But with heavy loads or a small amount of resources - and this feature matters. Namely - a significant number of actions performed by dynamic typing systems at each program execution - in static typing systems are performed once. Even before the first launch of the program.
Why does dynamic typing even exist? Because the programmer has to make extra gestures to get all these charms of static typing into his program. Although these gestures are small, they have to be done often, so in total dynamic typing saves a lot of time to write the program. But not for fixing it. Debugging programs with dynamic typing is a slightly more laborious process.
Therefore, now an interesting modification of static typing is being used more and more widely - type inference. That is, you do not need to explicitly prescribe the type of the variable. You can write the same as with dynamic typing. Just "new variable = something_calculated_for example_return_from_function_or_expression" and the type for this new variable will be determined by itself. But it cannot be changed in the future.

E
Egor Drushchenko, 2018-02-04
@GhostFantik

For me personally static typing is better! If you are dealing with a new library / framework, then static typing is easier, because you can see what needs to be passed to the method and what it returns (at the type level). Dynamics, alas, cannot boast of such.
And of course, Intelisense works better for static languages ​​than for dynamic ones. Compare Sharp and Python for example.

N
Nikita Kit, 2018-02-04
@ShadowOfCasper

Dynamic typing is when you can write
5 + "5"
AND get "55" with a typeof string (google "concatenation").
In languages ​​with static typing, you will get an error - first you need to convert all variables in the expression to the same type yourself. It's clearer by hand. As far as I know, or maybe I don't know, I only know js well - it's dynamic - in languages ​​like C ++, the data type is determined when a variable is defined with a keyword. int number = 5 or char name = 'nicky'
In js, the variable definition keys var, let, const can be any data type, they can be a number, a string, an object, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question