Why 4 spaces instead of tabs
Viewed k times. Read this first — finnw. Whatever you choose, it must be used by the whole team but not when one uses tabs others spaces. The edit was removed, but hopefully this comment will remain: Instead of indentation characters, why not use the left-margin instead?
I really don't think there should be an "accepted" answer here. 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.
Using indentation in Python allows you to avoid using braces or keywords to set sets of code apart. Most people new to the world of coding fail to realize that indentation is more for the interpreter and less about the structure of the program itself. When done properly, the indentation will give the reader of the code a level of comfort and understanding. If a code is properly broken up, it will much easier to comprehend. By writing code that is easy to review, a programmer can make an impression on prospective employers and increase their earning potential at the same time.
Felipe analyzed , GitHub repositories, 1 billion files, and 14 terabytes of code to determine why spaces might be actually better than tabs. While indentation is paramount when attempting to write readable and appealing code, there are a number of other best practices you should follow.
Below are just some of the practices you need to get accustomed to using. With the technological advancements in the world of integrated development environments, commenting on the code is more useful than ever. By following industry standards when developing these comments, you will allow other tools to utilize them in a variety of different ways.
While meeting deadlines is one of the things you will have to focus on to become a great programmer, you need to avoid skipping vital steps. The first thing you need to do before writing any code is to think about the architecture of the program you are working on. Failing to do this can lead to big problems in the long run. Knowing what your code will be used for and what programs it will be working with is vital.
With this information, you can write code that is both effective and bug-free. Writing code that is overly-complex can cause major problems when it comes to the functionality of a program. By focusing on writing simple code, you can make it much easier to avoid bugs. Your code should get right to the point rather than using a ton of abstractions.
Getting in the habit of writing simple code can benefit you greatly as you try to rise to the top of your industry. While there are situations where code reviews can be beneficial, there are times when it can just be a headache.
The only way to properly utilize this tool is by working with a developer that understands your codes and can monitor the updates it needs. The main goal of a code review is to maintain the quality of the programming being done, not to teach new developers.
Still funny. Spaces is the right answer, no matter what. Most languages are multy-platform. Spaces looks same on any platform and this is not the case for tabs. Just accept it. With spaces though you have different developers who use different numbers for each level of indentation.
With tabs one tab is always one level of indentation. The title of this blog is in no way shape or form clickbait. Click bait would be:. Learn how he increased his salary with this one little trick! This is a brilliant study idea, but you should modify your result to only apply to the sampled. I would have expected better from stackoverflow. There is no reason given in the article to explain why. Correlation is not equal to Causation. Yes, they even say that in their post. They have no idea why it is, it just is.
It says Correlation is not Causation in the conclusion. Add a new question on to the survey for next year asking if developers limit character length of their lines to 80 characters. Then see if this correlates with space-use.
They are to be exiled to a horrific world where the only language available is PHP and the only editor is ed. If it were worse than PHP, they might give up. PHP is just barely viable enough to entice them to keep going, thus prolonging their suffering. Both is not the same as mixed. Using both tabs and spaces is not the same: I use tabs for some languages, and spaces for others. I never mix the two in a single document. At Cratejoy, we use spaces in Python and tabs for Javascript and Less but we never mix tabs and spaces in a file.
I use both tabs and spaces, because I use tabs for some programming languages, and spaces for other languages — but I never mix them: never both in the same document. Mixing tabs and spaces implies using tabs and spaces within the same document and indeed, sometimes on the same line. I like think most people reading this would see it the opposite way and as a great example of meaningless correlation between what comes down to stylistic preferences in most cases.
It is my opinion that the title is the opinion. The data sample is flawed in that his sample was chosen in a way that has a misleading trend that fits the title of the article to make it look like the correlation is the cause, when the statistic says more about his sampling techniques than it does about who gets paid more.
For example, only people who knew about this survey or visited a certain site or subset of sites were surveyed. Er, what sampling techniques are you referring to, exactly? The sample is the set of people who took the Stack Overflow survey and answered that question.
More experienced programmers: 1. The linear regression included both programmer experience and tabs vs spaces, so the effect exists even beyond programming experience. So while anyone who prefers spaces to tabs can take code with tabs and instantly convert it to spaces, or make the tab distance equal to two or four, or whatever spaces for readability with a single keypress, someone who prefers two spaces per indent level will have a harder time making code with four spaces per indent level readable to him or her.
Because you are an experienced programmer, you know how to set your IDE to do these tricks, but an inexperienced programmer does not or does not value doing so. The article makes no claims about the technical merits of tabs vs spaces.
It just points out the existence of a correlation. I used to be a strong tab supporter. Want 4 spaces, 6, 8 spaces? Then I joined teams where the 2 were being mixed all over the place. It took me 5 years to realize the importance of this. Are you saying you literally press the space bar for indentation? Haha, of course not. Some using actual tabs, others using spaces.
A tab key gets converted to 4 spaces. So you get space characters from tab keys but that also behave like tabs on backspaces too. This is especially nice for python, my go-to money maker. If you want tabs to look like 4 spaces, you can set that.
If 2, you can set that as well. He discovered that was a problem in files that mixed tabs and spaces because how your IDE renders tabs might differ from how many spaces someone inserted. If everybody uses spaces and not tab characters, the file will render the same for everyone.
My hypothesis: Somebody who touts their use of spaces is more likely to exaggerate their reported income. It sounds pretentious. Like, meanwhile, children are dying in africa, stop using your computer and do something about it.
If your job is not in health, teaching or food making, you are useless, so you should stop wasting your time. Mah gawd you guys, who cares?
If we put this kind of scrutiny on the SO data scientists, imagine what kind of scrutiny we could put on what YOU do all day, such as…. The majority of the devs on the frontier of new languages, and language research, use an editor like vim.
To be sure. In 30 years, vi will 71 years old, and vim will be 55 years old. All of us are hoping for better, more functional tools in that timeframe. Everything else happens in another window at a shell prompt.
When I need to make anything else more efficient, I update my command-line programs. Well, actually it depends on what you value. If you want something feature rich, an IDE might be objectively better. If you just want to edit a few lines of source code, the small editor which is just an editor might be objectively better. Yeah right — like we need to memorize a zillion keyboard shortcuts to do the most obvious stuff!! Keeping up with tech is tough as it is, we need our memory for more important stuff.
I suggest the ones using spaces might be largely the ones who believe they are better and have higher standards when negotiating a salary. Which is not necessarily a bad thing. Developers who cannot extrapolate full solutions from limited information.
Funny, a few days ago, I would have found unbelievable that someone would actually think of tabs as the tab key. It also bends my mind that some people fail to understand that the ambiguity inherent in using tab characters is the very reason why space characters are strongly preferred by anyone capable of thinking logically.
That ambiguity is a feature of tabs, not a bug. Those of us that like compact code with two space indentation can coexist peacefully with our coworkers that use 4 space tabs. As long as tab characters are in the code it is just a editor setting and both groups can be happy.
Even that one weirdo that prefers 8 spaces per tab can do his thing without bothering the rest of us. Fixed it from average to median.
Though the argument still stands either way. The volume of low salary developers who cannot make the distinction brings down the median. Salary aside, I was a tabber for decades.
And it was the predominant coding standard at many of my employers and clients. Then one day my friend and colleague Doug Y. That tiny little piece of wisdom was my Road to Damascus moment. There is a bit of throwback in it. Tabs are faster to type, and IDE replacement is relatively new. Tabs are also a single character, and code files not having to count bytes is also relatively new. There is a lot of lag between the professional world moving past a paradigm, the educational world adopting that change, and the post-change students getting into the workforce.
How much relative? VB6 IDE is even smart enough to understand where the level of indentation ends and add only the correct amount of spaces…. I say this from experience both as a student coming out with 30 year out-of-date habits that I had to get rid of, and having trained several recent grads out of their school-taught habits that were based on green-screen limitations. But we are talking about the present and in the present, nobody is required to hit the spacebar 4 times for each indentation level.
Even if you are working with such an old language because you can use other editors instead of those IDEs. Contrary to popular belief, you can learn about obsolete things. My high school was teaching us to use computers on green screen terminals in the late 90s. I also worked as an adjunct professor for a while, and as part of the IT staff for a college, and with IT professors from 5 other universities. As for the present, no one is sitting over your shoulder telling you to change your typing habits.
Yes, nobody needs to be over your shoulder telling you to change your typing habits, because it is not needed anymore.
Programmers that get paid more are more likely to be required to use spaces. I have never worked at a large company with a coding standard that requires tabs over spaces. I have used tabs only during the course of my graduation where everything works and looks good.
The real world requires you to use spaces. People using tabs work at larger companies and therefore make more money. And of course that was a typo…. Company size seems to have been controlled for though.
So, developers who know the difference and care about the NEXT reader of their code use spaces to preserve their formatting across tabstop changes. Most people in office environments work with a mandated IDE, eliminating the tabstop change question.
That said, companies that allow diverse environments or working from personal equipment might pay more but require spaces for that reason. This is all self-reported, yes? What if the conclusion is spaces developers are just inflating their salaries by 8. I think the survey could have been poorly developed. Those in the beginning of their careers might not understand or even know that the IDE can change the tab key output to spaces, which could explain the lower salary.
They tend to only do what they are told. My theory is that creative people tend to earn more and changing the default configurations could have correlation in this data. Or they could know what the IDE configuration is, but assume the question is about which key they press. Also, there is no technical difference between using the key tab or the key space making it irrelevant for a survey, while there are technical differences between the character tab and the character space such as filesize and indentation of lines of code written in more than one actual text line or languages without a clear indentation pattern like SQL.
The only difference the actual character makes is in display across multiple IDE configurations. And that actually benefits tabs unless someone goes along typing spaces sort of like someone shoving fixed-width objects in the midst of a variable width HTML page. It is treated as a factor in the present and that is what matters for a survey about the present. Like I have nothing better to do all day long than correcting code that starts in columns that are not multiples of 4….
Most IDEs nowadays will have an automatic document formatter. And for those of us not using IDEs — anyone with any technical competence can run a CL linter, autoformater, or bang out our own script in a few minutes to address the issue permanently. Nutarama, must be a really old language, then. I had this issue in the past. My first code that went on to be compiled and executed with a runtime error was FORTRAN written on paper, which then went to card punchers, who created the card stack, which was then fed into the specialized reader.
For maybe 30 lines of code probably less — it was a very long time ago it then produced several tens of printed pages, on special paper used by dot matrix printers. Sometimes its actually better to use vim or emacs, even if you have to write your own extensions to replace missing IDE functionality. To a large extent, those are IDE configuration issues. Some people must do a lot of their work on a remote server, and use vim, emacs, or similar over the terminal.
Others are using less popular languages for which the best working environment is vim or emacs. There may be no IDE, or it may be under developed. Eventually these languages may get high quality IDE support, but until then…. I forced myself to learn eclipse and now intelliJ.
Also, you can consider the long term benefit of the time invested mastering various tools. Languages and IDEs come in and out of fashion, and sometimes evolve quickly.
Teachers who emphasize good coding style are more likely to emphasize the use of particular spacing and thus passively suggest using spaces instead of tabs than teachers who do not emphasize good coding style. Students who had the former teachers will generally have better style, apart from space usage, than students who had the latter teachers.
Also, students who had the former teachers are more likely to use spaces than students who had the latter teachers. Students with better style regardless of space usage will earn higher salaries, so a correlation between space usage and salary will appear. Personally, good coding style was a major emphasis in my first computer science Java class. We were taught to use four spaces to indent each line.
I started off using spaces, but later switched to tabs. If I need to submit code with spaces, I will write the code with tabs and then Replace All tabs with four or two or however many space characters and increase the file size , or configure my IDE to do this automatically. Other than space usage, I am very persistent on style and will fix the style of code I receive before I read or compile it. Look at hiring habits, though. You might be right that it is based on the institution, though.
Graduates from well recognized universities or those with good placement programs have a better average salary than others, regardless of the quality of the particular program. They just want the code to be delivered because the client is waiting for it. My hypothesis: The element of tradition in education plays a role, i. Call it genealogy of mentors. But how many of those space devs are required to use spaces because of code style guides at their respective companies?
Regardless of whether or not they choose to use spaces on their own. Code in Go is autoformatted with tabs by convention, and a large majority of open-source golang code is autoformatted with tabs this way. Or only very few people answered go and spaces, and so the sample size in that specific case is small.
I assume language choice was a multi-select option? Might be interesting to correlate of languages selected rather than treat each individually. And little Space users. Dude did you even read the article? Years of coding does not necessarily track perfectly with age e. That would still rest on the assumption that older developers did not have the tab character available to them. It being part of the original ASCII set, which goes back to the s, so this is so unlikely as to not be worth mentioning.
The best paying companies usually mandate that you should use spaces. The whole spaces and earnings thing is one giant fallacy from the ground up, mixing up the cause and the effect. IME, they mandate it because furniture police. They could as easily mandate using tabs exclusively for indent — a style checker can warn of mixes on commit.
More often than not, very senior developers prefer tabs, not because it adds any stylistic or technical value, not at all because it saves a few bytes on disk, but simply because it makes sense.
In a given editor, a tab has always exactly the same width. It happens to me repeatedly that upon code reorganization the IDE mixes up indentation, and unless I want my whole file reformatted like all javadoc comments messed up I need to fix this manually.
Using spaces for indentation is simply a dogma that has caught on among enterprise developers. Of course, mixing tabs and spaces is plain stupid, but if tabs for indent proponents can do the mix, so can spaces for indent proponents do it. Read the comments a bit more. Many people are actually making that assumption, very seriously. The IDE does it automatically for you. This is indeed talking about typed spaces.
Adaptable tab size does not refer to your keyboard! Text editors can edit any text in the world, in any language, and you can control indentation of your text editor. Considering the comments here, the two of us may be demonstrating the divide. The benefit of space characters is that tab characters adapting to the display preferences of the individual programmer suddenly look weird when one idiot presses the space character a bunch of times instead of using tab.
In an exemplification of the eminent flexibility of tabs, this is easily resolved with a. Then you have to use mixed tabs and spaces, and you will only cause pain for any other developer who tries to edit your work. I specifically set up my IDE to use spaces. It would be utterly braindead to hit the spacebar multiple times at the beginning of each line.
But any modern IDE only requires you to do it once or tab once for each layer of indentation you want. Gonzol, that is the reason why I think the survey may have been poorly developed. The whole point between tabs or spaces is the character and not the key pressed. Basically there are these two arguments:. Having varying lengths of tabbing seems like it would be harder to read. If ever something inside a pair of parenthesis needs to be broken into multiple lines, just break everything instead.
If you would need to break and there are no parenthesis yet, just add them. I prefer to use a brace style which does never need alignment on keywords identifiers. So if you need to break an argument list, everything gets on a new line, and then is just indented with tabs, no side effects. If the style guide does not permit that, indent with tabs according to the current indentation level, and then use spaces to match the length of the non-tab characters in the previous line. CreateNewAddress city, state, zipcode, streetaddressline1, streetaddressline2.
CreateNewAddress t city, state, zipcode, t streetaddressline1, t streetaddressline2. Yes, that is two more lines, but the indentation is unambiguous. Also non of the lines is even remotely approaching the length limit. For the other option, the additional indentation to match the parenthesis only with spaces. In front of the spaces all the tabs used on the parent line.
So effectively:. CreateNewAddress city, state, zipcode, ttt ………………………………………………………streetaddressline1, ttt ………………………………………………………streetaddressline2. Everyone knows what their editor is outputting. Apparently not considering the number of people saying spaces are slower.
And I would expect people without that experience to not be pulling as high of a salary. People making that comment clearly believe the question has to do with what key is being struck, not what the IDE is producing. The slightly more hollow sound of the spacebar hit hard with the knuckle of a thumb several times in rapid succession is easy to tell apart from normal typing.
If your spacing is consistent which, frankly, it should be , then you can change between tabs and spaces arbitrarily with no significant effort. The problem of arcane legacy code is the changing coding conventions of the past developers, not whether they used spaces or tabs. It makes sense they would on average be paid less. This is true until you hit version control, where tabs and spaces are taken into account by default. Exactly this. Mixed tabs and spaces cause version control issues, and create non-obvious, and impolite indentation issues when multiple devs work on files that contain them.
In every IDE I use, shift-tab goes back an indentation level while backspace removes the previous character. What IDE are you using that overrides backspace to indention level? I have all manner of shortcuts. The difference in salary here might correlate to developers who understand their tools, vs.
Configure your editor right and there is no extra time. Also, spaces maintain consistent visual styling across development tools. Code and data are here, try it out!
And, dare I say it? I am moderately sure that what one calls it makes no difference to how using tabs at various tabstops vs. Use an IDE that will display code formatted however you want it and save it formatted according to whatever code style convention is in place.
Or use a pre-commit hook to format it. Arguing over tabs vs. But then, if I fork it, and my editor changes the formatting, the merge will overwrite random bits of code all over. Depending on the editor used, tabs get expanded into 4 or 8 spaces typically.
So, tab-indented source code often shows up with unintented indentation — really ugly. I made pessimistic assumptions in order to demonstrate the robustness of your result, not to criticize it.
Most people clicked it even knowing it is a clickbait and that is where you win. Good job. Maybe I was too harsh in using the word clickbait, but the thing is that it was an interesting marketing move to connect salary with some specific polemic topic. But it is a smart way to promote the survey itself. Because it is assuming your typing habits could influence how much you earn. If you want to know the real reason behind this, you should isolate the money variable and start checking everything else.
You tell me why relate money to a typing behaviour is logical. It is not logical. It is marketing. The only logic applied here was that it is an obvious bait for people to click in the article and comment about it.
And yes, I was caught by it hehehe. Because many people are just using tabs, and they are not aware of the fact that tabs can be composed from tab characters vs space characters. I expect groups 1, 2, 4 to answer tabs.
Because of not knowledgeable people in group 4, since we can assume not having knowledge about an arbitrary topic statistically decreases the expected wage, tab answer will have a lower average wage. No, tabs are composed of tabs. They are asking what is in your file. As chipoverclock:disqus remarked before me, tabs have to be rendered, spaces do not.
This one time I beautifully formatted code in my IDE with tabs, which were the width of 4 spaces in my system. As soon as I uploaded it on gerrit, its ugliness was pointed out to me and I soon realised that because gerrit was rendering tabs as 8 spaces, none of my secondary indentation had any effect anymore.
Do not use tabs to separate pieces of code horizontally to a specific amount. I guess people who have abandoned tabs are the ones who were quicker to realise this than their counterparts in the same experience bracket.
Just for the people reading this, he did not just say yes to a random stranger: I am not a troll, I am his girlfriend. Leading whitespace tabs, internal line whitespace spaces, this keeps your formatting and allows your editor to size the tabs how ever it is configured. And is a complete PITA for anyone else to work on ever.
Only do this if you live in a silo, and have no Github account. Not with an. Every project has its own requirements, this is just one of those. Some projects may use tabs and some projects spaces, being able to manage either is more important. If I had to choose it would be leading tabs, allowing display choice for each developer.
If I have a multi-line comment to the right of two lines of code i. Not to mention the PITA of changing your tab stops on all your different tools. Thou shall not have a multiline comment to the right of lines of code. Or stop all this commenting trend, let the code speak by itself in freedom and glory!
If you follow these rules, you will be able to: — use tabs or spaces and nobody would care — change tab size as you like, for better reading without beeaking indentation — convert tabs to spaces and viceversa without problems. Jokes apart, code should be formatted in such a way that it really would not matter even if you edited it with non-fixed size fonts. As for where they go, comments should go where they make the code most readable.
Making readability a second priority to solving technical issues that arise because you want to use tabs instead of spaces is utterly misguided, IMHO. Sincerely I think that someone that uses spaces because are more portable should comment in a portable way too. And usually the main thing driving them to this mistaken idea is their lack of experience. Well, have fun with that. At least there is no minus button here! I agree with you that there are no fixed rules and I totally agree with you that assembly does require this kind of commenting, and yes, no tabs there.
For the remaining Peace and love. Tabs as leading white space only, all other alignment spaces. Most editors allow you to set how wide a tab is, 2, 4, 8. Any thing else would be multiple lines with single line comments. Note that the tabs are not a fixed width themselves; with a tab stop at column 5, a tab character in column three is replaced by two spaces when rendered in a fixed font, whereas a tab character at column 2 is replaced by three spaces.
And therein lies the issue. Consider two lines: Two tabs, two printing characters, six spaces, two printing characters Three tabs, two printing characters, two spaces, two printing characters. With tab stops set at every fourth column, the second set of printing characters lines up on column With tab stops set at every second column, the second set of printing characters starts at column 13 on the first line and column 11 on the second line.
In your example I see where adjusting tab width could misalign items, but your example is trying to align internal line items across two lines that have different leading whitespace indents. This seems like arbitrary alignment and ignores the natural grouping that the indent suggests, where I believe only aligning items within their indent groups is reasonable to support.
You could change the third tab on the second line to spaces, which in itself suggests it is being aligned to the first line, I do this sometimes, however, I can see an issue where tools that modify leading whitespace from tabs to spaces or spaces to tabs might modify those spaces as well if they happen to match the current tab width.
Are you saying that those apparently incompetent programmers who use tabs are all developing under notepad? He says straight out that code does not become better by using spaces nor worse by using tabs. I prefer spaces over tabs. Most editors convert the Tab to spaces, so developers basically indent pressing the Tab, but that just creates e. No one is bashing the spacebar. So if I was asked what do I use — spaces or Tabs I would be confused, and I guess a lot of people did answer spaces because the end result is space indented but they do use tab to do it.
You hit enter and it will go to the right level. I think any language that requires tabs is not part of the discussion. They reward the sellers who could sell a product that is still not finished and then make us do extra work because the product was already sold.
This is it. Anyone who knows their tools pretty quickly figures out how to make tab insert two spaces. Anyone who operates in a team pretty quickly figures out that tabs help other people to read their code, and cause fewer issues with source control. Yeah, but that knowledge is generally due to somebody pointing it out and then going looking for it. Yes, I remember when it was first pointed out to me.
The fact I was, and continue to be, in environments where I learn these things probably at least for me correlates to the direction of my career. My experience is exactly the opposite. Tabs are variable when viewed with other editors. Almost every place I have worked in the last 30 years has forbidden their use. I have a variety of rc and config files that I use to customize whatever editor a customer or employer uses.
The one place that insisted on tabs failed. OK, you win. My editor indents my code automatically. I only need to use backspace to delete indentation. And there is the problem with spaces — with tabs you only need to press backspace once in most editors and it just works. Did you check age? Salary may be different because one style was popular at a different point in history, so a different generation adopted it. If you need to further align code like lining up equal signs you would just use spaces here, no tabs or mixture of tabs and spaces.
This way the code will always carry both the indentation and further alignment properly between editors, and has the added benefits of user defined tab widths and slightly smaller file sizes. Code blocks unfortunately lose spaces in Disqus, but in your editor try: if something A long explanation other thing on these lines. Mixing TABs ans spaces. I use TABs, and my comments are either single line or stay below or above. Multiline side comments are totally ugly! I just found out that Mr John Daring Fireball uses tabs and that just makes me seriously happy that I use spaces.
I think you misunderstand the question. As far as I can see tabs use one character code wheras 4 spaces use 4. So a tabbed file will be much smaller than a non tabbed file, so tabs rule.
You can have blocks of code be much deeper than that I once had a for loop end up seven indents deep. If you typed code all day, every day, for ten years, you might save a couple of megabytes by using tabs over spaces. Text files are not that large compared to say, image files, or video files. I have been coding for years but I find it easier to press the tab key rather than the space key four times.
Spaces look the same size with a fixed-width font no matter what program or page you view the code on. This exactly. There is no standard tab width, which causes all of your carefully aligned code to look horrible if it is using both tabs and spaces. Tabs were invented to try to trim a few characters for files sent over the phone line.
Not relevant anymore. Someone using tabs for indent will never mix tabs and spaces. Just like someone using spaces for indent will never mix tabs and spaces. All the time.
0コメント