this post was submitted on 10 May 2026
254 points (98.8% liked)

Ask Lemmy

39494 readers
1797 users here now

A Fediverse community for open-ended, thought provoking questions


Rules: (interactive)


1) Be nice and; have funDoxxing, trolling, sealioning, racism, toxicity and dog-whistling are not welcomed in AskLemmy. Remember what your mother said: if you can't say something nice, don't say anything at all. In addition, the site-wide Lemmy.world terms of service also apply here. Please familiarize yourself with them


2) All posts must end with a '?'This is sort of like Jeopardy. Please phrase all post titles in the form of a proper question ending with ?


3) No spamPlease do not flood the community with nonsense. Actual suspected spammers will be banned on site. No astroturfing.


4) NSFW is okay, within reasonJust remember to tag posts with either a content warning or a [NSFW] tag. Overtly sexual posts are not allowed, please direct them to either !asklemmyafterdark@lemmy.world or !asklemmynsfw@lemmynsfw.com. NSFW comments should be restricted to posts tagged [NSFW].


5) This is not a support community.
It is not a place for 'how do I?', type questions. If you have any questions regarding the site itself or would like to report a community, please direct them to Lemmy.world Support or email info@lemmy.world. For other questions check our partnered communities list, or use the search function.


6) No US Politics.
Please don't post about current US Politics. If you need to do this, try !politicaldiscussion@lemmy.world or !askusa@discuss.online


Reminder: The terms of service apply here too.

Partnered Communities:

Tech Support

No Stupid Questions

You Should Know

Reddit

Jokes

Ask Ouija


Logo design credit goes to: tubbadu


founded 2 years ago
MODERATORS
 

In the Lord of the Rings fandom there's a persistent debate whether balrogs, or Durin's Bane specifically, have wings. The text in Fellowship is ambiguous whether what it is describing are literal wings or something else wing-like.

you are viewing a single comment's thread
view the rest of the comments
[–] Nemo@slrpnk.net 68 points 2 days ago (10 children)

Are tabs worth two spaces or four?

[–] Dultas@lemmy.world 2 points 1 day ago

4 for code 2 for yaml

[–] AndyMFK@lemmy.dbzer0.com 76 points 2 days ago (2 children)

That's the beauty of tabs, it can be whatever you want.

But the correct answer is 4

[–] naught101@lemmy.world 20 points 2 days ago (1 children)

I'm a spaces guy, but agree on the 4. A coder told me decades ago that 4 is better than 2 because if your code starts wrapping due to too many indents you should be refactoring it into functions anyway.

[–] Hudell@lemmy.dbzer0.com 13 points 2 days ago (1 children)
[–] naught101@lemmy.world 13 points 2 days ago (3 children)

In part, because it forces 2-space tab users to confront the indentation issue above

Also there are no drawbacks.. I still hit the tab key to indent (and shift tab to dedent). My editor does the rest.

[–] the_artic_one@piefed.social 15 points 2 days ago (1 children)

The drawback to spaces is that people with vision issues or dyslexia lose the ability to make the code more readable in their IDE by adjusting tab size.

[–] naught101@lemmy.world 4 points 2 days ago

I can't speak to dyslexia (but in would guess that 4 spaces is easier than 2?).

At my last job we had a default linter policy of 4 spaces across all languages (python, JS, rust, mostly). We also had a blind coder. He never mentioned it. I'd guess screen readers are capable of dealing with it these days?

[–] Hudell@lemmy.dbzer0.com 7 points 2 days ago

You can do the same thing with a linter rule, without forcing everyone to see the code in your preferred way.

[–] Speiser0@feddit.org 4 points 2 days ago (1 children)

Also there are no drawbacks

That's just not true.

[–] naught101@lemmy.world 1 points 2 days ago (1 children)
[–] Speiser0@feddit.org 2 points 2 days ago

You might want to read this: https://www.reddit.com/r/javascript/comments/c8drjo/nobody_talks_about_the_real_reason_to_use_tabs/

(There are more downsides of spaces, but I do not care to list everything. It should be obvious that "there are no drawbacks" is a far too general statement. :P)

[–] early_riser@lemmy.world 4 points 2 days ago (1 children)

Tabs are one space *quickly runs away*

I use a single space to indent when writing Python in a SecureCRT command window that gets sent to an interactive Python shell on the server.

[–] regedit@lemmy.zip 1 points 2 days ago

Tabs are one space *quickly runs away*

Run all you want, but we will find you!!! 😉

