Live data from Hacker News

Is the preprocessor still needed in C++? (2017)

foonathan.net

11–20 of 65 posts

Re: Is the preprocessor still needed in C++? (2017)

#11

TBH the length that C++ goes to replace every single use of the preprocessor "just because" is close to zealotry. Every single "fix" probably requires more lines of code under the hood than the entire preprocessor and in the end you have added tons of additional features to the language to fix problems that (often) don't need fixing. The preprocessor being a simple text replacement tool is a feature, not a bug, but l…

Template instantiation is a simple text replacement tool and it seems to work just fine.

Re: Is the preprocessor still needed in C++? (2017)

#12

TBH the length that C++ goes to replace every single use of the preprocessor "just because" is close to zealotry. Every single "fix" probably requires more lines of code under the hood than the entire preprocessor and in the end you have added tons of additional features to the language to fix problems that (often) don't need fixing. The preprocessor being a simple text replacement tool is a feature, not a bug, but l…

[deleted]

Re: Is the preprocessor still needed in C++? (2017)

#13

TBH the length that C++ goes to replace every single use of the preprocessor "just because" is close to zealotry. Every single "fix" probably requires more lines of code under the hood than the entire preprocessor and in the end you have added tons of additional features to the language to fix problems that (often) don't need fixing. The preprocessor being a simple text replacement tool is a feature, not a bug, but l…

> TBH the length that C++ goes to replace every single use of the preprocessor "just because" is close to zealotry.

This comment is short-sighted.

Take for example C++'s use of include guards to use translation units instead of modules to just compile a damn file. No one in their right mind would argue in favour of a preprocessor with #include instead of proper modules if they were to develop a new programming language.

Using #define to specify constant values is also absolutely awful.

Re: Is the preprocessor still needed in C++? (2017)

#14

TBH the length that C++ goes to replace every single use of the preprocessor "just because" is close to zealotry. Every single "fix" probably requires more lines of code under the hood than the entire preprocessor and in the end you have added tons of additional features to the language to fix problems that (often) don't need fixing. The preprocessor being a simple text replacement tool is a feature, not a bug, but l…

The preprocessor is a big roadblock for C++ modules

Re: Is the preprocessor still needed in C++? (2017)

#15
post #2

How can we replace nested comments? You can't comment out code that contains /* */ in it except with #if 0 Also, why is std::experimental::source_location loc = std::experimental::source_location::current(); loc.line better than __LINE__? what an unreadable monster that is!

> How can we replace nested comments? you may use multiline string literals

Care to elaborate on how that's supposed work in practice?

Re: Is the preprocessor still needed in C++? (2017)

#16

TBH the length that C++ goes to replace every single use of the preprocessor "just because" is close to zealotry. Every single "fix" probably requires more lines of code under the hood than the entire preprocessor and in the end you have added tons of additional features to the language to fix problems that (often) don't need fixing. The preprocessor being a simple text replacement tool is a feature, not a bug, but l…

Template instantiation is a simple text replacement tool and it seems to work just fine.

Is that why templates have such user friendly error messages?

Re: Is the preprocessor still needed in C++? (2017)

#17

TBH the length that C++ goes to replace every single use of the preprocessor "just because" is close to zealotry. Every single "fix" probably requires more lines of code under the hood than the entire preprocessor and in the end you have added tons of additional features to the language to fix problems that (often) don't need fixing. The preprocessor being a simple text replacement tool is a feature, not a bug, but l…

Template instantiation is a simple text replacement tool and it seems to work just fine.

I'm afraid it is not :) Template instantiation has way more rules than simple text replacement. Implicit instantiation is a story on its own, not counting that every compiler is free to implement own instantiation logic.

Someone said once that the truly portable thing between C++ compilers is only preprocessor :)

Re: Is the preprocessor still needed in C++? (2017)

#19

TBH the length that C++ goes to replace every single use of the preprocessor "just because" is close to zealotry. Every single "fix" probably requires more lines of code under the hood than the entire preprocessor and in the end you have added tons of additional features to the language to fix problems that (often) don't need fixing. The preprocessor being a simple text replacement tool is a feature, not a bug, but l…

Template instantiation is a simple text replacement tool and it seems to work just fine.

https://github.com/dlang/dmd/blob/master/src/dmd/dtemplate.d

That must be why the implementation of D's templates, which are designed to be easier to implement than C++'s is at least 8337 lines?

edit: Clang's clocks in at about 11k lines (.cpp alone), I'm too scared to find out for GCC.

Re: Is the preprocessor still needed in C++? (2017)

#20

TBH the length that C++ goes to replace every single use of the preprocessor "just because" is close to zealotry. Every single "fix" probably requires more lines of code under the hood than the entire preprocessor and in the end you have added tons of additional features to the language to fix problems that (often) don't need fixing. The preprocessor being a simple text replacement tool is a feature, not a bug, but l…

Template instantiation is a simple text replacement tool and it seems to work just fine.

Because of compile-time evaluation and/or template pattern matching, C++ template instantiation is Turing complete. So it's basically as far away from "simple text replacement tool" as you could possibly be.
Post reply on HN