Skip to content

Add transitive dependencies section to Meta-programming anti-pattern #13766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

Gladear
Copy link
Contributor

@Gladear Gladear commented Aug 8, 2024

As discussed in #13762 (comment), I added a "transitive dependencies" section to "Meta-programming anti-patterns".
I obviously open to feedback, whether typos or more general remarks about the content of the section. I've tried to keep it simple whilst exposing the problem, linking to mix xref when complexity arises.

This also fixes the documentation of mix xref a bit, since it only stated "runtime dependencies" can cause compile-connected ones, whilst all dependencies are affected.

for example, will also create a compile dependency. Some external libraries may also
create compile dependencies by using macros.
[`mix xref`](https://hexdocs.pm/mix/main/Mix.Tasks.Xref.html#module-a-brief-introduction-to-xref)
can be useful to identify these dependencies and refactor the code to remove them.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @Gladear! I am wondering if this is the best place to have this guide. The issue here are not strictly related to meta-programming. After all, simply using Foo.bar() in the body of a module will be enough to trigger this issue. I wonder if it fits either in Code or Design ones. It feels a bit higher level to be in Design, but it is not strictly about Design either.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just pushed an anti-pattern on compile-time dependencies, which I think is the most appropriate for this guide, inspired by the conversation started here: https://github.com/elixir-lang/elixir/blob/main/lib/elixir/pages/anti-patterns/macro-anti-patterns.md#compile-time-dependencies

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wondered that too when writing the guide. It actually does feel like an antipattern, more like a warning when using macros. I wondered if this could be added to the meta-programming guide, maybe after Write macros responsibly ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my mind, the core of the issue is that this warning is for application developers first, not library developers. It is hard to think of the best place to put it at right now, besides mix xref. :(

Copy link
Contributor Author

@Gladear Gladear Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, OK, I get what you're saying.

I'm looking at the Mix & OTP section of the documentation. What about linking it indirectly?

  1. adding a reference to mix compile.elixir in "Introduction to Mix" > "Project compilation" - on a "to go further" kind of link,
  2. adding a link to mix xref there - there's already a small paragraph about dependencies between files,
  3. adding an antipattern section to mix ref?

I think it has the advantage of being simple to find. People will search for "compilation" in the Elixir documentation if they're interested in the topic, and they'll find "Project compilation" under "Introduction to Mix". Then they can expand on the topic easily.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So to be clear, you want to add more links to the existing mix xref docs, right? Would you like to send a PR for those? Also, do you think some of what you wrote could be added to mix xref?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, that's the idea : add links to mix xref and document this issue in there.
I'll create a new PR for the links and update this one to move this section I wrote in mix xref when I get access to my computer again, starting Monday 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! I'm sorry, I completely forgot about this PR 😅 I updated it to add the links I talked about earlier.

@Gladear Gladear force-pushed the add-xref-to-meta-programming-anti-patterns branch from 7a1ebc5 to 38606ba Compare October 25, 2024 13:41
@josevalim josevalim merged commit c2a0f53 into elixir-lang:main Oct 30, 2024
4 of 9 checks passed
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants