3 ms·
I think the motivation is pretty clear here: * It was not typed, and with the advent of Hack, we wanted to have types. * The actual setter method was n
by munificent 11y ago
I think the motivation is pretty clear here:
* It was not typed, and with the advent of Hack, we wanted to have types.
* The actual setter method was not defined. If you searched the codebase,
you wouldn't find it. If you looked at the class, you couldn't see which
methods you could call, which made it harder to discover other calls,
such as ifNotNullSetName.
* IDEs can't autocomplete the code.
What this boils down to is metaprogramming. If you want to create an array that contains twenty items, you aren't going to do:
array.add(1);
array.add(2);
array.add(3);
...
You'll use a loop, some imperative code. That's because data structures like arrays are within the domain of things you can touch with code.
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.
- nmrm2 11y ago> 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.)