Tabs are objectively better than spaces
gomakethings.com
external-link
Yesterday, I shared some spicy takes. A few were particularly controversial—most notably, that I correct Gif the correct way (with a soft G)—but I also got a lot of emails asking me to elaborate on a few of them. Today, I wanted to talk about how tabs are objectively better than spaces. This won’t take long. Tabs let you define how big you want each indent to be, and spaces do not.

why don’t we store code unformatted and have everybody’s IDE display it with their preferred format applied? it would make everything easier and stop people bickering over pointless things.

That’s what tabs are for. 1 tab, to an ide, means “you choose how many spaces this tab is, and when we commit it back to git it won’t fuck the history up.”

I guess they were referring to formatting other than tabs, like place of brackets and line length, which sounds like a neat idea

…until you start using languages where whitespace is the only way to distinguish code blocks. (Most notably Python.)

aes
link
fedilink
English
21Y

It was harder to explain why picking on Python for this is dumb, before gotofail… (Not saying that’s what you’re doing, but it feels close, so this is relevant.)

For whitespace, my rule is this: If any level of indentation depends on the length of any word or name, you’re doing it wrong. If using a more descriptive name causes indentation where previously there was none, that’s fine, but if moving the opening parens causes the interior to be indented more, less so. (Yes, Golang’s structs)

Storing an AST would be interesting, but it’d require the IDE to support parsing each specific language, so you’d probably want something like an LSP but for just parsing to handle that.

Create a post

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 !webdev@programming.dev



  • 1 user online
  • 1 user / day
  • 1 user / week
  • 1 user / month
  • 1 user / 6 months
  • 1 subscriber
  • 1.21K Posts
  • 17.8K Comments
  • Modlog