I also don’t get it.
Why are we converting an AST back and forth to some limited string representation constantly?
This should happen only once on input (as we need to type in the code somehow), and from there the editor should work with the rich data structure that an AST is (likely even augmented by some meta-data).
Problem is of course that we don’t have proper AST editors yet.
We have some kind of hybrid, with a “stringly frontend” which is powered by a backend engine that works with the actual AST. But we don’t even cache the AST in memory afaik. We convert constantly back and forth form strings. That seems indeed ridiculous.
I’m of course not asking to change that right now. This would need some greater move across the whole filed of software development.
But what I’m asking for is some sane and safe method to generate code in Scala.
Having to resort for code gen to raw strings, without any safety, not even against typos, in one of the most powerful languages out there seems just wrong. And yes, people want code gen! But the result should be still maintainable.
I guess there is even some space for research and advancement of the state of the art in this topic. Scala should see this as a chance to become better than other languages on one more axis.
But rankly, at the moment we’re at the technical level of the m4 macro processor, in my opinion.
OK, I’m exaggerating of course: Scala has already very advanced and powerful meta-programming facilities. Only that those don’t allow unrestricted code generation. You can’t even abstract over the creation of similar shaped data structures which differ only by some concrete names. In that case you would have to write some string template, and iterate through some data to fill in the gaps and write out the this way generated code to disk. That’s the most awful and error prone approach possible! Even the C pre-processor hat more safety guards built in…
And it’s not like this is some exotic feature nobody needs. Here, just some random examples what kind of workarounds are currently employed because of this limitation of the mata-programming features: