> For the complete documentation index, see [llms.txt](https://harmeetsingh.gitbook.io/scala-type-system/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://harmeetsingh.gitbook.io/scala-type-system/phase-i/chapter-3-type-disciplines.md).

# Chapter 3: Type Disciplines

Programming languages can be categorized in many different ways—for example, by their programming paradigm (object-oriented, functional, procedural, etc.) or their execution model. One of the most common ways to classify them is by their **type discipline**, as shown in the following diagram:<br>

![](https://lh6.googleusercontent.com/R-pUgCGzDYzWYp6e32vOs5EINw6kgsHhyTNymQlDMHXxQA-NLYR_6vYSBDzLqc0EZAg3Mpr01p4T9NVTY-nejMcINuxJyrMQCRK8v35HN2DFHTZggAI1LL10dLpli8FvffvXNhj9)

Programming languages are broadly classified as **statically typed** or **dynamically typed**. There have been endless debates about which approach is better. We will not attempt to settle that discussion here, as both approaches have their own advantages and trade-offs. Instead, this chapter provides a brief overview of these categories and the terminology commonly associated with them.<br>

Another commonly used classification distinguishes languages as **strongly typed** or **weakly typed**. Although these terms are widely used, they do not have universally accepted definitions, and their meanings often vary between authors. Throughout this chapter, we use the interpretation described by **Heather Miller** in her [blog](https://heather.miller.am/blog/types-in-scala.html).

![](https://lh5.googleusercontent.com/Jjrw-3pat61UuD4sdhRJbWlg0hVHcLLWGl2VI-CK8IXFnq_96P7uEyrt4jGgNNyimG-c9zwpUj62-XPUPhAAY-AJGAtTM8G1Pu0q8CdM3UTUcjZT7uF-ksxNiMEtTeohXSGgyu6C)

### **Dynamic Typing**

In **dynamically typed** languages, type checking primarily occurs at runtime. These languages are typically executed by an interpreter or a virtual machine, although modern implementations may also use just-in-time (JIT) compilation.

#### **Strong Dynamic**

A **strongly dynamically typed** language performs runtime type checking and prevents operations on incompatible types. For example, attempting to call a method that exists on a `String` but not on an `Int` results in a runtime error rather than producing undefined behavior.

Python is a commonly cited example of a strongly dynamically typed language.

#### Weak Dynamic

Weakly dynamically typed languages tend to allow more implicit conversions or provide mechanisms that bypass strict type checking. Some languages also allow direct memory manipulation, making it easier to perform operations that would be disallowed in strongly typed languages.

Languages such as **JavaScript** (because of its implicit coercions) and **Assembly** (because it provides unrestricted access to memory) are often cited as examples, although the classification depends on the definition of "weak typing."

### **Static Typing**

In **statically typed** languages, programs are type-checked before execution, typically during compilation. The compiler acts as a safeguard by detecting many type-related errors before the program is run.

#### **Strong Static Typing**

A **strongly statically typed** language ensures during compilation that values are used according to their declared types. For example, if a variable is declared as an `Int`, the compiler prevents it from being used as another type without an explicit conversion.

Languages such as **Scala** and **Java** are common examples.

#### **Weak Static**

Weakly statically typed languages perform compile-time type checking but may also provide mechanisms that allow programmers to bypass the type system or manipulate memory directly. This can make it possible to violate some of the guarantees normally provided by static typing.

The **C** programming language is commonly cited as an example because it allows operations such as pointer arithmetic and explicit memory manipulation.<br>

The concepts of static vs. dynamic typing and strong vs. weak typing have been discussed extensively over the years. If you'd like to explore them in more depth, the following article provides an excellent starting point:<br>

[**https://pythonconquerstheuniverse.wordpress.com/2009/10/03/static-vs-dynamic-typing-of-programming-languages/**](https://pythonconquerstheuniverse.wordpress.com/2009/10/03/static-vs-dynamic-typing-of-programming-languages/)\
\
\ <br>
