Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Static typing: Difference between revisions

From Coderwiki
info, type inference
 
(No difference)

Latest revision as of 21:25, 12 August 2025

One of the ways we can group together programming languages is with these two groups:

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.