Skip to content

Improve code quality #3

@mbuffa

Description

@mbuffa

Context

Inconsistent API

Main behavior is somewhat inconsistent:

  @callback get(name :: atom()) :: struct() | nil
  @callback set(struct :: struct()) :: {:ok, struct()}
  @callback delete!(name :: atom()) :: {:ok, any()}
  @callback enabled?(name :: atom()) :: boolean()
  @callback enable(name :: atom()) :: {:ok, struct()}
  @callback disable(name :: atom()) :: {:ok, struct()}
  • get should probably return {:ok, struct()} to match set return values
  • It's quite ok to return just a boolean for enabled?, but we may not need to return anything other than a plain :ok for enable and disable
  • delete! should probably drop its exclamation mark. I don't remember why I added it there and not on set (IIRC, I think I dropped it for set)
    • Yup, looks like delete! escaped the slashing: 19d6f6f
  • Error specs should probably be added

Code quality

I think code quality could be greatly improved, eg. by:

  • Using with when relevant
  • Dropping nested cases
  • Separating behavior with macro definition
  • Making sure errors are correctly checked (|> Type.load() looks sus).

Metadata

Metadata

Assignees

Labels

breaking changeChanges that are expected to break interfacesenhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions