DEV Community

Vesin Dusko
Vesin Dusko

Posted on

Specification as Code, the full power of #DRY and #model-driven development

We have built our ToDo app (backend, frontend) using code generators and domain-specific language. Now we can analyze the benefits of MDD (model-driven development).

Speed

Writing the entire todo app in todo.sifu took us half an hour, and we got much code generated in 2-3s, 256 files, and 15k lines of code!

Consistency

All the code is 'same,' implemented in the same way with the same coding rules. It is like the same developer wrote it.
Solution #overview - We can see the entire app overview in one file todo.sifu file. We can say that sifu spec is 'documentation as code', which is the essence of DRY. We don't duplicate the knowledge. All the information from sifu spec goes directly into the code.

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system
Enter fullscreen mode Exit fullscreen mode

Maintainability

Reading, updating, and refactoring the app are much more manageable. The impact of every change is much more visible on such a high level. For example, we can see how many APIs will require updating by changing some models or queries.

Modeling

Instead of thinking about the implementation, developers are more focused on the modeling. Our experience is that sometimes we spend hours or days modeling and rewriting the sifu file with multiple iterations before generating code and diving into implementation. We are detecting flaws and fixing them 100x times faster than in the traditional development way.
Best #practices - Because of the code generator, the best practices will be enforced into the code. APIs will be implemented in the same way, all controllers, repositories, models, the security part of the app, web components, routings.

Quality

Thanks to the code generator, many dummy mistakes that can occur during implementation are avoided. Even if the generator has a bug and generates code with a bug, when the generator is fixed, all of them will be fixed by the next regeneration. We are solving problems in one place and distributing solutions into the entire code base. In our case, almost 80% of the application code is generated, and we don't test that code. That gives us great confidence and lets us focus on other things.

Upgrading

For example, these days, Angular 13 is released. To successfully upgrade an app to the new version, developers need to go through a set of steps. Update libraries, use the latest features of the framework, refactor some parts of the code, maybe even change the entire architecture. And repeat the same process for every client that the app has. There is much manual work to be performed to complete this job successfully. In the case of code generators, we need to update the code generator, which is no small amount of work, and then regenerate. All the parts of the code will get the same treatment.

Validation

One of the most significant benefits is the validation of the specification. Because the specification is a code, we can compile it and perform all different types of validations. This benefit is even more potent in the case of enterprise apps. For example, our app has 30k lines of specification code.

To use MDD, you need to invest time and resources into building the toolings, but the benefits are colossal. We at alchemy can develop a codeless platform with millions of lines of code and rewrite it already three times from scratch with the development team of 10-15 members!

In my previous life (the one without MDD and Sifu language and the code generator), for the same achievement, it would take a team of at least 75, and success would be much more uncertain.

Top comments (0)