nikhil.io

“Vertical Hanging Indent” is the One True Indentation Style

With the trailing comma and sorted properties/imports/arguments/whatever. Makes symbols easy to scan from top-to-bottom and looks like this in Python:

from constants import (
    EXIT_CODE_ARTICLE_ROOT_NOT_FOUND,
    EXIT_CODE_NOT_A_GIT_REPOSITORY,
    EXIT_CODE_NOT_AN_ABSOLUTE_PATH,
    MARKDOWN_EXTENSION_CONFIG,
    MARKDOWN_EXTENSIONS,
    MARKDOWN_FILE_EXTENSION,
    MAX_NUMBER_OF_WORKERS,
    PATHS_TO_REMOVE,
)

In which universe are these shittier alternatives considered readable or maintainable?

from constants import (MAX_CHARS_IN_SEARCH_RESULTS,
                       MAX_CHARS_SURROUNDING_SEARCH_HIGHLIGHT,
                       MAX_SEARCH_RESULTS, MIN_CHARS_IN_SEARCH_TERM,
                       SEARCH_INDEX_PATH)

or

from constants import (MAX_CHARS_IN_SEARCH_RESULTS,
                       MAX_CHARS_SURROUNDING_SEARCH_HIGHLIGHT,
                       MAX_SEARCH_RESULTS,
                       MIN_CHARS_IN_SEARCH_TERM,
                       SEARCH_INDEX_PATH)

or

from constants import (
    MAX_CHARS_IN_SEARCH_RESULTS, MAX_CHARS_SURROUNDING_SEARCH_HIGHLIGHT,
    MAX_SEARCH_RESULTS, MIN_CHARS_IN_SEARCH_TERM, SEARCH_INDEX_PATH)

That’s for Python and the modes are from the excellent isort’s docs. I am glad that Prettier does VHI by default (although you have to specify the trailing-comma and object properties are not sorted.)

See also: K&R is the One True Indentation Style