benchee icon indicating copy to clipboard operation
benchee copied to clipboard

Units: Use `use` to simplify implementing units

Open PragTob opened this issue 8 years ago • 1 comments
trafficstars

The unit implementations have a lot of method definitions that an implementation needs to define but that definitely just call out to a more common for code sharing.

For instance:

  def scale(count, unit) do
    Scale.scale count, unit, __MODULE__
  end

if we implemented that functionality inside a __using__ definitions of those functions are unnecessary, leading to more concise unit definitions. A smaller example of this is implemented in #154

genserver does the same - well more or less. Difference is, we don't want the functions to be overridden as far as I can tell.

Downsides of this approach I see so far:

  • magic :star2:
  • I think the documenation of the methods that are defined "commonly" will be the same for all modules. Not really a "big" problem, but that means the iex usage examples/doctests will always contain examples of the other units (or none at all)

I think it should considerably shrink down the effort to implement new units so I think it'd be good. Interested to see what others think ( @wasnotrice since you did the first version here)

Not high priority, as it'd be pure refactoring

PragTob avatar Oct 21 '17 20:10 PragTob

@PragTob I agree this would be nice. It did bother me when writing this that there was so much boilerplate to write in order to add a new unit.

I agree we may lose some doctests, but maybe that means we write different/better ones!

wasnotrice avatar Oct 24 '17 02:10 wasnotrice