# What code generation tools are recommended?

**URL:** <https://discuss.kotlinlang.org/t/what-code-generation-tools-are-recommended/8351>\
**Category:** Support\
**Created:** [June 30, 2018, 1:15pm UTC](https://discuss.kotlinlang.org/t/what-code-generation-tools-are-recommended/8351 "2018-06-30T13:15:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![determinant](https://avatars.discourse-cdn.com/v4/letter/d/bbce88/32.png) [@determinant](https://discuss.kotlinlang.org/u/determinant)\
**Post date:** [June 30, 2018, 1:15pm UTC](https://discuss.kotlinlang.org/t/what-code-generation-tools-are-recommended/8351/1 "2018-06-30T13:15:33Z")

</div>

I’m looking to generate classes once and immediately use them many times for executing custom scripts. These are the options that I found:

- [https://asm.ow2.io/](https://asm.ow2.io/)
- [http://bytebuddy.net](http://bytebuddy.net)
- [GitHub - square/javapoet: A Java API for generating .java source files.](https://github.com/square/javapoet)
- [GitHub - square/kotlinpoet: A Kotlin API for generating .kt source files.](https://github.com/square/kotlinpoet)

Does anyone have any feedback on these options or any other options that I’m not aware of? I would appreciate any suggestions regarding an ideal approach.

**Use-Case:**  
I’m creating a Kotlin back-end application which allows the user to type custom scripts for automation and custom computation. I defined my own beginner-friendly scripting language which also exposes an API for interacting with the application.

My parser creates an object representation of a script and then calls an execute method to run it. I’m running into performance issues with these scripts as they’re run millions of times.

---

<div class="post-metadata">

**Author:** ![mibac138](https://avatars.discourse-cdn.com/v4/letter/m/b9bd4f/32.png) [@mibac138](https://discuss.kotlinlang.org/u/mibac138)\
**Post date:** [June 30, 2018, 5:17pm UTC](https://discuss.kotlinlang.org/t/what-code-generation-tools-are-recommended/8351/2 "2018-06-30T17:17:20Z")

</div>

asm and ByteBuddy (which is built on top of asm) generate classes during run time. JavaPoet as well as KotlinPoet on the other hand generate classes during compile time.

This means that using Poet’s you must know exactly what you want to generate before running your program. Though using asm and ByteBuddy you generate stuff during run time, which means you can pass some data, such as user input during class generation. This gives you more flexibility but requires some resources during your program runtime. Also, ByteBuddy is a higher-level API than asm.

Regarding your use case, as far as I understand it you’ve basically created an interpreter for your scripting language. Given that, you’ll probably want to use asm or ByteBuddy to compile those scripts to Java bytecode.

---

<div class="post-metadata">

**Author:** ![determinant](https://avatars.discourse-cdn.com/v4/letter/d/bbce88/32.png) [@determinant](https://discuss.kotlinlang.org/u/determinant)\
**Post date:** [July 1, 2018, 9:51pm UTC](https://discuss.kotlinlang.org/t/what-code-generation-tools-are-recommended/8351/3 "2018-07-01T21:51:54Z")

</div>

@mibac138 Thanks for helping narrow it down. I’ll start researching asm & bytebuddy. Perhaps I’ll get lucky and find a nice Kotlin DSL for these.
