Hacker News new | ask | show | jobs
by timidger 2095 days ago
Clippy catches a lot and I can't imagine coding without rustfmt.

But there's more to style guides than formatting and Clippy lints. Some designs will pass Clippy (or worse, lead to Clippy warnings far past the point where a redesign is economical) but be inefficient, inflexible, or have a poor effect on compile speeds.

One major problem I experienced in my last job (where I worked on production rust) was the insane amount of macros and proc macros used. This was an originally C++ heavy shop so they leaned on it more than, say, a python shop moving to rust would.

This led to terrible compilation times and confusing code only certain engineers could maintain (I'm guilty here - I've since left and I know of one proc macro I wrote that will cause headaches to anyone who uses it).

We need an opinionated style guide. The language is so complex we probably need multiple, with different trade offs.

3 comments

> One major problem I experienced in my last job (where I worked on production rust) was the insane amount of macros and proc macros used.

Is there any language that allows full-fledged macros that doesn't have projects that descend into this?

This seems like a standard problem with programmers deciding 1) they don't like the language semantics and use macros to adjust that (then why are you using the language) or 2) over-factoring before you really have enough reuse.

I'm not convinced totally that's the case, but I'm definitely more open to that idea after that job. I've stopped using macros in my side projects and I avoid projects that use them now.
I'm not sure that style guides are the right way to tackle such arising problems. That sounds more like completely separate problems that are each best explained in longer blog posts and learned by the engineers over time.

Most of the popular style guides from big companies I know from other languages are much more one a trivial level where each of the bullet points can be quickly explained and generally isn't more complex than a clippy lint (which is why I mentioned that).

I imagine the advent of more functionality being available in `const fn` would probably reduce a lot of the `macro_rules!` and proc macro use - at least it has for my projects.

Definitely would like to see a more in-depth guide to patterns for structuring large code bases. I've finally dialed things in pretty well in my own head, but it took quite a while to get there, with a lot of lessons learned the hard way.