Question

This question already has an answer here:

In response to my question regarding Java source code generation, I received this answer warning me about potential maintenance problems:

  1. mixing auto-generated code always pose a risk of someone modifying it in future to just to tweak a small behavior. It's just the matter of next build, when this changes will be lost.
  2. you will have to solely rely on the comments on top of auto-generated source to prevent developers from doing so.
  3. version-controlling - Lets say you update the template of someMethod(), now all of your source file's version will be updated, even if the source updates is auto-generated. you will see redundant history.

His proposed alternative is enhancing classes at runtime using bytecode generation.

My thinking was that injecting generated code into existing source code files would enhance maintainability, because it makes it obvious what is going on instead of performing some operations behind the scenes.

Should I:

  1. create a tool to add generated code to existing source code; or

  2. augment the classes using bytecode generation at runtime?

What has been your experience with either of these approaches?

No correct solution

Licensed under: CC-BY-SA with attribution
scroll top