[–] kamen@lemmy.world 3 points 1 day ago (1 children)

However many I feel like that day. Sometimes depends on the language and use case - if it tends to be deeply indented, I'd gravitate towards 2.

If using actual tabs, you can change how they appear just for yourself without touching the actual code; the same can't be said about spaces.

[–] Nemo@slrpnk.net 2 points 1 day ago (1 children)

I was trying to stay out of the fray but this one I feel I have to respond to:

tabs, you can change how they appear just for yourself without touching the actual code; the same can't be said about spaces.

This is why I use spaces. A space is a space everywhere, a tab depends too strongly on the editor. I've had too many times where I had to edit on a different machine and it transmogrified my tabs into a different non-character entity in a way that didn't reveal itself until later.

[–] kamen@lemmy.world 2 points 1 day ago

I can kind of see your point if you're speaking from a devops/sysadmin's point of view (i.e. something that would require you to use default editors on the go on systems that you don't necessarily have control over).

Other than that, a tab's principal purpose is indentation. One tab is one level of indentation regardless of how it appears. If a tab gets transformed into something else, it sounds like a text encoding problem and indentation would then be just one of (and possibly the smallest of) several possible issues.

I'm speaking from a web dev's point of view - I'm assuming that I'll always have my own configured editor on hand and I'll be able to tell it that one tab is N spaces, sometimes even differently for different file types in the same project. Worst that could happen is that I don't have a specific configuration and the editor just falls back to the default until I set otherwise. Since I'm working in a team, using spaces for a source controlled project would mean that everyone has to use the same. Having tabs means that everyone can configure it for themselves (assuming editor configs don't go in the repo).

[–] SubArcticTundra@lemmy.ml 16 points 2 days ago* (last edited 2 days ago) (2 children)

I might have the solution: Elastic Tabs. They di what tabs were always meant to do from the start, whilst also fixing the shortcomings that spaces are currently used to fill.

[–] regedit@lemmy.zip 3 points 2 days ago (1 children)

Wtf is this witchcraft and how can I use it in VS Code?

[–] SubArcticTundra@lemmy.ml 2 points 1 day ago (1 children)
[–] regedit@lemmy.zip 1 points 1 day ago* (last edited 1 day ago) (1 children)

You are my spirit animal! ❤️

[–] SubArcticTundra@lemmy.ml 2 points 4 hours ago
[–] SubArcticTundra@lemmy.ml 4 points 2 days ago* (last edited 2 days ago)

When you display a TSV file using elastic tabs, they finally display nicely.

[–] panda_abyss@lemmy.ca 19 points 2 days ago

:set tabwidth=4

[–] kbal@fedia.io 14 points 2 days ago (2 children)

I've heard of 8, 4, and even 3 which is pretty crazy... how could it possibly be 2!?

[–] JohnnyCanuck@lemmy.ca 10 points 2 days ago (2 children)

2 spaces is pretty common in JavaScript... And I think I remember it being pretty standard in HTML way back when. Screens used to be smaller, with low resolution. 4 spaces was a luxury.

Isn't 2 spaces the standard in Ruby? I don't use it, but I've heard such things.

[–] farmgineer@nord.pub 2 points 2 days ago

This is my experience as well. These days, fewer than 4 spaces is downright unreadable to my aging eyes.

[–] kbal@fedia.io 4 points 2 days ago (1 children)

Two spaces sure, but that's for people who don't use tabs.

[–] JohnnyCanuck@lemmy.ca 4 points 2 days ago

Yes, I mean tab stops set to two spaces.

[–] massive_bereavement@fedia.io 6 points 2 days ago (1 children)
[–] TAG@lemmy.world 4 points 2 days ago (1 children)

3 is a tab width compromise. It is wider than 2 but not as wide as 4. No one is happy but not as unhappy as they would be at their less preferred extreme.

[–] massive_bereavement@fedia.io 3 points 2 days ago

Enlightened centrism at its finest.

[–] aln@lemmy.world 5 points 2 days ago
[–] CorrectAlias@piefed.blahaj.zone 2 points 2 days ago (1 children)

Live a little and do a mix of both

[–] kamen@lemmy.world 3 points 1 day ago

This way people from both sides of the argument can hate you. Win-win!

[–] ipkpjersi@lemmy.ml 2 points 2 days ago* (last edited 2 days ago)

Four, but I'm a spaces fella.

[–] theherk@lemmy.world 3 points 2 days ago

That depends; are oranges worth 9 feathers or 12?