codegen/op-codegen/adr/0001-kotlin_dsl_as_source_of_truth.md
ACCEPTED
Discussed by: Paul Dubs, Alex Black, raver119 on 19. October 2019
This code generation experiment is meant to be our starting point for both the API unification for ND4J and SameDiff, and the multi-language support. For this reason we have to define ops, or their interface, in a language neutral way.
The initial idea was to use a Language Workbench like MPS. This had to be discarded because of bugs and limitations encountered while trying to define a language that would work for a few simple examples.
The next idea was to use Ops defined in JSON files. This would have allowed us to define Ops as human readable data and read and write those files from any programming language. However, the drawback with this approach is that writing json manually invites many problems if written manually (e.g. typos, bad structuring, having to look up the proper keys,...). In order to rectify that drawback, we would have to create custom tooling, that we would have to maintain and that contributors would have to use.
Using a Java builder pattern based approach is very verbose.
We use a Kotlin-based DSL to define Ops.
Using a full programming language as the platform to build our DSL has both advantages and drawbacks.