Stephen Horne wrote:
..
C++ TMP is the greatest thing since sliced bread. In-language
metaprogramming is at least very convenient, and can drastically
increase productivity.
True, but as I said, it still takes a different approach than run-time
code, implying a different skill-set. There are C++ programmers and
C++ TMP programmers, and those sets are very far from being
equivalent.
Also, the error handling is problematic. Get one tiny detail wrong and
you're deciphering bizarre error messages for days.
I have yet to see a stand-alone C++ code
generator that produces anything human-readable, much less maintainable.
I agree, in general. However...
First, when I write my own code generators, I make a point of ensuring
that the generated code is readable. I do this for my own benefit -
otherwise, how can I have any confidence that the generated code is
correct. I don't even see why other code generator writers find this
so hard.
If you'd like to put me to the test on this, I'm quite happy to let
you try (but not disclose) one code generator and its documentation.
It started out as basically a treecc replacement. Only supports C++,
and only runs on Win32 I'm afraid - at least until I get the rest of
my unexpected porting issues covered. Not much in the way of examples
because I'm the only user and I use it for non-trivial apps, but the
docs are OK-ish because I'm pretty forgetful at times.
Some of the generated code is aweful, but in terms of design rather
than readability. For example, I there's and iterator class generator
that generates each class separately - I should be using a data driven
system with thin wrappers around a shared implementation (though
that's naughty because I'll need offsetof with potentially non-POD
classes - sigh - oh well, maybe member pointers might work in this
case), but the current version is really just testing a principle.
A lot of the generated code would also upset idealists, but e.g. the
use of gotos was the most readable way to implement the stepping
through a decision digraph whatever peoples opinions of goto may be.
As for maintainability, that's besides the point - it's like
criticizing a compiler because the object files aren't maintainable.
You're *supposed* to maintain the DSL source files, and the whole
point is to avoid equally unmaintainable manually-written source code.
Are you really going to manually code an LALR state model just because
yaccs output isn't maintainable, even though yaccs input files clearly
are?
The popular compilers may not have been "up to doing the job" ten years
ago, they are now.
I didn't say the compilers - I said the language, as in the *current*
standard. Coping with correct code is one thing - being robust WRT
applications usage of libraries and giving good error messages is
something else.
The extreme differences between compile-time and
run-time syntax you mentioned can be annoying, but (1) the new standard
greatly improves the situation with the decltype, constexpr, and auto
keywords, and (2) syntax that makes it obvious which code runs at
compile-time isn't necessarily evil.
It's not so much the syntax difference as the paradigm difference that
bothers me.
Even so, that's good - and if I understand the 'auto' keyword right,
I'd say that type inference in particular is very welcome.
But have these features been seriously tested by a wide audience as
compiler extensions in the real world? Or are they *genuinely* known
to be the right approach in C++ even without such testing? Or are they
untested creative ideas that people are prematurely committing to,
that may end up being the next standards disaster plot?