Metaprogramming and DSLs in Java.
Brian Goetz
brian.goetz at oracle.com
Fri Nov 27 22:51:05 UTC 2020
Metaprogramming is a double-edged sword. On the one hand, it lets you
slice through the boilerplate of implementing things with "design
patterns" by moving the patterns out of your program and into the
metaprogram where it is out of view. On the other, there is a
significant risk that it creates a sort of balkanization, where skilled
Java programmers cannot read other people's Java code because the
semantics are locked up in insufficiently-specified (or simply
unfamiliar) macros or transforms.
As a developer, I have used metaprogramming and DSLs in many
environments to great benefit, and in past lives. So I see the
benefit. But there are big red flags waving too. One is that
metaprogramming features tend to appeal more to the writers of code than
the readers -- and one of the core values of Java is "reading code is
more important than writing code." Additionally, having used dozens of
them, I find metaprogramming systems in languages more structurally
complex than Lisp (which is all of them) usually have the effect of
getting you past the current roadblock, but run out of gas not far down
the road.
We like to judge a feature through the lens of "when everyone can
program with this feature, will the resulting code, across the entire
ecosystem, be better or worse?" And, given the candidate ideas I've
seen so far, none of them give high confidence that they will actually
make things better, but instead just move the pain elsewhere. But we
are open-minded, and to the extent high-confidence candidates come
along, we'll consider them.
On 11/23/2020 7:49 AM, Rahul Khandelwal wrote:
> Hello All,
>
> I have been using Java for around 8 years now.
> Recently I switched to Kotlin for projects related to my office work.
> It was the time I encountered DSLs and the concept of Metaprogramming.
> As Java is my primary interest, I explored if we can achieve the same in
> Java as well.
> But I couldn't find any resources which explore DSL/ Metaprogramming with
> Java.
>
> As project Amber is exploring the productivity and usability aspect of
> Java, I wanted to know whether DSL/ Metaprogramming can be achieved in
> Java? If it can't be then in that case is it in roadmap of further
> exploration?
>
> Regards,
> Rahul
More information about the amber-dev
mailing list