Follow Slashdot blog updates by subscribing to our blog RSS feed

 



Forgot your password?
typodupeerror
×
Microsoft Programming

Spaces or Tabs? Microsoft Developers Reveal Their Preferences (msdn.com) 238

In a new video, Microsoft's principal cloud advocate and DevOps lead weighed in on that crucial and perennial developer question: which is better, indenting your code with spaces or with tabs? "This is kind of a loaded question... However, I am very opinionated on this. I happen to be a huge fan of tabs, for a couple of reasons.

Number one, your file size is going to be much smaller, because a tab is just one character. Okay, okay, granted this isn't a big deal any more, but I'm old as dirt, and I remember when hard drive space was at a premium.

But here's the real reason: you can customize your indentation width. And this is actually a bigger deal than it sounds like. By using tabs, you now give each individual the ability to see the indentation widths that they want, or even in some cases need. That makes it so much more accessible than spaces, right?

So because of that, for accessibility reasons, use tabs.

Well, I guess that settles that, leaving no need for any further... Wait, there's more responses from other Microsoft developers on this page, including program manager Craig Lowen. At the end of a video titled WSL2: Code faster on the Windows Subsystem for Linux! he says: I prefer spaces to tabs, and that's because tabs don't actually have a denotation of how wide or short they have to be in indentations. That's totally done by your IDE, so if you open it up in a different IDE, it might have a different level of indentation. If you use spaces, you'll always have the same indentation level if you're using a fixed-width font.

But however, I still use the tab key, and I just make my editor insert spaces for me.

This discussion has been archived. No new comments can be posted.

Spaces or Tabs? Microsoft Developers Reveal Their Preferences

Comments Filter:
  • Navigating through such a barbarian's code using arrow keys is a waste of finger-calories. Tabs preserve one keystroke per indentation level for navigation.

    That the primary argument in favor of spaces is "ugh, able use option for set width make Mongo angry" illustrates the neanderthals on that side of the debate.
    • This, is indenting code with spaces not a fireable offense in a software development role? I just assumed it was.

      • No, there are MANY who prefer spaces. And I canâ(TM)t really blame them. Itâ(TM)s the default way to keep files consistent, and some languages require spaces.

        Then there are the files with mixed tabs and spaces. A special place in hell belongs to those users.

        That said, I prefer an IDE that automatically converts to tabs AND notifies you when there are extra spaces. (Except of course for languages that require spaces.)

        • Nevermind, that spot in Hell is reserved for Slashdot mobile.

          • Thats not slashdot mobile. Thats your stupid iPhone. Android users dont have that problem. Its only you. Literally only you. Apple decided that the standard quote and apostrophe characters werent good enough for Apple users and decided to default to using childish cartoon glyphs of those characters instead, and its only been fucking 6 fucking years and you still think its slashdot and not your dumb fucking iPhone that you never bothered to fucking configure to not use stupid cartoon glyphs.
      • Tabs are for heathens that have no code aesthetics.
        As soon as you have multi-line statements tabs fail.

        While the article's first reason for tab use (smaller files) was valid 30 years ago, so was limiting line length to 80. Considering that the phone in your pocked has 10x the pixels as an old VGA display and also has more storage that you could buy for a years salary back then I don't think that argument has merit today.
         

        • There's rarely any good reason to use super-long lines of code, and when there is, it's better to let it run forever (my preference) OR to have an ugly line break than to defile an entire source code file with space-based indentations. The other options would be a small price to pay to maintain the sanity of tab-based indentations.

        • As soon as you have multi-line statements tabs fail.

          Tabs for indentation, spaces for alignment.

        • As soon as you have multi-line statements tabs fail.
          As you have multi line statements, I fire you :D

          has more storage that you could buy for a years salary back then
          Unless 30 years ago, he was a multi billionaire, it was impossible to buy 64BG or even more on less than a ten years salary you can even say 100 years to be on the safe side.

    • by ceoyoyo ( 59147 ) on Sunday October 11, 2020 @05:50PM (#60596364)

      Interesting. The winds seem to be shifting on this one. Previously the space-users were so overwhelmingly vocal that the wise tabbists couldn't or wouldn't say anything. Now, the first few threads I see here are in support of tabs.

      I think the two developers in the summary really make it clear what the dichotomy is about. Tab advocates want to give maximum control to whatever poor schmuck has to read the code. Space advocates are a bunch of control freaks who will give up authority over layout over their cold dead fingers. Or search and replace.

      • Interesting. The winds seem to be shifting on this one. Previously the space-users were so overwhelmingly vocal that the wise tabbists couldn't or wouldn't say anything. Now, the first few threads I see here are in support of tabs.

        The newbs took a joke from HBO's Silicon Valley seriously. Give them time, they'll learn. Their skills will eventually develop and they will use the occasional console based tool.

        I think the two developers in the summary really make it clear what the dichotomy is about. Tab advocates want to give maximum control to whatever poor schmuck has to read the code. Space advocates are a bunch of control freaks who will give up authority over layout over their cold dead fingers. Or search and replace.

        Actually the spaces advocates want the next poor schmuck, which may be themselves at times, to be able to instantly read the code regardless of IDE, or editor, or console. Its not about control per se, its about things just working the first time without experimentation or reconfiguration.

        • by ceoyoyo ( 59147 )

          If your code requires a particular tab stop, you need to think about how you're writing code. Stop trying to draw your penis in it.

          • ^^ This. I don't understand how people can be writing their code so poorly that changing the tab stop renders the code unreadable to any developer.

        • Why are you using a shit IDE and not Borland 4.5?
          • by drnb ( 2434720 )
            It was that sweet integration of Microsoft C++ and Microsoft Fortran in the Developer Studio IDE that converted me from Borland. ;-)
    • It's not just arrow keys. If you want to place the cursor at the beginning of the line, you have to be much more accurate using the mouse when the file uses spaces for indentation.

      • by Megane ( 129182 )

        If you want to place the cursor at the beginning of the line

        That's what the Home key is for. (or the zero key if you are in the holy editor known as vi) Do you seriously take your hand off the keyboard to reach for the mouse while typing?

        • That's what the Home key is for.

          The Home key (or '0') takes you to the beginning of the line, not the beginning of text. To insert something at the beginning of the text you have to hit the arrow key 4 times as many times with spaces than with tabs.

          I use gvim. It's often quicker to use the mouse to move the cursor many lines than to use some keys to get to where I want.

          • Lol, why don't you just use your mouse all the time if you're not going to use keyboard shortcuts?

            In most sane editors you can hit home to go to the start of the line, and then ctrl+right to jump to the first character.

            I use gvim.

            Nevermind.

            • and then ctrl+right to jump to the first character.

              TIL ...

              But still, it's more work than if the indent character is a single tab.

              Fundamentally, that's what I see whenever this argument arises: the "spaces" camp is always saying "but there is this workaround ..".

              With tabs, you don't need workarounds.

    • That the primary argument in favor of spaces is "ugh, able use option for set width make Mongo angry" illustrates the neanderthals on that side of the debate.

      Mongo no want artist code, Mongo want boring engineer code. Written by people with clipboards.

      And if you think Neandertal is some sort of insult, that tells us which side of the "ugga ugga" you're really on.

    • Comment removed based on user account deletion
  • by crow ( 16139 ) on Sunday October 11, 2020 @05:07PM (#60596234) Homepage Journal

    The biggest problem with tabs is that you get people who will do a mix of tabs and spaces, and then it all falls apart. If you're going with tabs, you can't work with a logical 4-space indentation with 8-space tabs, which is exactly what I've seen some people do. (I think emacs does that by default in bash mode, for example, but it may just be my settings are wrong.)

    What is needed is commit checks that require that everyone adding code to the project is following the standard, possibly with exceptions for projects that also include third-party code.

  • by Joce640k ( 829181 ) on Sunday October 11, 2020 @05:12PM (#60596246) Homepage

    tabs don't actually have a denotation of how wide or short they have to be in indentations. That's totally done by your IDE,

    If only IDEs had settings for that...

  • If you don't mix both, you're good.
    But this consistency must be at least project-wide, preferably company-wide.
    Personally I prefer spaces, because your code will be aligned exactly the same no matter the IDE (specially on elaborate comments... yeah, I'm not a clean-code zealot, not everything can be explained in a function name).
    But this discussion is like that one over semicolons on JS... damn, so much worse problems to deal with.

    • > Personally I prefer spaces, because your code will be aligned exactly the same no matter the IDE

      And also no matter the programmer, which is the problem for some. Tabs allow programmers to set the indentation level to their preferences.

      I was a spaces guy but have been converted. I think tabs are only a problem (as you indicated and as many have noted in this thread) when they are mixed with spaces. That fucks everything up, and eventually leads people to think tabs are bad.
    • by nyet ( 19118 )

      sw=4:ts=8:noexpandtab

  • by Anonymous Coward on Sunday October 11, 2020 @05:22PM (#60596282)

    Tabs are the semantic way to do indentation. One character per indentation level. And tabs used only for line-leading indentation. Then each tab character has semantic meaning related to the program structure. Intelligent people recognize this as a good thing.

    Spaces are presentation-level indentation. Not only is each space individually meaningless, but you've just hard coded the visual appearance of your code. There's no special indent character, as spaces are used everywhere (other than perl line noise). Bad for a whole host of reasons, not least of which is accessibility. Narcissistic autocrats forcing their hare-brained choices on everyone else.

    Use spaces if you want to keep coding with Cobol-style fixed punch-card positions like a troglodyte. Or move beyond the weaving loom and program in the 21st century. Semantic markup is generally agreed to be superior in all other realms, but some dinosaurs refuse to adapt. Their death by fiery meteor is well deserved.

    • I was with you until you attacked dinosaurs. Dinosaurs are awesome.
    • by swilver ( 617741 ) on Monday October 12, 2020 @01:41AM (#60597444)

      One the problems with tabs is that any alignment of code further along in a line gets screwed up when you change the tab size. Comments at the end of a line for example on lines that have different indentation.

      Let's say I use tabs, and I set tabsize to 5 (0, 5, 10, 15, 20):

      !....!....!....!....
      >....if(x == y) {>..// My comment that is a bit long
      >....>....x+=1;>....// but aligns nicely with the next line
      >....}

      Now, change tabsize to 4 (0, 4, 8, 12, 16, 20):

      !...!...!...!...!...
      >...if(x == y) {>...// My comment that is a bit long
      >...>...x+=1;>..// and now magically does not align anymore
      >...}

      You can try the same with any mix of spaces/tabs, or advocate only to use spaces at the end of the line... and it still won't align for people that use a different tab size (one of the main arguments for tab advocates). That's why you use spaces.

      --
      ps. Some more text here to counter the lameness filter. Please try to keep posts on topic.
      Try to reply to other people's comments instead of starting new threads.
      Read other people's messages before posting your own to avoid simply duplicating what has already been said.
      Use a clear subject that describes what your message is about.
      Offtopic, Inflammatory, Inappropriate, Illegal, or Offensive comments might be moderated. (You can read everything, even moderated posts, by adjusting your threshold on the User Preferences Page)

      • by vyvepe ( 809573 )
        It will align perfectly well when you use tabs as an code indentation marker to the first code character. And only spaces after that (to indicate indentation relative to the first code character). It is good to have an editor which will show tabs and spaces and even better is to have a pre-commit hook checking this. See: https://slashdot.org/comments.... [slashdot.org]
  • by Anonymous Coward on Sunday October 11, 2020 @05:25PM (#60596300)
    ...align with spaces [dmitryfrank.com]. Never, ever use tabs for alignment.
    • by crow ( 16139 ) on Sunday October 11, 2020 @05:39PM (#60596336) Homepage Journal

      Tabs are neutral evil. Mixing tabs and spaces is chaotic evil.

    • Yes, this works. I am a spaces person myself. However usually when I see indentation with tabs, they also align with tabs as well. This makes changing tab width not work very well. As a side effect, when I do adjust tab width I can see clearly what the original author's indentation size was because there's only one size where things like up in a coherent way.

      I had to do a project recently where for the first time ever, the code style was dictated to be tabs. And there were OCD people unrelated to the p

  • you can customize your indentation width.

    So *everyone* else who views your code has to adjust their tab display for your files?
    People who do what you suggest should be dragged out behind the chemical sheds and shot.

    • by ceoyoyo ( 59147 )

      What the hell kind of code are you writing that it's unreadable if your tab stop changes?

      Stop putting ASCII art in your comments. Problem solved.

      • by Jamu ( 852752 )
        This. I use a proportional font. Tabs and the good readability work for me.
        • I also bold face the important part of the code!

        • by Megane ( 129182 )
          I was way ahead of my time, back in the early '90s I was working on an ad-ware project. It was for Buick, so I decided to edit my code in Eras font, their preferred advertising font of that era.
      • What the hell kind of code are you writing that it's unreadable if your tab stop changes?

        It's more a case of code being unreadable due to excessive indention due to tabs forcing one to set a non-standard tab width simply to view the code on a screen/page. Using spaces -- or combinations, like in Emacs where it can use, say, 1 tab and 2 spaces for a 10 space indent -- makes things universally readable and editable *without* requiring a non-standard tab width. (Said as someone with 30+ years using many, many different programming languages, often several within the same project.) But it's just

  • ...duh!
  • Python: spaces, since the indent is part of the syntax.
    Almost all others: tabs
    I don't use an IDE per se, however my text editor can quickly and easily convert all leading tabs to spaces or vice versa.

    Now we get into the real religious wars: How wide should the tab indents be?
  • Spaces you fucking heathens.

    Christ.
  • When spelled as two words, any more refers to quantities. ... When spelled as one word, anymore is an adverb that refers to time. It means “at present,” “still,” or “any longer.”

  • 3 spaces... (Score:4, Funny)

    by nuckfuts ( 690967 ) on Sunday October 11, 2020 @06:25PM (#60596478)
    ought to be enough for anybody.
  • as a beginner - whatever my IDE of editor was set to by default
    then it became 2 spaces, I finally found it hard to make up the correct indentation, went to 3
    then I discovered how to use tabs properly, and switched to tabs
    then I realized that tabs were inconvenient for copy-pasting, and most people in teams I worked with didn't use tabs properly, didn't configure their editors properly, etc... so I switched to 4 spaces as it is the most common I found, I still use tabs for personal projects.

    So my vote is: fo

  • I bet this the kind of guy who uses single-character variables too. Maintaining his code must a bliss.
    • by drnb ( 2434720 )

      I bet this the kind of guy who uses single-character variables too. Maintaining his code must a bliss.

      Well if he is worried about file size then he's probably working on a floppy disk based machine. In that case it might be a 40 column Apple II display so the single char variables (two for readability) make sense.

  • Number one, your file size is going to be much smaller, because a tab is just one character. Okay, okay, granted this isn't a big deal any more, but I'm old as dirt, and I remember when hard drive space was at a premium.

    I'm older than dirt and remember that too. Then I moved from a floppy disk based computer to a hard drive based computer and it was never a concern again.

    Being older than dirt, what was still a concern was having code look the same regardless of whether it was being viewed in an IDE, type'd or cat'd to the screen from the console, printed, etc.

    But here's the real reason: you can customize your indentation width. And this is actually a bigger deal than it sounds like. By using tabs, you now give each individual the ability to see the indentation widths that they want, or even in some cases need. That makes it so much more accessible than spaces, right?

    Not really. Because any sane organization is going to have coding guidelines telling you what the indentation should be. You should acclimate to the organization's

  • I use all spaces, and insist on it in projects I work on, for the simple reason that tab width is entirely defined by the editor/IDE and can vary from one developer to another depending on settings. Tab-based indentation only works if everyone has the same tab setting and the indentation interval is exactly one tab (ie. if the indentation level is 4, everyone has to set tabs at 4 spaces and not 8). It's far too easy for indentation to become inconsistent the moment even one developer deviates from that, and

  • "But here's the real reason: you can customize your indentation width"

    "That's totally done by your IDE, so if you open it up in a different IDE, it might have a different level of indentation"

    It's the same argument on both sides. You can customise tabs, but the implementation of that customisation can sometimes work in a way you don't intend. Does your code always need to look the same or is it important to be able to easily modify the look of your code? Sounds to me like it depends on the code.

    Which leads

  • Tabs with a width of 4 and OTBS. I always use braces, and it's a waste of vertical space to put a brace on it's own line, even for functions. It's literally the only thing that I have "OCD" about. Mixing spaces and tabs is abomination. Consistent use of 4-space or even 8-space indents is OK, if I have to work on someone else's code that works that way, but I never do it that way myself.

  • If we had Elastic Tabs in a critical mass of editors, this conversation would have concluded long ago.

    Elastic tabs:
    - allows dynamic indentation alignment for indentation blocks. Useful for comments, parameters, tables....
    - allows proportional fonts. Otherwise we are with ugly monospace fonts.
    - saves disk and bandwidth over tabbed source, which saves disk and bandwidth over spaced source.

    • by swilver ( 617741 )

      I'm going to use this right now, my 2400 baud modem has been feeling kinda sluggish lately.

  • Simply put, using tabs is hard. Tabs should be used only for indentation, and only at the start of a line, and never mixed with spaces. Spaces then are used at the end of the line for aligning comments if needed. Donot use tabs there.

    Inevitably though, there will be developers on your team that just don't care enough to get this right. They'll use tabs and spaces wherever they want and as long as it looks right on their screen they donot see the error of their ways. Pointing out these flaws usually get

  • I did an experiment once replacing tabs with spaces in the linux kernel and the directory size grew by approximately 25%. This is significant - think about git grep for example and being to keep the source tree in memory vs having to hit the disk. In pathological cases 25% size increase implies manifold performance hit.

You can be replaced by this computer.

Working...