Minimum cut code relocation?

Hey random thought…
I have noticed in our code its easy for code to be written numerous times in different locations when a developer doesnt know/think to look for other implementations and rewrites in situ. The result is often a function where the input or output types strongly reference another module. Type inference often hides this. I wonder then, would it be possible to do an easing pass on code that would move/suggest to move code to a module where it had the least numer of module references in its type signature?

A

2 Likes

Sounds like more of an issue if project organization and less of a problem for a compiler or language server to solve. Do you have any examples that you can share though? I’m curious what provoked this and if there is a pit of success type situation here.

This compiler is a place where our code is parsed and ast traversed, we can do lots of things with that data that can be the role of the compiler. If you have it as a separate tool, youre repeating a lot of the same work. The compiler includes code formatting for example which is the same purpose but lower value even, IMO.

my example:

module X = {
  let y = ....
  let z = ...
}

module Y = {
  // Naturally belongs in X
  let q = (a, b) => X.y(a) + X.z(b)
}
``

Isn’t this also an advantage? I have one philosophy here. Similarity of declaration is different from duplication of implementation, and DRY should only be applied to the latter.

Making some couplings between interface modules just because they have the same payload leads to design problems.