DEV Community

Kurt Reynolds
Kurt Reynolds

Posted on

Seeking advice for best practices on formatting code

Hello everyone!
A recent interaction on Stack Overflow got me thinking about best practices for formatting my code. Does anyone have any information on where I could find some documentation/instructions on best practices for formatting code?

Discussion (4)

Collapse
ingloriousratbastard profile image
Javier Yzaguirre

Also not sure as to what you mean but perhaps you might look into some extensions for your IDE of choice. For VS Code, check out Prettier, Beautify, and Better Align to kind of tighten up your code a bit. Bracket Pair Colorizer also comes in handy.

There are some slightly more advanced extensions like Quokka and GitHub Copilot that will help with suggestive code completion.

Collapse
kurtreyn profile image
Kurt Reynolds Author

I've got Prettier, but haven't heard of the others. Thank you for the information.

Collapse
sfiquet profile image
Sylvie Fiquet

I'm not entirely sure what you're asking. Maybe add a link to the SO interaction so we have some context. I'm going to assume you're not talking about formatting code in markdown.

The whole point of formatting code is to make it easier for other people to read. That includes you in six months time when you have forgotten everything about the program.

In general each programming community has its own standards. Given your profile, I assume it's JavaScript you're talking about? Maybe google for "Javascript style guide", there are a few around. I found this article that lists five of them. Which one to use? It doesn't matter, you use whichever style guide your company/uni has picked. As an independent learner you can pick any you like.

There are tools called linters that you run on your code to check if it conforms to the chosen standard. It helps you catch bugs early, e.g. a typo in a variable name will cause an undeclared variable error. Eslint is a popular one.

Collapse
kurtreyn profile image
Kurt Reynolds Author

This helps a lot. Thank you for the reply.