|
|
|
|
|
by The_rationalist
2091 days ago
|
|
Kotlin has this amazing concept called compiler plugins where you can extend, intercept and alter the compiler at any stage of the compilation pipeline (ast, psi, ir) through an API. There even are frameworks that make writing such plugins easier such as
https://github.com/arrow-kt/arrow-meta
(which enable to bring union type, higher kinded types, pattern matching, etc)
Or https://github.com/google/ksp |
|
Manifold[2] is basically a javac plugin if I'm not mistaken, and it shows just how powerful stuff can be accomplished with this approach (including e.g. auto-generation of Java types from common modelling languages like GraphQL, JSON, YAML etc. adds extension methods, unit expressions, ranges, C++-like preprocessors, structural subtyping, even crazy stuff like type-safe reflection - like Ceylon used to have!).
For Groovy, besides the built-in AST annotations like `@Immutable` and `@Canonical` (which turns a class into a data class, basically), you can achieve stuff like the Spock Testing Framework[3] which changes the Groovy syntax a little bit to make it really awesome for testing.
[0] https://www.baeldung.com/java-build-compiler-plugin
[1] https://groovy-lang.org/metaprogramming.html
[2] http://manifold.systems/
[3] https://spockframework.org/spock/docs/1.0/spock_primer.html