Static typing
More actions
One of the ways we can group together programming languages is with these two groups:
- Statically-typed programming languages
- Dynamically-typed programming languages
Static typing is where we explicitly give every variable and field a data type.
Sometimes, it is possible for the compiler or interpreter to 'guess' the data type of a variable.
This doesn't mean it has no type (it's not dynamic), it's just that we don't have to explicitly mention the type. The variable still has a type, and we can't overwrite it with a value of a different data type.
For example, this code in C will make x an integer, even though we don't specifically mention it:
auto x = 17;
The code above is internally translated to:
int x = 17;
The C auto keyword is not the cleanest way of doing type inference. In Rust, variables are declared using the let keyword, and you can optionally specify a type on top of that.