dwyl / phoenix-ecto-append-only-log-example

📝 A step-by-step example/tutorial showing how to build a Phoenix (Elixir) App where all data is immutable (append only). Precursor to Blockchain, IPFS or Solid!
GNU General Public License v2.0
78 stars 7 forks source link

Do we need behaviours? #16

Open SimonLab opened 5 years ago

SimonLab commented 5 years ago

The example is using behaviours to define the structure of the API interface: https://github.com/dwyl/phoenix-ecto-append-only-log-example/blob/e8eee00fab8f1555ab93c2d2757c497207d81873/lib/append/append_only_log.ex#L9-L14

The implementation of the API is then done in the before_compile macro: https://github.com/dwyl/phoenix-ecto-append-only-log-example/blob/e8eee00fab8f1555ab93c2d2757c497207d81873/lib/append/append_only_log.ex#L25-L48 ... However I'm not sure behaviours are needed for the append only example. From my understanding it makes sense to use behaviours when multiple modules need to provide the same functions but with a different logic of implemention. In our example only the AppendOnlyLog module is implementing the behaviours.

For a learning purpose it makes sense to see how behaviours works :+1: but I'm not sure if they provide a lot of values for this repository?

Should we still keep them to demonstrate how they can be used?

ref: https://elixir-lang.org/getting-started/typespecs-and-behaviours.html#behaviours

nelsonic commented 5 years ago

Related to: https://github.com/dwyl/phoenix-ecto-append-only-log-example/issues/8