this post was submitted on 05 Sep 2023
165 points (79.6% liked)

Programming

17405 readers
186 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 6 points 1 year ago* (last edited 1 year ago) (2 children)

Interesting take. I prefer spaces because each piece of code that I see with tabs has an implicit tabsize you really need to have if you don't want the code to look ugly - especially if the person has been mixing tabs and spaces - and they usually do. Sometimes unadvertently.

When you remove all tabs at least everyone is on the same page.

To the actual problem raised by the article:

I have ADHD. Two spaces per indent makes it damn near impossible for me to scan code. My brain gets too distracted by the visual noise. Someone who’s visually impaired might bump their font size up really large, and need to scale up or down the amount of space per indent. Someone might just prefer it because…

I wonder if it could be possible to adjust the "indent number of spaces you see" in code editors. Code editors are able to figure out what are indents and what are not, so in theory it should be possible. Perhaps that would be an idea for a new feature?

[–] [email protected] 13 points 1 year ago (1 children)

each piece of code that I see with tabs has an implicit tabsize you really need to have if you don’t want the code to look ugly - especially if the person has been mixing tabs and spaces - and they usually do.

Well written code doesn't have an implicit tab size. You should be using a tab to mean "one indent" and if you need to align something an exact number of characters then use spaces.

This is the downside to tabs, they are easier to use correctly. With spaces if it looks right in your editor it probably looks half decent everywhere else. Tabs have a worse behaviour if they are misused, but if used well then every viewer can view and edit with their preferred indent size.

I wonder if it could be possible to adjust the “indent number of spaces you see” in code editors.

You could potentially do a good job with a full parser for the language in question to determine the indent level and separate indent from alignment. But I’d rather not rely on this when we have a perfectly simple and semantic character for indicating what is an indent and what is an alignment.

Maybe this could be a useful linter though. That way mistakes are caught but not every editor needs a perfect parser of every language.

[–] [email protected] 4 points 1 year ago

The thing is - I have probably seen hundreds of projects that use tabs for indentation ... and I've never seen a single one without tab errors. And that ignoring e.g. the fact that tabs break diffs or who knows how many other things.

Using spaces doesn't automatically mean a lack of errors but it's clearly easy enough that it's commonly achieved. The most common argument against spaces seems to boil down to "my editor inserts hard tabs and I don't know how to configure it".

[–] [email protected] 1 points 1 year ago

Yes. That's what tabs are for. You can choose the width of the tab. It can be small for people with small screens. It can be big for this guy or people with 600 inch ultrawides.

Tabs are objectively superior because they are exactly what everyone wants at all times, and the git commit history does not get polluted.