https://xkcd.com/1513

https://xkcd.com/1513

Intro

We’ve all had experience when we either needed to share our code with someone else or go back and figure it out ourselves and realized that it was bit of a clumsy mess. This is part of the process of learning, but there are 5 things you can start doing today that can improve your project and code quality significantly with minimal invested effort.

Table of Contents:

  1. Project Folder Structure
  2. VSCode Formatters
  3. Using npm, venv or virtualvenv, etc
  4. Wrapping Third-party Packages
  5. Don’t Indent Too Much

1. Project Folder Structure

Choosing a good structure for your project can determine how often you come back to improve it. When the structure makes sense and provides quick access to the portion of code you are interested in, you are much more likely to make improvements because you understand the structure without having to spend time re-learning the how it is structured.

In my opinion there is no one right answer for how this should be done. We all have different preferences, the most important thing is consistency throughout.

As an example, if you’re starting a project with ReactJs and you aren’t familiar with best practices then I would suggest Googling “Reactjs project structure examples”. You’ll find handfuls of examples on Github showing different ways to structure and organize projects. It’s worth taking a quick look and picking one that makes sense for your use case.

If you want to invent your own structure, great! Here are some tips:

  1. Have a src/ folder — all of the code you write should go in here
  2. The only files at the top level should be ones relevant to the whole project, like a build script or Dockerfile, for example
  3. Try to think in general terms when creating subdirectories inside the src/ folder
  4. Make your structure work for you — if an import or include statement feels hacky, that could be a sign you need to restructure