Skip to content

Levels of Code Generation

Levels of Code Generation

There are several layers in Software Development where Code Generation happens. On every place – it has different purposes and accomplishes different goals.

Speed of bootstrapping a new project

If a software developer is able to present something minimally functional to a business owner or client, he will be able to enter the feedback loop that is essential for the usefulness of a software product or service in the long run. He will verify that the requirements match the programmed result.

Minimize hand written Code

Many platforms and tools offer code generation of layers of functionality that is not truly useful logic by itself. Such models could be

  • CRUD operations,
  • information transformation between data formats,
  • gluing code that connects models, data access, and layers – together.

I’ve done many of those myself with my Database Application Generator with Code in Java, PHP, Android (with the Android Architecture Components (from 2018), Flutter, Vaadin Framework and others.

I’ve seen also several plugins & CLIs in this area;

Runtime Code Generation / Execution

You implement Aspect Oriented Programming with Spring Framework by wrapping up additional code on the annotated classes. This was the way it is implemented or at least it was implemented when I scratched with it . The Spring AOP – adds – before and after an execution – the code that is configured to be an aspect (in AOP terms) at runtime.

Speed of execution of Generated Code.

There is certainly – many times – an overhead when a platform is Generating Code at runtime or compile time. It tries to follow higher level programming goals and objectives and minimize manually written logic. The output code – in general – offers to the programmer:

  • business logic correctness,
  • preprogrammed /configured/ workflow, etc.
  • Shift the focus to business logic – visible to the user/client

But, If you want speed execution, code your Code in compiled language. This is of course – if you strive for speed on single machine. There are services that are easily scaled up – by booting up multiple (virtual) machines. This way the Backends are able to handle a lot more requests than a single machine with an optimal software. DO you code for hardware architecture or for second or third level Virtual Machine? The choice is tough one.

Interpreted languages

Interpreted languages also offer hidden Code Generation or execution of  code that is not strictly type.

  • Duck typing – in Object Oriented Languages – it is implemented with Interfaces that have common functionality.

Spring Repository API

Spring Repository API offers runtime mapping to what the programmer was trying to accomplish in the Data Access Layer. The name of the methods in the Interfaces are able to be translated to SQL queries. I’ve seen similar stuff for Android Room Library.

 

And here is another aspect to look up to the Code Generation.

Instantaneous/Code writing phase

A lot of the tools offer Code Generation once. There is a benefit to this that – you could change and tune it up – according to the needs. Many IDE Plugins do that, a lot of Command Line Interfaces and also – external visual tools like the one I’ve coded.

Postpone to Compile Time

When you use modern IDEs, Languages and tools – many of the code generation is postponed to the moment – before packaging an executable file. This is the way it is implemented in Android (especially with Kotlin), Flutter, Vaadin Framework in the newest versions, many of the NodeJS packages, TypeScript and so on.

No-code platforms

The ultimate Code generation in my opinion are the no code platforms. I also – do think that – they do generate a lot of junk Code. Their functionality is very often – predetermined to the extent of the extensibility embedded in the platform. Some tools may offer plugging in together stuff – on very low level. But this minimizes the user basis.

The key here are the Business Needs & the level of experience you need. If a platform accomplishes to get the job done – without code – many times by labeling stuff beyond the concepts of programming – it could become successful. This is how WordPress is so big.

My Attempts

I’ve implemented myself several options:

Unfortunately – Both tools are technical in the sense that – the client must know what he/she wants in such detail that – to define the fields properly. In the same time – it is not successful among other developers, because every company & every developer is in love with their own tools and code. I am no exception. I do accept that my code is far from perfect, but this is for several reasons – my team (me) & my focus on how and what to build. I’ve realized that – especially in marketing terms – how you describe a product – is more important than – how complex it is and what technology it contains…

Leave a Reply

Your email address will not be published.