Hacker News new | past | comments | ask | show | jobs | submit login

I believe you are correct. I could probably remove the imports altogether, and just prefix those functions with `Phoenix.LiveView`.



+1 for removing imports!

Not that importing is useless but single-use imports drive me a bit nuts. Even just using it a few times. It's nice to be able to jump to some code and know exactly where everything is coming from without having to jump around the file.


Knowing the origin of the function is a huge benefit, but also imports create compile time dependency. In this case, it's not an issue, but when you're importing a lot of things across your codebase, it can become an issue.


I'll take compile-time dependency over unchecked run-time dependency (almost) every time!


Ya, if you design relationships as a DAG then those sorts of compile time dependencies don't matter. Of course sometimes it can't be avoided (Phoenix router, ecto relationships) the router isn't updated very often and schemas don't have too far a reach (at least they don't if you keep them in their contexts).

I don't avoid import but I generally I strive to import one module where I'm going to be using many functions. I rarely bother with `only` unless it's absolutely necessary due to conflicts otherwise specifying `only` is a good indication I don't even need to import.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: