Skip to content

Instantly share code, notes, and snippets.

@Enhex
Created January 13, 2018 10:04
Show Gist options
  • Save Enhex/02f15abbc1c3842bf538639315c9ada1 to your computer and use it in GitHub Desktop.
Save Enhex/02f15abbc1c3842bf538639315c9ada1 to your computer and use it in GitHub Desktop.
Optimal usage of tabs and spaces
Optimal usage of tabs and spaces
================================
Goal:
Minimize number of characters used while keeping everything aligned with any tab size.
Tabs should be used to align text from the same line position, so having different tab size won't misalign the text.
Spaces should be used when the line position isn't aligned, and when it becomes aligned after the spaces tabs should be used.
examples:
(using `|` to indicate alignment)
|a
| b| <- indentation starting from position 0
| c| <- indentation starting from position 0
|a
| b | |// comment| <- comment starting from 1 tab then 1 char, need to add 2 spaces to align it with the next line
| ccc| |// comment| <- comment starting from 1 tab then 3 chars
Notes:
======
- hard to see if spaces properly align tabs, which makes it error prone.
- only using tabs for 0 position alignment, and spaces for the rest is not error prone
- automated formatting won't make mistakes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment