I'm serious about this folks! I really want to see the CPP obviated.
People who have never used tools such as JBuilder may not fully appreciate
the advantages they provide. This isn't about pointer safety, or making
sure you aren't blowing the bounds of an array. Imagine you could select a
namespace, enter a command with a new name as an argument, and your IDE
would rename every identifier qualified with that namespace to the new
name. Not only that, but it would fix every reference throughout the code
base so that it referred to the new namespace. The JBuilder creators call
that "refactorin g" (using packages rather than namespaces). It isn't what
I mean by the term "refactor". To me, that is only a minor proceedure
performed as part of refactoring. But that's not what I want to discuss.
I'm just using it as an example of the many different capabilities Java
IDEs have.
I sincerely believe the CPP is the biggest reason C++ IDEs can't do these
kind of things. I'll add the observation that, if it's hard to build a
tool to navigate and manipulate source code, it's probably hard for a
programmer to do the same. Stroustrup's suggested approach to doing away
with the CPP is to find ways to accomplish the things people use the CPP
for as easily in native C++. You guys probably think I ignore everything
you tell me you use the CPP for. Well, that isn't the case. And I use the
CPP directly or indirectly as much, or more than a lot of you do. See for
example: http://doc.trolltech.com/3.3/moc.html#moc
There are three different areas of use that I have been able to identify for
the CPP. 1) #inclusion, 2) conditional compilation 3) stringizing program
elements. Right now I want to talk about the third of these. I just
discovered that it is possible to pass the equivalent of a string literal
to a template like this:
ISO/IEC 14882 §14.3.2
[Note: A string literal (2.13.4) does not satisfy the requirements of any of
these categories and thus is not an
acceptable template-argument. [Example:
template<class T, char* p> class X {
// ...
X();
X(const char* q) { /* ... */ }
};
// error: string literal
as template-argument
X<int,"Studebak er"> x1;
char p[] = "Vivisectionist ";
// OK
X<int,p> x2;
--end example] --end note]
I know this doesn't provide what the macro(#) provides. But it may be a
place to start. Could templates be used for the same kinds of things you
currently used the CPP # parameter for? What would they have to provide?
I'm not looking for the most esoteric example you can invent. I'm asking
about something that would provide 90% coverage.
Here's my first thought. Pass the name of a class to a template, and have
it converted to some kind of inner class with string representations of the
member variables and member functions. That might be useful for stuff like
introspection.
--
"[M]y dislike for the preprocessor is well known. Cpp is essential in C
programming, and still important in conventional C++ implementations , but
it is a hack, and so are most of the techniques that rely on it. ...I think
the time has come to be serious about macro-free C++ programming." - B. S.