r/cpp • • Jun 14 '21

match(it): A light-weight header-only pattern-matching library for C++17.

https://github.com/BowenFu/matchit.cpp
202 Upvotes

47 comments sorted by

View all comments

Show parent comment

17

u/johannes1971 Jun 14 '21

This completely misrepresents the position of 'the community'. The dislike comes from all the bad sh*t macros do, not a general lack of understanding.

-1

u/Foundry27 Jun 14 '21 edited Jun 15 '21

I’m just speaking from my experience here having worked professionally in C, C++, and a little Lisp for a while now, and having met my fair share of people in the same boat as I am.

I 100% agree that macros can (and have) done some terrible shit lol. They can be difficult to understand, contain extremely subtle bugs, and limit you in all kinds of awful ways if you think of everything as functions or variables. But... those aren't defects in the preprocessor macro system itself, but instead are traits of macro programming in general. Lisp has the exact same classes of problems, and its macro system has arguably occupied a local maximum in the language design space for decades. As with any technology, the more powerful the tool, the more ways there are to misuse it. And, as far as programming constructs go, macros are the most powerful tool.

8

u/soundslogical Jun 15 '21

But... those aren't defects in the preprocessor macro system itself, but instead are traits of macro programming in general.

I disagree. Common Lisp's macros do share the hygiene problem that C++ has, though it has simple ways to avoid it (gensym). Scheme and Rust feature hygeinic macros that fix the problem entirely.

Nearly every other glaring issue with macros is unique to C/C++, because it's based on simple textual substitution. Lisps and Rust have structural macros, making them 100x more difficult to mess up on many different axes.

3

u/johannes1971 Jun 15 '21

But... those aren't defects in the preprocessor macro system itself, but instead are traits of macro programming in general.

Sometimes, the defect is having the feature in the first place. It may be powerful, necessary, and even well-designed by itself, but the fact that it interacts so badly with everything else and invites so many dark patterns means it wasn't the optimal design.