🌱 Tim's Dev Wiki

Search IconIcon to open search

Type System

Last updated September 21, 2022.

A type system is a set of rules defined by a programming language specification that assigns a type to every variable, expression, function, and possibly other things beyond those.

# Why Type Systems Exist

Type systems exist for one reason: to help you write less buggy code in a more self-documenting way.

# Static Typing

A statically typed language is one where the type system’s rules are checked when you run the compiler (ie. at compile-time). It’s called ‘static’ because any type system violations are caught before you execute a single line of your program.

# Dynamic Typing

A dynamically typed language is one where the type system’s rules are checked during the execution of the program rather than at compile-time. In other words, nothing has a type until you run the program, and only then do the types get assigned to expressions, variables, functions, etc.

# Strong Typing

There’s a lack of a formal definition for this, but a strongly typed language is basically one where it is not possible for the developer to bypass the type system’s rules. In other words, a value’s type never changes in unexpected ways, such as through implicit casts.

# Weak Typing

Just like strong typing, there is a lack of a formal definition, but in general: weakly typed programming languages are ones that have a more relaxed enforcement of its type system’s rules, meaning that it’s possible to violate/bypass them.

Sometimes, we talk about the relative weakness of the type system between different programming languages. Eg. C++ is not strongly typed, however it is consider ‘stronger’ than C.

Note: people often confuse weak typing to mean dynamic typing, and strong typing with static typing. They’re completely separate. For example, C is both weakly typed and statically typed, while Python is both strongly typed and dynamically typed.