Portrait Dr. Axel Rauschmayer
Dr. Axel Rauschmayer
Homepage | Twitter
Cover of book “JavaScript for impatient programmers”
Book, exercises, quizzes
(free to read online)
Cover of book “Deep JavaScript”
Book (50% free online)
Logo of newsletter “ES.next news”
Newsletter (free)

Sections in source code

[2020-02-14] dev, javascript, ide
(Ad, please don’t block)

In this blog post, I’ll briefly explain the idea of having sections in source code. The IDE Visual Studio Code has a related concept: folding regions.

Source code sections  

In my code, I like to group related constructs – for example:


//========== Core data structures

export class FileFactory {
  //----- Setting up the FileFactory

  addDirectory(dirPath) {}
  addGeneratedFiles(filePaths, generationFunction) {}

  //----- Using the FileFactory

  getReadable(filePath) {}
}

//========== Helper functions

export function writeFileFactoryToDirectory(fileFactory, outputDir) {}

Visual Studio Code: folding regions  

Visual Studio Code supports folding regions. These are marked as follows:

//#region Core data structures
//#endregion Core data structures

Alas, they only affect folding. There is an issue asking to display regions in the code outline, though.