Let's pretend we aren't going to argue Tabs vs. Spaces. Is 4 spaces really more legible than 2 spaces? It seems to be the default everywhere I look, and I suspect it has to do with Tab size.
I've always preferred two spaces.
Let's pretend we aren't going to argue Tabs vs. Spaces. Is 4 spaces really more legible than 2 spaces? It seems to be the default everywhere I look, and I suspect it has to do with Tab size.
I've always preferred two spaces.
For further actions, you may consider blocking this person and/or reporting abuse
Lindiwe -
Kudzai Murimi -
King Triton -
Edwin Gonzalez -
Top comments (41)
I prefer 4 spaces because they take up more screen space, which means that I can fit fewer indentation levels before it starts to feel uncomfortable, so in general it means that I start addressing some potential spaghetti code issues earlier.
(although tabs are better because anybody can configure their editor to show as many or as few spaces as they want to, I had to say it)
The argument about "how many spaces" is really an argument in favour of tabs.
It goes beyond how many as well, since the moment you use spaces, you start having people align code with them as well. :/
@avalander
You can use prettier cli to format the files. Install prettier dependency and add this script in package.json of any javascript/typescript projects
{
"scripts" : {
"format:two": "prettier --tab-width 2 --write \"src//*.ts\" \"test//.ts\",
"format:four": "prettier --tab-width 2 --write \"src//.ts\" \"test/*/.ts\"
}
}
then run:
$ npm run format:two
or
$ yarn run format:two
for more info you can checkout prettier official website
vs code can auto format an entire file to use the number of spaces one desires, and always uses spaces
Yeah but at my work we use two spaces, can I configure vscode to display four spaces but actually save the file with two?
not that I'm aware of. you'd just have to change it before you commit
Auto-formatting causes trouble with source control. You end up having large patch-sets than desired. It can be hard to locate what was actually changed in a file.
Fibonacci Indentation or nothing.
I'd vote for inverted Fibonacci Identation! 😂
That's amazing!
We will argue 4 vs 2 spaces until we are blue in the face. God forbid someone to suggest a compromise of 3 spaces, for they will be murdered before they finish their sentence.
3 spaces is the most logical compromise. But because humans are illogical, we'll never see a 3 spaced code file.
I bet you set the TV volume to odd numbers.
I use the Fibonacci sequence to set my volume.
I think you'll find the volume should be changed in increments of 5... 😉
The reason volume is adjusted in increments of 3dB is bc changes less than 3dB are imperceptible to the human ear.
how dare you suggest we do something that is not a multiple of 2?? /s
we tried that at a previous gig; made everyone unhappy and uncomfortable. if it's code, IMHO, it's a tab (4 spaces!); if it's markup or documentation or config, two is perfect.
3 spaces
Monster
You rebel.
This one, officer, right here
Tabs, people, use tabs. Then you can choose however many spaces you wish.
I started contributing to a project last night, and after asking this question an issue appeared a few hours ago that is pretty relative to your point!
Tabs are breaking YAML
This is unfortunate that YAML chose not to accept tabs. There's no practical reason not to allow it.
In VSCode there are options like setting the tabs equal to a number of spaces, or you can even have tab insert spaces, I believe.
In other words, I’m not sure what you mean. 😂
If the line starts with the tab character, I can configure VS Code to show it as either two or four (or any other number) spaces, so the same code can have different indentation space in your machine than in mine.
If I configure VS Code to set two spaces every time I press tab, it is unfortunately not possible for somebody who prefers four spaces indentation to visualise the code that way.
This is the first time any part of this discussion has made sense to me. 🤩
or use vs code and still be able to pick the number of spaces you want
My preference for 4 spaces comes from starting out with Python.
Since starting to use Prettier in VS Code, I've been having issues with the setting being changed to 4 spaces in the interaction with the Rainbow Indent extension, and as such have been moving to using 2 space instead.
I don't think either is "more readable" than the other. When there's a bunch of indent widths, even the rainbow indent/bracket colorizer isn't enough to stop me from needing to use my finger/piece of paper to figure out where the matching curly brace is/should be.
8
I used to prefer 4, but I figured, if I find myself indenting too much, then it should probably be refactored. Sort of learned about this by reading about the Linux style guide.
Am I the only person that Bracket Pair Colorizer just annoys and distracts?
I'm not sure if I should set violent colors or something, but any time I try it it only harms me.
I just have
"editor.renderWhitespace": "boundary"
and the default indent guides and it seems enough for me.Ditto for Indenticator and indent-rainbow.
indent-rainbow also doesn't autodetect the tab settings, which are a builtin VSCode thing, why this :v
I use 4 for Python code (it's PEP8) and 2 for html/css/js.
I prefer four because its much easier to quickly scan for what braces match and where blocks end and begin.
Deeply nested code is usually to be avoided, so I don't miss the space is takes up.