Code Generation STILL in Action 1
— The Past —
Jack Herrington wrote a book Code Generation in Action way back in 2003. It took advantage of the little programming language that could, Ruby. I remember having a discussion with a colleague back then about the value of generated code. We were of the opinion then that it would only apply to simple repetitive cases and wouldn’t make much of an impact.
If only I could go back in time and slap both myself and my colleague in the face! We missed out on being early adopters of time saving technology. In fact almost everyone using Java was already taking advantage of code generation whether they realized it or not , Eclipse would generate getters and setters and had its refactoring capabilities, Spring was beginning to handle externalizing dependencies, and the then fledgling Hibernate Framework was manipulating bytecode to enhance Java methods.
At the same time my colleague and I were hammering out code with the tried and true cut-n-rape technique that had been popular since before we were born.
— Modern Day —
I have the “opportunity” to work on porting some old JSPs which, in true 20th century Model 1 style, link directly to each other and the database via scriptlets, to a more modern Java MVC framework. Rather than just wade in blindly, manually translating JSP scriptlet page to Java MVC framework code, I decided to make the project interesting and have been writing a Ruby JSP parser/code generator. It can identify scriptlet code and extract it for me. I have been enhancing the parser to handle generation of Spring MVC code and am working on having it generate Spring Web Flow flows from reading the form action attributes in the JSPs to model application flows.
Old school regex to the rescue: /%<(?![=,@,-]).*?%>/m