It's possible I don't understand the proposal and I'm probably going to get egg on my face and but I'm not sure I really want this. If I wanted Objective C or C# or Java or Python I'd use Objective C or C# or Java or Python.
I actually like the preprocessor. I like that I can write code like this
#ifdef DEBUG
#define DEBUG_BLOCK(code) code
#else
#define DEBUG_BLOCK(code)
#endif
void SomeFunction(int a, float b) {
DEBUG_BLOCK({
LOG_IF_ENABLED("Called SomeFunction(%d, %f)\n", a, b);
});
... do whatever it was SomeFunction does ..
}
In other languages that I'm used to there's no way to selectively compile stuff in/out.
I like that I can change the behavior of a file for a single include unit
-- foo.cc --
#include "mylib.h"
-- bar.cc --
#include "mylib.h"
-- baz.cc --
#define MYLIB_ENABLED_EXPENSIVE_DEBUGGING_STUFF 1
#include "mylib.h"
because enabling it globally would run too slow
I like that I can code generate
// --command.h--
#define COMMAND_LIST \
COMMAND_OP(Stand) \
COMMAND_OP(Walk) \
COMMAND_OP(Run) \
COMMAND_OP(Hide) \
COMMAND_OP(Jump) \
// make enum for commands
#define COMMAND_OP(id) k##id,
enum CommandId {
COMMAND_LIST
kLastCommandId,
};
#undef COMMAND_OP
// --command.cc--
// Make command strings
#define COMMAND_OP(id) #id
const char* GetCommandString(CommandId id) {
static const char* command_names[] = {
#define COMMAND_OP(id) #id,
COMMAND_LIST
#undef COMMAND_OP
};
return command_names[id];
}
// make a jump table for the commands
typedef bool (*CommandFunc)(Context*);
bool FunctionDispatch(CommandID id, Context* ctx) {
static CommandFunc s_command_table[] = {
#define COMMAND_OP(id) id##Proc,
COMMAND_LIST,
#undef COMMAND_OP
}
return s_command_table[id](ctx);
};
Or this
class Thing {
public:
void DoSomething();
private:
#ifdef USE_SLOW_LEGACY_FEATURE
// needs access to Thing's internals.
void EmulateOldSlowLegacyFeature();
#endif
};
Yes, I can try to hide the implementation but again, the reason I'm using C++ is because I want the optimal code. Not a double indirected pimpl. If I wanted the indirection I'd be using another language.
I love C/C++ and it's quirks. I use it's quirks to make my life easier in ways other some other languages don't. Modules seems like is ignoring some of what makes C/C++ unique and trying to turn it into Java/C#
People saying the preprocessor has issues are ignoring the benefits. I miss the preprocessor in languages that don't have one because I miss those benefits.
You could say, "well, just don't use this feature then" but I can easily see once a project goes down this path, all those benefits of the preprocessor will be lost. You can't easily switch your code between module and include, especially if it's a large project like WebKit, Chrome, Linux, etc.
Leave my C++ alone! Get off my lawn!