Indent with tabs
There are two uses of white space in source code: indentation and alignment.
Indentation expresses the semantic level of a source line. This task falls naturally onto tabs.
- Semantically correct: one tab is one level in; a space is separation of two words, and emptiness of a character wide.
- Accessible: visually impaired people might have difficulty reading indentation too small, like 2-space; some might otherwise find indentation too large, like 8-space, too tiring to read. With tabs, they can freely adjust to their comfortable display width.
- Respectful: with tabs, users could adjust their display width to their liking; spaces force author's preference onto them.
- Less bytes: with 4-space indentation, a tab saves 3.
If you have background in Web development or other computer layout systems, think of relative and absolute sizes. A tab is like 2rem
; a space is like 32px
or 32pt
.
Align with spaces
Tabs are not ideal for alignment: if the content before it is longer than a tab's width, the following example that looks fine with tab width 4:
routers.add({
"/" => get_index,
"/transactions/{id}" => get_transaction,
"/account" => get_account,
})
.. looks terrible with tab width 8:
routers.add({
"/" => get_index,
"/transactions/{id}" => get_transaction,
"/account" => get_account,
})
Here, spaces are more fit:
routers.add({
"/" => get_index,
"/transactions/{id}" => get_transaction,
"/account" => get_account,
})