So, there is a monolithic back end application I and some friends are working on. It has a module Types
with 116 data
definitions (and counting) that everything else depends upon. A smallest change, like say adding a Show
instance, entails recompilation that takes several minutes, with all the generic instance FromJSON
definitions and such.
I am starting to question if this is a best practice.
In my recent additions to the code base, I prefer to write the data
definitions at the same module where I need them so that they do not burden the compilation process. However, this is also not optimal: often a client module only needs the types, not the logic, and it is comfortable to import all the types at once.
So, if we decide to always keep types separate from logic, then there are several ways to organize the types:
-
A single module
Types
that everything else depends upon.Graphically.
Types ← Logicᵢ
-
To every module
Logicᵢ
, a moduleLogicᵢ.Types
.Graphically,
Logicᵢ.Types ← Logic
. -
Split the module
Types
intoTypes.Logic₁
,Types.Logic₂
, then import everything intoTypes
.Graphically,
Types.Logicᵢ ← Types
andTypes ← Logicᵢ
. -
More radically, have
Types
split a module for each type, likeTypes.Type₁
,Types.Type₂
and so on.
Another consideration is that, in the future, we might start to generate some types from the data base schema and the HTTP API specification automatically, and some combination of approaches 3 and 4 seems to be the easiest to automate.
What is the advisable way forward?