A New Way to Think
If you come from JavaScript, Python, Java, or Go, the biggest adjustment in Mar is not the syntax. It is that a handful of things you do every day, reassigning a variable, mutating an object, returning early, throwing an exception, checking for null, quietly calling the network from anywhere, are simply not in the language.
This part of the book explains what replaces each of them, and why the trade is worth making. The five chapters build on each other:
- Values That Never Change: every value in Mar is immutable. What “change” means when nothing changes, and why this eliminates a whole family of bugs.
- Functions You Can Trust: every function computes its output from its inputs, and nothing else. Where side effects go instead.
- Everything Is an Expression:
ifandcaseproduce values, there are no statements, and why “no early return” turns out to be a gift. - Types Without Ceremony: records, unions,
Maybeinstead ofnull,Resultinstead of exceptions, and a compiler that infers almost everything. - Integers and Decimals: Mar has no floating-point numbers, only exact ones. This sounds radical; it is one of the most practical decisions in the language.
A note on posture. Each of these ideas can be described as taking something away, and defenders of functional programming sometimes make it sound like a moral improvement. This book takes a different line: each restriction is a purchase. You pay with a habit; you receive a guarantee. The chapters try to be concrete about both sides of the transaction.