This repository was archived by the owner on Dec 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Role of code generation in OSHI 5 #4
Copy link
Copy link
Open
Description
About 5 months ago I wrote a small program with JavaPoet that generates the API according to a set of general definitions.
For example, the following YAML file defines a small Nic component:
- Nic:
- name: The interface's name
type: String
- mtu: The interface's maximum transmission unit
type: Integer
- ipv4: The interface's IPv4 addresses
type: String[]
- luid: The interface's local UID
type: Long
platforms: windows
- guid: The interface's global UID
type: String
platforms: windows
- connected: Whether the interface is connected
type: Boolean
platforms: windows
...
The program produced the API component and the interface for the driver (which I call the Index) along with proper JavaDoc on everything. I'm confident that JavaPoet can generate just about any kind of API we come up with, so the question is whether it's a good fit for the project.
Advantages to generating the API
- Generate hundreds of source files in seconds
- Places the essence of OSHI into a single definition file
- Makes it easier to produce a uniform/consistent API
- Makes it easier and less error-prone to add/change features
- Changes to the API itself can be propagated quickly and error-free
- Allows us to relax on DRY if doing so leads to a better API
- No additional runtime dependencies and integrates well with Maven
Disadvantages to generating the API
- Flexibility to add special cases to the API is lost
- Doing so goes against one of our design goals, but could be permissible once or twice
- This means that the API we come up with must be general enough to suit every feature
- Another piece of code to write and maintain
I'll update this post with any additional concerns.
Metadata
Metadata
Assignees
Labels
No labels