De-anonymized Models

Do you use tuples () and anonymous records { .. } in your Models?

I do, especially if I am hacking out some piece of code in an exploratory way, and I don’t have a solid idea of the exact data model yet. If I designed the data model up front, I do this less. I am finding of late, I like to refactor my more hacky efforts into a less anonymous form. Which led me to think, what is the definition of a fully de-anonymized model in Elm?

Given a model that includes them:

type alias Model = 
   { tuple : (A, B)
   , record : { x : X, y : Y }
   }

(where A, B, X, Y are types not shown above).

There is a transformation to turn this into a model where all of the types and fields are named. Which is, to replace each tuple with a record (with named fields), and to replace each anonymous record type with a reference to a type alias:

type alias Model = 
   { tuple : Tuple
   , record : Record
   }

type alias Tuple = { a : A, b : B }

type alias Record = { x : y, y : Y }

Also note that tagged union types are also implicitly using tuples for their arguments:

type Tagged = Option A1 A2 ... An => -- Is almost equivalent to
    type Tagged = Option (A1, A2, ..., An)

So these constructor arguments also need to be turned into records with a type alias and named fields.

Once a model is in its de-anonymized form every type and field is named.

So my question is, is this better from a self-documenting code perspective, because these names give a clue to someone reading the code what the purpose of each type and field is? On the down-side sometimes it gets hard to think up good names for things.

I also find that I do not generally turn 1-tuples into records where they are arguments of tagged union constructors - the tagged union constructor serves as the name for the parameter in that case.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.