Anti-patterns (WIP)

Last modified on February 2, 2020 by Alex


This is a collection of anti-patterns that I have observed happening out in the wild.

Default parameters and too many binary parameters

Let’s take a look at the following snippet.

Can you describe in a single sentence what this method does? I can’t. Why? Because there are at least four different methods hidden here. Default parameters should be used only if the behavior of the function does not significantly change based on those parameters.

Special values without new types

This is highly problematic because it makes it difficult to track which values require special handling, and which do not. You end up with code like this:

And all hell breaks loose when it turns out that outOfRangeValue is one of possible values for foo as well.

It is much more preferable to either define a new type,

or a newtype with custom constructors and deconstructors.