Hacker News new | ask | show | jobs
by sodapopcan 1041 days ago
The point about code generation into the project is unfair. The only library I'm aware of that does this is phx_gen_auth, everything I've used works exactly as described. phx_gen_auth takes this approach due to José's experience working on Devise for Rails, which mirror's mine as a user. I overrode almost everything in Devise, often in very messy ways. While the difficult-to-upgrade argument is a sound one, once you've over-written a massive chunk of a library anyway, upgrading is no easier.

Otherwise, great article about Phoenix!

2 comments

(Author here). Yeah, it may be unfair. phx_gen_auth is definitely one of the main ones that I encountered and struggled with (compared to, eg, django-allauth or django-social-auth). Even just the basic approach to working with Phoenix seems to be much heavier on using code gen (`mix phx.gen.`, `mix phx.new.`, etc) than Django. Maybe that's my newness and the books and documentation I encountered, but it seems like a lot more of the code in a Phoenix project ends up being code that was originally generated compared to an equivalent Django project). Even from the very beginning, there's a lot of code generated when you do `mix phx.new`. Eg, this exists for a reason: https://www.phoenixdiff.org/
Ya, it's fair, it's a common complaint! Though the size of the generated files is nothing compared to Rails :D

You're right that phx_new does count too. It's a bit misunderstood that Phoenix is actually closer to a micro-framework like Flask than it is a full-fledged solution like Django or Rails. What takes it up to their level is `mix phx.new`, so your argument is more on point than I initially thought. The LiveView issue tracker even provides a single-file version of a Phoenix app to re-create your issue in [0]. As you can see, it's not as simple as something like Flask, but not as complex as the generator does.

Again, great article and happy to have you aboard ;)

Also, if you want an auth solution without code generation, there is Pow [1]

[0] https://github.com/wojtekmach/mix_install_examples/blob/main...

[1] https://github.com/pow-auth/pow

You forgot

ecto.gen.migration!

You’re right! I still haven’t read up on how Django does it, but I’m assuming it must make a migration file? Obviously I shouldn’t assume but how else would you add things like indexes and whatnot?
All right, I've read! I'm sort of referencing two different threads I'm involved in here but from the Django docs:

> Your models will be scanned and compared to the versions currently contained in your migration files, and then a new set of migrations will be written out. Make sure to read the output to see what makemigrations thinks you have changed - it’s not perfect, and for complex changes it might not be detecting what you expect.

So it's not different other than it can scan the changes in models to help create the migration which is a nice little convenience.