General Registry: Create tag for macro usage

In a recent discussion about newbie friendliness, the topic about macros came up.

Someone suggested, that it may be beneficial to prevent auto merges to the general registry, for code that uses them. I think that’s a bit too harsh.

But what about creating a tag, so that we can review the PR, and possibly comment on the overuse of it?

Macros are overused in nearly every language that uses them, and I think this could be a way to deal with this issue.

Eventually might even the compiler be able to give good advice to alternatives.

Like:

You seem to be using a macro for xyz. It seems this could also be done with closures. 
Macros are for rare edge cases, and not to be used lightly, as they can make code hard to read.

I don’t know if the compiler is ready for that, but setting up the registry, seems doable right now.
So people could review code, with that purpose.

2 Likes

Perhaps a VSCode plugin?

12 Likes

I have yet to see that this is an issue with Julia. I don’t think I’ve come across any overuse.

Macros are a bit of a pain to write, but beyond that, they’re a perfectly normal feature of the language. Not that I’m opposed to applying a tag to packages that define macros, but I wouldn’t consider it a stigma at all.

6 Likes

If you’re right, maybe we should do this (but only in the REPL) for all macros? It seems not too hard. I mean if done unconditionally. I’m not sure what you meant by “for xyz”, to analyze the macro for complexity, and only warn when some level exceeded? Then harder and I’m not sure needed.

I only recall trying to locate a function definition, and not finding it. That’s annoying. Or rather I found it but it was a macro and/or eval (I understand you sometimes want that for the convenience of the package maker, but less ideal to read for the user?). I forget the details. E.g. for Genie.jl package.

P.S. Can someone make a macro for that Clippy advice…? And I’m sort of serious, maybe some warnings should be that obvious; and not take up extra lines in the REPL.

1 Like

Might as well be. I know its an issue in other languages, and other people, as in my initial link, said its overused.

I guess depends on where you look at.

It’s not only about convenience. Having to write a large number of similar function definitions is rather error prone. There are certainly tradeoffs with @eval loops but they shine at being consistent.

2 Likes

Let’s consolidate this discussion over at the simultaneous Internals & Design post that’s also about how to handle registry submissions that export macros. This is more of an internals/governance sort of thing than it is New to Julia.

2 Likes