liveBook · Manning

Static typing

As explained in Go in Practice, Second Edition

Static typing determines and checks program types through analysis before execution, typically during compilation.

Static typing determines and checks program types through static code analysis before execution. Go is statically typed, unlike dynamically typed languages such as Python, PHP, and JavaScript, which check types at runtime and may convert values during execution. section 1.3.4

Go combines static typing with selected dynamic-feeling features. Under some circumstances, values can be converted between types without explicit coercion, and type switching can make code concise while retaining static checking. section 1.3.4 section 1.1

var i int = 2

Go declarations can state a type explicitly, as in `var i int = 2`; shorter forms such as `var i = 2` and `i := 2` retain static typing through inferred types. section 1.1

The design targets large codebases and large developer teams without imposing the complexity associated with some traditional statically typed, compiled languages. Go remains compiled while providing a runtime with garbage collection and a toolchain that supports application development. section 1.1

How Go in Practice, Second Edition covers it

How deep it goes
Defines compile-time-oriented checking and contrasts runtime typing, but stops short of compiler internals or a detailed type-system formalization.
Examples
Illustrates explicit and inferred Go declarations alongside comparisons with Python, PHP, JavaScript, and TypeScript.
What you can do after
Evaluate/understand how Go checks types statically while retaining selected conversion and type-switching conveniences.
How it connects
Connects static typing with dynamic typing, type switching, type conversion, compilation, and garbage collection.

Also explained in

Compare how 12 books explain static typing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Go in Practice, Second Edition. The section links point to the parts of the book it draws on.