Re:Writing code that writes code – Hack Codegen
by nmrm2 on Thursday August 20, 2015 @11:51PM
(#10095890)
> but I think it beats trying to reinvent the entire world of tooling that programmers use all day: grep, text editors, IDEs, etc.
Exactly, but only because we don't have a any really good solutions to building tooling that supports meta-programming for typed languages.
> the window into the program that we have while editing doesn't see any of the results of that metaprogramming
I wonder if there's a way to build IDEs that provide support for metaprogramming.
(Also, this was a really excellent comment.)
But what about class definitions? What if you want to add twenty methods to a class? Fans of dynamic languages will rightly say that class definitions, functions, etc. should also be in the domain of what your code can affect. Smalltalkers and Rubyists will happily write imperative code to build and modify classes.
This is really powerful. It's exciting stuff.
At the same time, for better or worse, most programmers are not spending their day in a live editing environment. They aren't in a Smalltalk browser all day. They're in an IDE or text editor.
That means the window into the program that we have while editing doesn't see any of the results of that metaprogramming. All of the static analysis tools, auto-completers, go-to-definition-ers, etc. can't handle dynamic metaprogramming because they run before any of that metaprogramming is invoked.
Code generation is a way out of that problem. It lets you do imperative dynamic metaprogramming, but then bakes the result back out to the file system where the rest of your tool ecosystem can see it.
It's not the most elegant solution in the world, but I think it beats trying to reinvent the entire world of tooling that programmers use all day: grep, text editors, IDEs, etc.