DEV Community

Cover image for The book library: Code organization
Ulises Alexander Arguelles Monjaraz
Ulises Alexander Arguelles Monjaraz

Posted on • Originally published at uaam.hashnode.dev

The book library: Code organization

This little post would be about how I had, and I'm planning to organize the code inside my book library. This library is part of the reading management system that I'm working on. But, at the moment, this is where I'm focusing my efforts.

How it is now

Originally, I did'n have a structured way to organize the code of my library. Currently, my code is organized like this:

  1. Type Classes
  2. Type declarations and newtype declarations with their functions next to them.
  3. Sum data type definitions.

Original organization

The base of the new way

Now, I'm planning to implement the following approach, described by Eric Normand :

  • Actions: Anything that depends on when it is run, or how many times it is run, or both [...].
  • Calculations: Computations from input to output. They always give the same output when you give the same input. [...].
  • Data: Recorded facts about events. [...]. [1, p10]

How it would be

How this would look without seeing the actual code:

  • First I would put the data or in this case what is a book. Type classes, type and newtype declarations; type aliases, and data types.
  • Then the calculations in this case and by the moment the functions to wrap and unwrap around my defined types, and other operations that don't need to interact with the outside world.
  • Finally, I would put the actions, right now the only type of functions that I think could go here are time-related functions.

New organization

References

[1] E. Normand, Grokking simplicity: taming complex software with functional thinking. Shelter Island, NY: Manning Publications Company, 2021.

Top comments (0)