2 ms·
> A function called `{my-domain}_path()` 100% agree. I think it's generally good practice for macros which generate non-hidden functions to surface them as pa
by dnautics 5y ago
> A function called `{my-domain}_path()`
100% agree. I think it's generally good practice for macros which generate non-hidden functions to surface them as parameters for the user to include in their code so you can easily chase where it's coming from (e.g. EEx.function_from*).
On the other hand, at least it's easy to find the source code for any given macro.
If you want a gentler, less magickey introduction to elixir for web, I recommend starting with Plug. The good thing is that Phoenix builds on top of plug so everything you will learn is still applicable to Phoenix. The big danger is that you might be dragged kicking and screaming into Phoenix, as I was (but trust that most of the macros is phoenix are there for a reason and they do save time in most use cases at the expense of having to memorize a whole lot of shortcuts)
- klibertp 5y agoPlug is actually very hard to learn, because its design is very simple, but knowing how to use this design to produce the effect you need requires a whole lot of mental gymnastics. A less generic design would account for, for example, "initialize this state on first time this plug is called" (I think something changed here, but don't remember if for the better) and similar things, but then it would be less generic and possibly not flexible enough to support all the things Phoenix and co. need from it. That being said, Plug is still better than Phoenix, so if you're not in rush to build something and can experiment, then learning Plug first will give you better understanding of Phoenix later on.
- nelsonic 5y agoIf anyone else is stuck learning Plug, the Elixir School tutorial is a good starting point: https://github.com/dwyl/elixir-plug-tutorial https://github.com/dwyl/elixir-plug-tutorial