Clean Business Rules

Do you ever see code spill over into the right-hand void?

For most, you may have encountered situations where lines of code are not visible because they are just too long to fit onto your screen, like below.

Graphical user interface, text, application Description automatically generated

You may click the highlighted button to give you more room:

Graphical user interface, text, application Description automatically generated

But it just isn’t enough — code still spills over!

For this specific situation, you can probably collapse the left-hand formula helper and possibly see the rest of the commented-out code, but what if there were lines longer than that?

Now, you may be saying to me, “Well Eric, just buy a 4k monitor, hook it up to your laptop and you’ll be able to see everything.” While this may work for some home office warriors, some of us only have the option of a small laptop screen.

To prevent this from happening in the first place, I propose all business rule writers collectively stop writing long lines of code in their business rules.

I may be wrong in this, but I don’t think anybody has a good time scrolling to the right to see a long string of 18 qualified dimensions — or some crazy function that has a bajillion required parameters. In my experience, whenever I encounter this, the code is always harder to read.

So how do we write shorter lines?

I haven’t been writing code in VB.NET very long, but apparently in 2009 implicit line continuation was added to the language.

What this does for us, is we can write out things like this:

Text Description automatically generated

The reason we can write it out like this, is because VB.NET executes and compiles code as one line if it encounters certain characters.

So, for that first string declaration, after the `=` character, you can write anything below it and it will treat the line above it as a continuation of the statement — similarly, this is true for the `&` character.

And for the calculate function, each optional filter parameter that follows the main calculate formula can be put onto separate lines due to the `,` character implicitly continuing the statement.

There are a bunch of other characters you can use as well, like any of the binary operators (i.e. +, -, /, And, Or, Like) or any of the assignment operators (i.e. =, &=, :=, +=). The fully qualified list is in the link I provided above.

No more long lines, please, I beg of you.

Hopefully, putting this out into the ether will put a dent in the reduction of long line statements in business rules across all OneStream implementations.

I promise you — not only will your business rules be more readable — it will also impress your business-rule writing colleagues, I guarantee it.

Share This: