Here is why tabs are better than spaces for indenting code. Let’s assume that tabs are set to 4 spaces. When indenting code, it is unlikely that one would want to insert code or select text starting in the middle of a tab. The programmer will most likely want to select at the beginning of a tab or at the end of a tab. When spaces are used, the programmer will have to click in an area that is half the width of a character to insert the cursor before an indent or after an indent. Using tabs, the programmer has 2 character widths where they can click to insert the character. That’s 4 times as much space. Also, fewer keystrokes are required to navigate tabs than spaces (though, some editors can make the spaces act like tabs in this regard).
The only reason I can think of to not use tabs (aside from being anal-retentive) is because different text editors can have different tabs set. However, if you’re consistent with the use of tabs, this should make no difference. If programmer A likes 4 spaces and programmer B likes 2 spaces, they can both do their work the way they want without affecting the other. The problem occurs when one programmer decides to use spaces when the rest of the code is in tabs. This is more of a personnel issue, I think. If the developers can’t agree on a standard then they have bigger problems.
This is mainly a problem in template languages as per the example. A particular example in PHP is where files end in “?>” followed by whitespace. Perhaps tolerable if you’re just printing HTML, but if you’re trying to print an image or other binary, for example, the whole world explodes. And, worse yet, you might not notice until you get phone calls exclaiming “Our PDFs are broken!”.
Perhaps avoided by rigorous testing, but, really, who has time for that?
I hate unnecessary whitespace at the end of lines too!
It seems completely irrational take make it such a big concern, but who really cares about rationality!? We know it rashes us, and we know the their nagging existance will not be silenced until they are removed.
Good to hear other people have the same level of OCD I do.
Wow, I thought I was the only web developer in the ASP.NET world who cared about good client-side code!
It’s too bad Microsoft is so clueless. VS2008’s default setting inserts four spaces when the tab key is pressed, there’s still no minimal CSS auto-formatting option, and .NET’s auto-generated JavaScript is still a hideous mess written by people who think whitespace-laden C# syntax is acceptable for JavaScript. Apparently MVC in VS2010 has some minifying functionality, but I haven’t seen it yet.
If you don’t understand why lean client-side code matters, just wait until next year, when Google starts using file size/download time as part of their search result ranking criteria. When you see all your sites drop a notch, don’t come crying to all the real web developers - we’ll just say “I told you so, web n00b!”
Actually, this is trolling in a way, but it is necessary.
CH comments are sooo many that I just don’t ever seem to be able to read them all. It’s too much. So I end up violating the first-do-a-search rule at the page level.
So, as many may have requested before, I shall repeat:
Please allow some markup in comments and let us hope that commenters who want to say something useful take the additional trouble to use bold, /italic/ or underline
Over a period of time, and over a variety of topics, i estimate that casual comments coming from lazy commenters will have less or no markup (i hope, let’s all discuss this) and so it will be easy to filter comments.
Want some marketing? Here:
Responsible Markup Initiative @ CH blog
Again, the complaint is that there are too many comments to read and many comments without lot of useful content.
Eclipse Ganymede handle very well those issues, it can be configured to remove end line white spaces and bottom of file empty lines.
Also it as a pretty nice eature for auto indenting code.
I use both functionnality on php/PDT projects and they are just fine for me
For sure I use other editors for python, one showing me every tab, I tend to do the same for YAML files.
What I hate is copying and pasting code and there is a ` instead of a ’ somewhere!!! one time it took me a freaking hour to find what was the problem with the quotation!!!
What I hate is copying and pasting code and there is a ` instead of a ’ somewhere!!! one time it took me a freaking hour to find what was the problem with the quotation!!!
yea white spaces are definitely gay for programmers. i know because i iz one. a suggestion is to have a script built into your checkin routine that forces all code to limit spaces between words to 1. if ur gay and dont know how to do this or leik your language doesnt support regex then there is an easy way to. create a recursive function that does a search and replace - replacing double spaces “__” with single spaces “_”. o yea and it helps to be a little drunk when writing recursive code.
What I hate is copying and pasting code and there is a ` instead of a ’ somewhere!!! one time it took me a freaking hour to find what was the problem with the quotation!!!