DRY in low-code with OutSystems
DRY (Don’t Repeat Yourself) — one of my favorite principle in coding. Moving away from the opposite of it WET (Write Everything Twice). While this is not a very complex principle that aims to reduce repetition but still, many of us commit this.
With the power of low-code platforms like OutSystems, it makes our mind work in RAD thus sometimes forgetting that we have principles to follow to make our application healthy. Healthy in the following forms:
Maintainability
Imagine that you have code that does the same thing scattered all over your solution and you need to change it. You have to find all of those instances and do the changes. The more codes you touch the more likely the changes will cause an issue. Grouping logic together helps the software to adopt new changes.
Readability
While it’s much easier to read code in low-code, repeating codes will make your code larger thus leading to the need for more time to read. Creating encapsulation and grouping the logic the right way will highlight the responsibility of what an action is supposed to do.
Reuse
“DRYing” your code promotes code reuse. Given that things are not tightly coupled to each other and with the right granularity, it could save development time by reusing what is already written.
In general, all of this will reduce the cost of development giving developers more time and space. But on the other hand over-DRY’ed code can cause overly complex code. My rule of thumb — break the logic if a reuse situation arises till then KISS it — if you don’t know this acronym, I will leave it to you to do research…
And now, does the code below look familiar to you?
Trust me, I’ve seen lots of this because the platform doesn’t have the capability yet to do a generic implementation for such a requirement. In high-code world like C#, we could simply create an Interface or Abstract class to fill up the audit fields. Beware, shameless plug coming… this is when I created Dynamic Extension which leverage on Reflection to help assign values dynamically. It currently only supports Record List and List because these data types are being passed on extensions as a Reference type. The demo shows a workaround on making this work on just a record. With this extension, you can create an encapsulation of your audit logic to not cause noise to the business logic and implement well the Single Responsibility Principle.
Disclaimer: The extension mentioned are not officially supported by OutSystems. The views expressed by the author above do not necessarily represent the views of OutSystems.