Skip Navigation

Tabs are objectively better than spaces - gomakethings.com

gomakethings.com Tabs are objectively better than spaces

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 t...

Tabs are objectively better than spaces
TechNews @radiation.party

Tabs are objectively better than spaces

4 0
170 comments
  • I've always wondered why some people tout "forcing a consistent appearance across environments" as a pro for spaces. That's a bad thing.

    To be honest I'm surprised code format converters aren't ubiquitous. Let the repo have it's master format, enforced on commit. Then converters translate into each developer's preferred standard dialect on checkout and back again on commit.

    • The consistent appearance thing is probably more about how mixing tabs (for indentation) and spaces (for alignment, eg in multi-line function definitions of calls) looks like complete crap if you change the tab width.

      • Using only tabs for indentation and only spaces for alignment will never result in crap alignment when adjusting tabstops because the alignment does not use tabs.

        This is using both tabs and spaces for alignment.

         
            
        --->func foo(int i,
        --->--->     int j);
        
          

        Observe what adjusting the tabs does,

         
            
        ->func foo(int i,
        ->->     int j);
        
          

        This uses only spaces for alignment,

         
            
        --->func foo(int i,
        --->         int j);
        
          

        When converted the alignment is maintained because the tabstops aren't used for alignment, only for indentation.

         
            
        ->func foo(int i,
        ->         int j);
        
        
          
      • I think you have it backwards. If you use tabs for indentation and spaces for alignment it works great for any tab size.

        It is when you use a tab just as a compressed representation of 8 spaces and use them for alignment as well that it goes to shit. (because you have made the sin of tab == 8 spaces instead of the correct tab = 1 indent level)

  • I think calling one way better than the other is flawed. The reason the title is saying that tabs are objectively better is because they are used in addition to where spaces are used elsewhere. You could make the same argument in favor spaces due to keeping things simpler.

    The argument of having variable indent size for tabs so viewers can decide how big they are is imho legitimate but also not the goal as it's addressing something that teams generally agree on. There is max characters per line, brace placement, general code style and rules. Yes we can eject the indentation from the rules that are agreed on but once again simplicity over complexity has an equal say.

    In the end it doesn't matter that much, a good programmer will be able to work in either setting, the Editor will do most of the work anyways.

    With all that said, spaces all the way!

  • Original poster is right by all accounts, of course. Now, let's come up with exotic significant indentations.

     
            function xyz(a, b):
        |   var x = 2
    
        |   if true:
        |   |   do_something()
        |   else:
        |   |   do_something_else()
    
        |   anyway()
    
    
      

    Pro: Your editor no longer needs to implement indentation hints.

    Con: Looks obstructive if not highlighted like an indentation hint.

    Your turn.

  • I'm tinkering with a whitespace language and prefer using 1-space rather than 2. I don't really like the double character for 1 level. Is that weird?

    Tabs are forbidden though I could use tabs with a (1-line) per-file code filter for the compiler to turn 1 tab into 2 spaces, and that might be easier when working with others (though I don't know how it would be seen, especially needing to change editor tab behavior).

170 comments