Telosys: A Code Generation Tool
Developers who are often stuck writing the same code repeatedly will be grateful for this code generation tool by Laurent Guerin.
Join the DZone community and get the full member experience.Join For Free
In this article, we are going to examine Telosys, a code generation tool. We will do that by talking with its author, Laurent Guerin. This will give us the possibility to learn also about his views on code generation and what its users have accomplished by using Telosys.
Why Are Code Generation Tools Relevant?
Code generation is the simplest and most used technique in model-driven development. We use a source of information, a form of model, and we combine it with some template to obtain a generated artifact, for example, code.
Personally, I consider code generation as a useful entry-level step into more advanced techniques. Because of this, I think that it is very important to create simple code generation platforms that lower the entry barriers for new users.
As a community, we want to move as many developers as possible from writing repetitive code to looking for smarter solutions. If we make code generators accessible and effective we will "save" many developers and bring them on the model-driven development and language engineering side.
So usable and well-rounded code generators like Telosys are extremely valuable to the language engineering community.
This is why I think it can be very interesting to chat with Laurent. He, as the author of Telosys, is in a great position to explain to us what problems people try to solve using code generation and what is relevant to them.
The Big Picture
Could you tell us a bit about yourself?
I'm a senior consultant with 30 years of experience in software development and architecture. I've worked in different IT services companies like Steria, T-Systems, [and] Sogeti Consulting. In my career, I have held different positions: developer, project manager, software architect, expert, innovation leader, [and] consultant. I'm passionate about software engineering, DevOps, software craftsmanship, and code generation. I'm also a part-time teacher at Nantes University.
We got in touch to talk about Telosys, your code generation system. Could you describe the project to our readers?
Telosys is a "lightweight code generator," I mean a "pragmatic tool." I created this code generator to provide developers a simple and easy-to-use tool. Telosys is designed to be usable by everyone in any type of situation. It allows [devleopers] to generate any kind of language, so it is a code generator adaptable to all types of projects. Moreover, all the components are free and open source.
For more information, you can visit the website.
By the way, compliments on the website of your project; it is very clear and nicely designed. I will suggest our readers to take a look.
Why did you need to build this project?
A few years ago, I noticed that developers spent a lot of time coding repetitive and uninteresting portions of code. This is a general problem that we encounter on all types of projects regardless of the development language. This is especially true during the startup phases of a project.
So, I first worked on the factorization of the generic code by creating frameworks and libraries to minimize the volume of code to write manually. But there are still many components with a repetitive structure that must be created manually by the developers (screens, controllers, DAO, unit tests, etc.).
Only code generation can reduce this workload. But the "classic" tools (MDA tools, etc.) are usually quite heavy and complex to use (most of them require UML models) and therefore, it is not profitable to use them for small or medium projects.
So, I started writing a code generator that does not require a UML model and that can be easily used by developers either in an IDE or with a simple command line.
The first use of the experimental version of Telosys allowed my team to generate the entire persistence layer of a Java web application in 2 days instead of the originally estimated 52 days., which encouraged me to continue my work and that is how Telosys was born.
Could you tell us how Telosys differs from other code generators?
First, Telosys was created by developers for developers. It just aims to be pragmatic and efficient.
The conception and development are governed by some basic principles:
- it must be simple, easy to use and remain light
- it must be 100% open source
- it must be able to generate code for any kind of language or framework
- the generated code must have zero dependencies on the tool (to be able to stop using the tool at any time without impacting the project)
- developers must be able to adapt templates easily with any text editor
- developers must be able to define the project entities with a "lightweight model" (no UML model required)
So Telosys can be considered as a tactical tool. It's not a strategic choice with a big impact on projects organization.
You can install it, use it, and delete it whenever you want. Of course, you can also use it from the beginning to the end of the project and capitalize on the models and templates, it's up to you.
What are users typically doing with your software?
Some users just generate code using existing templates. Others have created their own templates library and are regularly improve it.
A user has replaced a proprietary and expensive code generator with Telosys to generate his C# web applications.
Another uses Telosys for microservices deployed in the cloud with Docker.
Sometimes Telosys is also used to learn a new language. For example, if you know how to create a REST backend in Java and you wonder how to do it in Python, just install the Python templates and generate the code.
As you can see, the uses are very varied.
You provide integration of your tool in the Eclipse IDE. How difficult was it to create the Eclipse plugin?
Eclipse plugins development is not very easy. Especially when you need to create different kind of visual components like editors, views, properties editors, help pages, etc.
To be efficient you must master many concepts and APIs:
- the plugin architecture,
- the specific API to access workspace resources,
- the SWT library for graphical components,
- events and tasks management,
- the deployment on the Eclipse Marketplace,
and so on.
But once everything works it's very comfortable to use Telosys with Eclipse, especially for templates bundles creation.
Why Eclipse? Do you plan to support other IDEs?
Eclipse has been chosen because at the start of the project it was the most-used IDE. At the very beginning (7 years ago) the first version of the generator was embedded in an Eclipse plugin and directly coupled with the model editor.
Now, the basic components are clearly isolated from the GUI. The features are callable using an API, so it is possible to integrate the generator into any Java application.
Telosys can also be used with Visual Source Code and Atom in association the command line tool. Some extensions have been created for these IDE to provide specialized editors for Telosys files.
I think that it would be nice to have a Telosys plugin for all the Jetbrains IDE (IntelliJ, PyCharm, PHPStorm, GoLand, etc) but right now I don't have enough time to work on that. Maybe next year.
Which use cases you see for code generation?
Code generation is very useful to provide a common frame for developers. If everyone starts the development by code generation you can be sure that the base is homogeneous for all the team and the code has a satisfactory quality (respect of the standards, comments, unit tests, etc.).
Of course, another major point is productivity. You can significantly reduce the workload during the initial steps of components creation. The more entities you manage, the more time you can invest in creating templates.
Code generation can also be used to quickly produce dynamic mock-ups of an application. Then the code can then be reused in iterative development cycles.
A "scaffolding" approach based on an existing database is also very efficient. I've used it many times, for new projects or for migrations from a language to another one.
In the projects where you use code generation, is code then changed manually? Do you frequently need round-trip code generation?
I estimate that in 80-90% of the cases I don't need round-trip code generation.
Very often it's not so easy to use round-trip code generation for the developers because they must keep in mind what the generator can or cannot do in the code. Moreover, it has an impact on the source code because it requires to manage markers.
What companies have you seen using code generation? What results did they get?
I've seen all kinds of companies use code generation. But often only big companies are able to put in place heavy tools. These companies usually have heavy processes and the means to manage them. But this type of tools (complex to set up and to use) are sometimes abandoned because they ultimately slow down the development (it's a shame).
Reactive or Agile companies generally need simpler and lighter tools.
So, the results are mixed. It depends on the context. Code generation is not suitable for all situations. The cost of setting up tools is sometimes underestimated. And when you have a tool you should not try to generate everything; you have to know when to stop.
How You Use Code Generation
What do you most frequently use as a source of data for your templates, databases? JSON or CSV documents? Other sources?
As every code generator, Telosys merges the templates with data stored in memory.
This data is mainly the entities managed by the project. All entities are defined in a "lightweight model" that can be a "database model" or a "DSL model."
Telosys models are explained on the website, on this page.
A database model is created automatically by Telosys using a relational database as the source. In this case, the database schema is used as the original model, each table is considered as an entity, and the relationships are defined by the foreign keys.
This kind of model is stored in a single XML file. It can be customized by the user if some changes are required to adapt the model.
In the case you want to create a model from scratch, you can use a DSL model. In this case, each entity is defined in a text file. Telosys has its own syntax to define an entity (see the DSL syntax reference).
So, in summary, Telosys uses XML and text files with specialized editors to facilitate the models edition.
The model loaded in memory is a "generic model," an abstraction of the concrete models. So, in the future it will be possible to use any kind of source that can match with this "generic model."
Who typically write templates? Any developer or specialized consultants?
Now with version 3.0, its documentation and specialized editors, any developer is able to customize existing templates or to create new ones.
This has been verified on many projects with different level of developers. Each time a developer is autonomous after about one day of use.
Do you work on transpilers from other GPLs or from DSLs?
Not yet, but since version 3, the DSL model is now the reference model for Telosys and I think that one day it will be necessary to convert a different kind of source to this model. For example, XMI could be the third type of model for Telosys and perhaps it would be simpler to convert the XMI source to a Telosys DSL model than to create a new implementation of the generic model.
About the Open-Source Project
Why did you start this open-source project?
I have been an Open Source supporter for over 20 years. So, for me it's obvious. I never imagined creating a tool that is not open source. I want to share everything with users including the source code. I would like the community to grow and to provide new ideas to continue the tool improvement.
Do you receive many requests for support?
Yes, since the release of version 3.0 Telosys is more and more downloaded and I receive many questions by email, via the forum or via GitHub.
There are also interesting suggestions, new ideas, new expectations, etc.
How do you spread the voice about your product?
To date, the Web is the main vector to spread information.
The communication on Telosys is quite recent; I waited for the release of version 3.0 (a major version) to start publishing articles and documentation. But some users have followed the project since the first version.
The Telosys website is now the main entry point to discover the tool. There are also some videos on YouTube, a forum, a Twitter account, a LinkedIn group, etc. GitHub is the reference for the source code and it also hosts some wikis. A few months ago someone has created a "Telosys" tag on StackOverflow, so you can now ask your questions on this fantastic site.
And sometimes I give presentations with demos in technical meetups, developers groups or universities. Do not hesitate to contact me if you want a presentation.
Do you have plans to monetize your work?
No, currently it is not planned.
Is there anything that you find exciting about code generation or in general in MDD or Language Engineering?
There are different ways to consider code generation. As far as I'm concerned, I took the path of pragmatism and lightness. This approach allowed me to create a pragmatic generator which completes the set of existing tools like classical MDA tools.
And approaching code generation from the developer's perspective is for me the most interesting aspect. Programming is a craft and it's a difficult job. It is very motivating to create tools that will help developers to work better and faster. But it's not just a question of productivity, and certainly not an attempt to reduce the role of the developer. Generators do not replace developers! A tool cannot think instead of the developer, it can only replicate N times what a developer has designed beforehand. It just frees up time to treat the interesting parts of the development, the components with real value added.
It's very exciting to design a "developer companion tool" and there are always improvements to be added to the tool. It's like the Grail quest, it's an endless story.
Do you have any project or resources our readers should look into?
There's an article about Telosys on the blog "Modeling Languages" which can be interesting: "Telosys: The Concept of a Lightweight Model for Code-Generation."
And more generally all books or articles that deal with software craftsmanship, clean code, low code, etc.
For example, a book that inspired me: The Pragmatic Programmer by Andrew Hunt & David Thomas. This book contains a lot of great ideas regarding software development and particularly some chapters like "Domain Languages," "The Power of Plain Text," "Code Generators," and my favorite one "Code Generators Needn't Be Complex!"
Do you know Obeo? It seems that MDD is strong in Nantes. Have you worked with Jordi Cabot?
Yes, I know Obeo and more particularly 2 of its creators (Etienne and Stephane).
I also know Jordi, I have discussed with him sometimes when he was in Nantes.
Indeed, there are many people in Nantes who work around MDD/MDE.
Anything else you would like to add?
Just a little message for the readers: if you're interested in code generation with pragmatic/lightweight tools and if you'd like to share ideas about it do not hesitate to contact me via my Twitter account just send a mail at firstname.lastname@example.org.
A big thank you to Laurent for this interview and his work on Telosys!
Published at DZone with permission of Federico Tomassetti, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.