programming practices – Is enforcing code formatting standard that important in 2021 compared to 2005 with microservice architecture?

As soon as the code is read more than it’s written, it doesn’t matter if you’re writing a microservice or not: bad code is bad code.

Formatting is important, because:

  • Consistent formatting decreases the time wasted understanding code. Whenever it’s your colleague reading your code when you’re on vacation, or you yourself six months after writing the code.

  • Correct formatting decreases risks of errors, where at the first glance, you think the code is doing this or that, but the code actually does something else. Popular example:

    if (this.enabled)

    The second statement will execute whenever this.enabled is true or false. Nevertheless, it looks like it’s a part of the condition body. May not be a big deal to fix, but sometimes, one can waste a few hours on a problem like this.

Your 5.000 LOC threshold, or the presence of a microservice, or the presence of multiple languages is completely irrelevant.

Many of your bullet points, by the way, are plain wrong:

A microservice rarely exceeds 5000 lines of code (probably that is too much).

I would be interested to see your reimplementation of Amazon S3 or Amazon SNS in 5.000 LOC. More importantly, LOCs are completely irrelevant here: you can screw things up with bad formatting in three lines of code, as shown above.

We have multi language setup with microservices written in Java, Kotlin, Golang, Python.

Which is not the case of every project out there. Many use one or two languages. More importantly, the more languages you use, the more it is important to stick with the official style, specifically because the code will be written and read by developers who are not language experts. The most horrific pieces of C# code I’ve seen were written by programmers who mostly use JavaScript.

High level of redundancy. Code is duplicated much more often.

Which means… that consistency in code formatting becomes more important?…

Code is disposable, very easy to just throw it in the garbage and write something new.

This is your specific case. In most companies, it is not unusual to find code dating back ten or twenty years back. Once it works, it makes little sense to throw it away and write something new. Terrible formatting may explain why a team could decide to throw the piece of code away.

The code being disposable means we will not end up with a maintainer having to maintain it for many many years as it is with monoliths.

See previous point. And the lifespan of a piece of code has absolutely nothing to do with microservices. If you rewrite your microservices on regular basis, you’re doing it wrong.