Keep your business code separate from the rest

Daniel Weinmann - Jun 10 - - Dev Community

One of the best things you can do for a codebase is to keep the business logic separate from everything else.

Imagine you have an app from 20 years ago, written in an old framework no one uses anymore. Thousands of people rely on it for their jobs, because it is the only app that deeply understands how this particular industry works.

The user experience could be so much better but the app works and no competitor beat them yet. Now you're tasked with bringing this giant to the modern days by adopting current technologies to improve the overall experience.

You take a quick look at the code, and being a seasoned dev with a sharp sword, you prepare for war. You know it's going to take your team a long time and it's going to be messy. Why?

Because most of your time will be spent untangling the logic that needs to stay from the parts that need to go. And what needs to stay is the business logic. The rest is old framework code no one cares about.

Now, while you untangle this mess, are you going to leave another one for future generations? Of course not. Because you know the current framework you're using now will undoubtedly be replaced by something else in a decade or so, you will do your best to keep the business code separate from everything else.

To do so, ask yourself the following question at all times:

If I were to migrate to a completely different framework tomorrow, would I be able to take the business logic with me?

If the answer is "yes", you're writing code that lasts. If not, you're borrowing from the future and some refactoring is in order.

. . . . . . . . . . . . . . . . . . . . .