← Back to context

Comment by mgaunard

3 years ago

the preprocessor is a great tool to reduce duplication and boilerplate.

People that don't like it generally just don't know how to use it.

People don't dislike it because they are unaware how helpful it can be. They dislike it because they are aware how hacky, fragile and error-prone it is. They want something more robust than text substitution.

People that don't like it generally have used macros that are more sophisticated than just blindly copy pasting text into your source files and have became aware of how absurd that is.

Or perhaps those people can think of better ways to get those benefits that also don't allow things like

    #ifndef asdf
    }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
    #endif

which obliterate tooling such as IDEs. Of course, this is a contrived example, but the preprocessor is just one big footgun, which offers no benefits over other ways of solving the problems you mentioned, such as constexpr and perhaps additional, currently unimplemented solutions.

  • It being possible to misuse a tool does not mean the tool is not very useful.

    • A tool being very useful doesn’t mean that it is a very good tool.

      There are better tools for the functionality the C preprocessor attempts to provide. Other languages have module inclusion systems and very powerful macros that don’t have the enormous footguns of the C preprocessor.

      Édit: to be clear, I think #embed is a fine idea; I’d use it and it would make my sourcebase cleaner in some places.

    • My carpenter has a lot of tools that can be dangerous if misused. Of course better tools can be devised, but useful things have been done with them (and he still has all his fingers)

    • Yes, but we’re in a thread about ways to improve the language, not about how to make the best with what’s there. This type of argument holds back improvement.