The interface of a function, method or procedure, is composed of a number of inputs and output channels, and it is important to choose the correct type of channel to guarantee the function’s contract is being met by callers. input channels can be roughly classified as follows: A set of values it explicitly receives through […]
If you have programmed in Scala you are no doubt familiar with case classes (also known as value classes) and pattern matching, especially in the case of sealed classes (which is said for a class whose subclasses are all known). Pattern matching allows writing code like this: /** A List is either empty or an […]
While this point is not strictly speaking related to zen-level (as it is not about preventing programming errors) it remains a useful tool in the software designer’s toolbox: Unchecked typed exceptions found in Java and many other languages can be used as a very powerful break statement. Common wisdom says that using exceptions for control […]
The DRY Principle says you Don’t Repeat Yourself when writing code. Encoding the same knowledge in two distinct locations means that if the information changes, we need to update both of them. Failing to apply this principle leads to what is humorously called WET code. (“Write Everything Twice” or “We Enjoy Typing”, according to Wikipedia […]
Layers Shearing layers is a principle originally expressed for buildings: things that change at a different pace should be kept separate. Service like electrical wiring needs to be changed more often than the load-bearing structure, and load-bearing structure is expensive to change. If wiring is nested in the structure in such a way that changing […]
The Problem Requiring a method to perform a certain kind of action at most once (or exactly once) is a need I encounter practically on a daily basis.
I was reading articles about software today while my code was compiling and stumbled on this article by Joel Spolsky: Making Wrong Code Look Wrong. Quote: This is the real art: making robust code by literally inventing conventions that make errors stand out on the screen. … also known as reaching for Level Three.
Can we derive a systematic procedure for finding high quality solutions to design problems? I have so far given specific solutions to specific problems for illustration purposes but this website is not meant to be a recipe book; my goal is to give you the means of finding your own solutions to the problems you […]
The other day I was researching implementations of the Event Bus pattern and decided to have a look at the Guava event bus. The page linked above is in Questions-and-Answers format, and includes the following questions:
The last post showed how a fluent interface can be used to construct structured data. If data is seen as a tree, it can be described entirely in depth first fashion, some method calls descending in a branch, and some others going back to the parent node. When reading the code, however, it may become […]