Just like grammar in real life, syntaxes have to followed when a programmer writes code. As for code formatting, just don't think too much about it.
Code syntaxes are the bare minimum requirements to follow so that programming code to run properly on a compiler. As for code formatting, it feels a bit similar to a writer's individual writing style. Which is not really a big issue anyway. If the code is written for your own consumption and purposes only.
The reality today is that lots of endeavours today are a team effort. Properly formatting one's code will allow it to be properly understood by others and will increase its readability.
But who has time to manually format your code anyway? There is so much work to do anyway, and code formatting is not really a high priority anyway.
[Enter formatting on save and code formatters.]
My current IDE that I use for programming is Visual Studio Code, which is the most popular IDE for developers on Stack Overflow. It is open source, available on a large variety of operating environments and most importantly, it is extendable in the form of downloadable extensions made by developers for developers.
Right now I handle large amounts of Python and HTML/CSS code. I typically don't have much time to format my code properly. Most of the time how I code goes something like this:
Quickly hack out a solution by hard-coding → Trying to implement the solution for a larger range of input values by rewriting hard-coded code as custom classes
As such it can get messy pretty quickly, especially when I am moving from hard codes to custom classes.
Therefore I combine code formatters with formatting on save. Now I do not have to think about code formatting at all. Every save I make, the code formatter reformats the code for me. I do not have to do anything at all and I can focus purely on thinking how I should code.
For Python, I was using
autopep8 for quite some time until I discovered Black. Now I use Black exclusively to format my Python codes. For HTML/CSS, my preference is Prettier. Seeing all the indenting for HTML/CSS being done properly for me on save is really satisfying. I would say that code formatting really simplifies coding in HTML/CSS. Less time is wasted searching for the opening and closing tags. It is amazing!
If you have not tried code formatting yet, do give it a try. Trust me, once you use it you would not go back again!