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!
Presumably it would become auto loc = std::source_location::current(); at some point, which seems fair enough to me.
Is the preprocessor still needed in C++? (2017)
21–30 of 65 posts
Re: Is the preprocessor still needed in C++? (2017)
#22How 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!
Presumably it would become auto loc = std::source_location::current(); at some point, which seems fair enough to me.
It's tidier for the compiler though, but the change does not seem to make it easier for the reader of the code to comprehend.
Re: Is the preprocessor still needed in C++? (2017)
#23How 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!
D just uses __LINE__, because it hasn't got a preprocessor so the compiler can resolve the token properly.
The implementation of that is at https://github.com/dlang/dmd/blob/v2.094.2/src/dmd/expressio...
Re: Is the preprocessor still needed in C++? (2017)
#24Earlier quoted context omitted.
Presumably it would become auto loc = std::source_location::current(); at some point, which seems fair enough to me.
It is since C++20. Comment author tries to make code verbose to make their point or does not know about auto and the state of C++.
Fortunately you only need to write this at the utility function, not at every call site, so it's ok.
In general I find various new features in C++ suffer from verbosity, but of course without experimental this one gets better.
Re: Is the preprocessor still needed in C++? (2017)
#25TBH 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…
Re: Is the preprocessor still needed in C++? (2017)
#26TBH 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…
And certainly doesn't help with compile times.
Re: Is the preprocessor still needed in C++? (2017)
#27Re: Is the preprocessor still needed in C++? (2017)
#28We just need an interpreter that can work on C++ files, supported by the standard. Something akin to the https://www.python.org/dev/peps/pep-0638/ Code generators/transformers are rare only because it's so hard to actually start. Too bad https://www.circle-lang.org never took off.
Re: Is the preprocessor still needed in C++? (2017)
#29Java tried so hard to "do the right thing" by abolishing the preprocessor, and we ended up with another preprocessor called IDE, unnecessary code patterns, and (oh my) Maven profiles for conditional compilation (among other things).
Re: Is the preprocessor still needed in C++? (2017)
#30 #if LIBVERSION >= 2
draw_point (2, 3, RED);
#else
set_color (RED);
draw_point (2, 3);
#endif
This is actually a case where the C preprocessor would be useful in many more languages. OCaml has cppo which is like a better cpp and is very useful for solving these sorts of problems. (https://github.com/ocaml-community/cppo)