Some time ago I made some experiments, CRC cards from Kent Beck and Ward Cunningham made me try to program without public getters and setters. I learned a lot from it, especially about “double dispatching”, and how it is useful but we usually forget about it (shame, shame…).
It shifts your mind from “what should I use” to “how do I use” …
Functional programming made me experiment to program only with immutable objects. That’s a very interesting restriction I advocate anyone to try. Essentially, it teaches me when I can safely use mutability, and I can say it has its place.
Also, learning Racket made me try to program without loops at all. After a while I learned to use recursion and loops very effectively.
The main point here is that constraints make you keep your focus where it matters, stripping useless details and superfluous choices. It shifts your mind from “what should I use” to “how do I use”, a far better question to learn.
There is a legend about Demosthenes, the famous greek orator, about being a better speaker using pebbles in the mouth.
Here is my list of “pebbles” :)
- Immutable classes and collections only, no mutable state anywhere.
- No public getters and setters, no direct access to struct fields outside of module/file/something local.
- No loops, only recursion. Only tail call recursion.
- Paralellism by piping things to different processes, no shared state (immutable or not).
- No classes, just structures.
- No ifs or cases, just pattern matching/multimethods/method overloading/subclasses (goes well with the previous one).
- Everything as a fluent interface/method chaining.