The Relicans

loading...
The Relicans Prime

Tabs or Spaces?

captainellie profile image Captain Ellie ・1 min read

Happy day friends!

I hope your Wednesday is going great, and I am here to ask you a very important question...

TABS OR SPACES? Why?

tavs vs spaces gif

As a Pelican who codes, it has always been a question in my mind...

So help a Pelican out and please comment with your preference and the WHYYYyyyyy!

Discussion (6)

Collapse
chaelcodes profile image
ChaelCodes • Edited

Tabs

Allow users to determine what spacing they want while reading code. Many folks with learning or visual disabilities use this to make it easier to read. For some disabilities, 2 spaces is easier, and for some 8 is easier.

HOWEVER, tabs make perfect alignment hard. You can't Indent your methods to the depth of the first method call, because you'll be comparing tab spacing to characters. Even if you ignore that, a tab and then a space become very common, if you're trying to indent to match the first call, like

something = object.super_long_method_with(lots, of, arguments)
                   .other_method
Enter fullscreen mode Exit fullscreen mode

One tab deeper is MANDATORY if tab spacing is modifiable.

Also, I just created that code example with spaces. I cannot create it with tabs in this forem web editor unless I copy/paste tabs. Which is annoying. Want properly spaced code in your StackOverflow question/answer? Probably a good idea to use spaces.

Spaces

Everything is consistent all the time. You have complete control of your spacing, and whether it's on github, your editor, or the web, it always looks the same.

The complication

You can automatically convert files from tabs to spaces and spaces to tabs. Normally, accessibility defeat consistency any day, even with the StackOverflow argument, but the ability to convert files into readable formats means that you're weighing web editing of code samples and common language practice against anecdotal preferences from a community that knows how convert files. Even accessibility sites are split with tota11y using spaces and a11yproject using tabs.

Collapse
wyhaines profile image
Kirk Haines

I used to use tabs. Now I use spaces. However, most editors make it easy to switch between them, and to customize indentation regardless of what one uses, so it is pretty invisible most of the time.

As for why -- I used to use tabs because it was fewer keys to hit, and tabs are a character that are intended to encode indentation.

I switched to spaces because tabs sometimes cause formatting issues of their own, whereas spaces are more predictable, and because I graduated to just using my editor features (whether it be vim or a GUI editor) to manage the issue for me. It makes tabs the width that I prefer. It makes spaces do the same thing. If I change something, the editor figures it all out and handles all of the tedious stuff itself, so all that I have to do is to type my code.

Collapse
pachicodes profile image
Pachi πŸͺ (she/her/ela)

I have no preference on the matter. I use Tabs, for no particular reason πŸ˜‚

Collapse
xomiamoore profile image
Collapse
eduardoklosowski profile image
Eduardo Klosowski

I use EditorConfig to configure my editor for each project, according to the defined code style. When is a new project, I follow what the community of that language uses most, 4 spaces for python, tab for Makefile (this format need tab)... Change this make more conflicts in git merges.

Or I need spaces to put hot dogs:
code with hot dogs

Collapse
realchrissean profile image
Chris Sean πŸͺ

Tabs 100% haha

Forem Open with the Forem app