The fact the the answer with fewer votes is actually first is testament to that: why should the asker get a special power i. Active Oldest Votes. Spaces A tab could be a different number of columns depending on your environment, but a space is always one column. Your second paragraph is wrong; the answer is 4! Daenyth - perhaps if you are using a curly-brace language.
Everyone can set it to his taste and be happy. Show 8 more comments. Tabs Now, of course, consistency matters more than either one, and a good IDE makes the differences negligible. That said, the point of this thread is to be a holy war, so: I prefer tabs: They're a character specifically meant for indentation They allow developers with different preferences in indentation size to change how it's the code looks without changing the code separation of data and presentation for the proverbial win!
It's impossible to half-indent something with tabs. So when you copy code from some website that used 3 spaces into your 4-space indented file, you don't have to deal with misalignment. What about copying that 3-space indented code into your tab-indented file, which you have set your tabs to 3 spaces? When you send your code to your compatriots they wonder why that function has such bad indentation!
Tabs are not originally meant for indentation, they are meant for tabulation , and do a dreadful job at it Timwi: Wikipedia seems to say that they are meant for moving the cursor to the next of a set of fixed columns. Doesn't sound like tabulation was the primary function. Also, I was referring to the post-typewriter era. Check for yourself. Another benefit of this approach - fewer keypresses when using arrow keys for left-right navigation.
Show 13 more comments. Peter Boughton. Yes yes yes yes yes. One hundred percent yes. This lets everyone set their own tab width while preserving tabular formatting. If you're worried about keeping within 80 columns as you probably should be! Honestly, is this so difficult? Yes, but don't use spaces to line up within a line. Your colleagues may be using a proportional font so your ASCII art is going to look weird on their screens. Add a comment. Tabs allow mistakes to be more noticeable , it's annoying to micro manage to spaces.
Spaces should be used where tabs are completely useless. Perhaps that you need to upgrade :p? MaR: Noticable mistakes is true, the width of a tab is larger. Tabs are consistent as a single Tab is an indentation, while you otherwise have to define how many spaces you will use for an indentation.
Customization is an advantage. You are using tabs in the first place, so it's more productive. Seems you can't even give a good reasoning why it is impractical, haters gonna hate TomWij: How is tab larger than equivalent number of spaces? Python is virtually the only language that got whitespace right to use tabs safely but still - it offers only little advantage compared to "insert spaces". MaR: Where did I state 'equivalent number of spaces'?
I've tried all those, tabs work perfectly in them! All of the arguments for tabs are great in theory. In theory, practice and theory are the same. In practice, they are not. And in an ideal world it would In reality, you can't see the difference between spaces and tabs, they always seem to get mixed up when moving code around, and viewing the code in another program that has tabs set to 8 columns is a nuisance.
Every editor has a "show whitespace" option now, and Visual Studio has a 'tabify' option — Chris S. Good argument. That's the reason I gave up on trying to convince people that tabs are more logical. Even programmers who should be used to abstract thinking seems to confuse tabs and spaces "if it looks like four spaces, then it must be four spaces!
The nail in the coffin for me was that it seems to be impossible to configure Emacs to indent only with tabs. It is too easy to silently do the wrong thing with tabs. I used to use tabs too, but I was running into trouble with some IDEs that couldn't insert spaces for continuation lines and I hated to replace all those auto-inserted tabs with spaces Visual Studio was one of them.
So I just sticked with spaces. Some relevant opinions that may be of interest: Guido says spaces Joel says spaces Atwood says spaces Zawinski says spaces, sort of. Just because you're famous doesn't make you correct. Xepoch: have you read their rationale :? Matthieu M. I don't like olives either but doesn't make me wrong because others do. I find it ludicrous that people wouldn't use the tab for indentation, but this is why they call them CS holy wars Xepoch: yes, I suppose everyone is entitled to one's opinion : I do think though that Guido has pointed the main issue: mixing tabs and spaces is evil, because both appear as "blank space" to the user.
Fishtoaster: When you say that Joel says spaces, shouldn't the link be to an actual Joel quote? The link just goes to the JoelOnSoftware forum where some ppl most likely not speaking for Joel discuss tabs vs spaces.
Show 2 more comments. Tabs for the win. Joel Barsotti. Unfortunately I'm the minority. You are inefficient at keyboard code browsing. So indentation wouldn't matter.
Tabs are called tabs tabulators because they were invented for tabulation, not indentation , and they do a dreadful job at both. Lorenzo: You are inefficient at keyboard code browsing. You should use w and b or e and ge to skip through whitespace and tokens :P — R. Martinho Fernandes. For the sake of devilish advocacy: don't inflict badly-formatted code on editors that you consider inferior. Use tabs. Timwi: sorry to necro, but the computer tab key was NOT invented for tabulation.
Your argument is akin to claiming that the computer return key was intended to start a new line and move the cursor to the far left, because that's what it was for in a typewriter : — Beofett. Show 7 more comments. That breaks as soon as you start indenting for anything other than statement nesting. For example if you want to align function arguments on the same column, one per line. It's possible by mixing tabs and spaces but very tedious. It's not tedious at all, since it means you can tab most of the way there and then just use a couple of spaces, rather than having to type dozens of spaces just to get to the right column.
If you have non-whitespace chars to the left of your first argument, there's no way to guarantee arguments on subsequent lines will align for everyone. You've never tried writing HAML, have you. VivekGhaisas No, I still don't rue the day. Show 11 more comments. When I contribute to a 3rd part project, I follow their standards When I create my own stuff or bespoke solutions for clients and project I am responsible, I use 4 spaces so it will be have better visual ergonomics in different IDEs, code editors, monitors, and for people with accessibility issues including myopia, bad lighting, artifacts because of ageing, etc.
Celso Bessa Celso Bessa 5 5 silver badges 9 9 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Does ES6 make JavaScript frameworks obsolete?
Podcast Do polyglots have an edge when it comes to mastering programming Featured on Meta. Now live: A fully responsive profile. Linked Related Hot Network Questions. Question feed. Stack Overflow works best with JavaScript enabled. Accept all cookies Customize settings.
The second is on whether our indents should equal 2 spaces or 4 spaces. During Intro to Programming, we indent our code 2 spaces and use tabs instead of spaces for indentation. The default tab size in VS Code is 4 spaces so we need to update it.
You'll see an Editor: Tab Size option which you can set to 2. Let's take a look at what good HTML indentation looks like - and then we'll look at an example of poor indentation. This is common convention to save space. As our code gets more deeply nested, there can be a lot of empty space in our code editor and eventually our code will end up running off the screen. This is why we are proponents of 2 spaces of indentation instead of 4 - to save space in our code editor.
As we mentioned in the last lesson, this has two benefits: it provides better accessibility for screen readers for the visually impaired and it makes it easier for browser translation software to translate our HTML into other languages. We should make our sites more accessible if possible and this is an easy step we can make in that direction. Now let's look at other examples of indentation in the HTML above.
We've found that some students are confused about this at first - and here's a common mistake we've seen from beginners:. This is called a comment. Most coding languages have the ability to add comments. Comments are messages for humans to read - the machine ignores them so they don't get run as code. In general, your code should speak for itself. That means you don't want to have too many comments.
However, they can be very helpful. We won't worry about other languages yet, though! There is a shortcut for commenting code out in VS Code. This will comment out the code if it's not commented and uncomment it if it is commented. Also, VS Code will automatically use the correct syntax for commenting for the language you are using. Let's get back to indentation.
We've looked at an example of good indentation and one common mistake that beginners make. Now let's look at an example of bad indentation.
0コメント