5 – Static Vs Dynamic Typing

So in researching some C++ stuff, I kept seeing the term static typing and language is being referred to as statically typed, and C++ was one of those. Can you explain what does it mean for a language to be statically typed? When you go to C++, you’re going to have to tell the compiler what kind of variable you want, whether it’s a floating point variable or whether it’s a character or a string. You need to know ahead of time whether you want a lot of precision like a float 64 or a double could give you. And you do this because it tells the compiler a lot about what it has to do. In Python, you don’t have to do that. You can have the variables be whatever they want, and they can change halfway through. It doesn’t matter. But if you declare a variable floats F in C++, it has to be a floating point number for as long as F exists. Now, if you go to a different function, you can have an indefinite string F, although that seems silly. It doesn’t matter outside the scope of the name, but inside the scope, it has to always be that type. And so it is a fixed type. It’s a static type, and that’s what statically typed means. So when designing a programming language, I’m making my own programming language, and I have a choice to go with a statically typed language or not. A dynamically typed language I think is the phrase. How do I make that trade off? What’s going on in making that trade off? Statically typed language is more likely to be faster because you know ahead of time what you’re doing. Dynamically typed language is likely to be more flexible and to let the user decide later what it was they wanted to decide. So it’s a flexibility versus speed trade off.

%d 블로거가 이것을 좋아합니다: