On 17/06/2014 4:44 p.m., H. S. Teoh via Digitalmars-d wrote:
On Tue, Jun 17, 2014 at 04:16:43PM +1200, Rikki Cattermole via Digitalmars-d
wrote:
On 17/06/2014 3:05 a.m., H. S. Teoh via Digitalmars-d wrote:
[...]
I would personally avoid using string mixins unless there's
absolutely no other way to achieve what you want -- they're a kind of
last-resort nuclear warhead that you don't bring out unless all the
other guns fail to win the battle.
I have a rule about string mixins which I believe to be a good one to
follow:
If using string mixins, don't expose it to client code unless they
explicitly want it.
Basically what this means is, use something to wrap it like a mixin
template but don't just say hey call this function and use it as a
string mixin! Its a little nicer. Also the explicit getting of the
string is important for debugging. Sometimes its needed for the more
complex cases in edge cases/broken functionality. I use it during
development (a simple pragma msg inside the mixin template for
example).
Hmm, you know what would be really nice? If there was a way to get at
the string representation of the fully-expanded form of instantiated
templates as the compiler sees them before handing them off to codegen.
Well, OK, I know that's not how the compiler does it, but still,
something equivalent to this would be very handy for debugging
deeply-nested templates that currently would just spew walls of
incomprehensible errors.
A feature that I would love, is the full code output post CTFE. Which is
kinda what your saying. Would be lovely to see just _exactly_ is going
into the binary and more importantly where!
I would be very happy even if comments weren't even there.
But in saying this, some of this could be handled by opDispatch. Its
just a shame that both approaches currently aren't handled for
auto-completion by any IDE's. I would expect the string mixin would be
one day.
[...]
String mixins? Auto-completion? I dunno, that sounds like a stretch to
me. How would an IDE handle autocompletion for things like like:
string generateCode() {
string code = "int x=";
if (solveFermatsLastTheorem()) {
code ~= "1";
} else {
code ~= "2";
}
code ~= ";";
return code;
}
int func() {
mixin(generateCode());
}
?
I would assume a full frontend would be required for this.
T