0

In the page at http://pear.php.net/manual/en/standards.indenting.php, it is advised to use space instead of tab as it causes issue with diff, patches. Here is the excerpt from the page.

Use an indent of 4 spaces, with no tabs. This helps to avoid problems with diffs, patches, SVN history and annotations.

So, my question is if we are using tabs everywhere, how it is going to affect these commands?

3

If you are rigorous about using tabs everywhere in the project, then it really won't affect the command. Usually the issue is mixing tabs and spaces.

If you mix tabs and spaces, you have to deal with two lines looking identical to humans but being different in regards to tools like diff:

if(i == 0) {
    do something;

and

if(i == 0) {
    do something;

The reason people avoid tabs and prefer spaces is that tabs display according to editor settings, so one developer writes this:

for(i=0; i<10; i++) {
    do this;
    do that;
    do it again;
}

Another guy comes along with tabs set to two instead of four and makes an edit:

for(i=0; i<10; i++) {
  do this;
  do it different;
  do it again better;
}

The other guy opens the code and it looks like:

for(i=0; i<10; i++) {
    do this;
  do it different;
  do it again better;
}

Multiple by ten developers and the code quickly looks horrid for everybody. So someone "fixes" it, and then your history is full of things like this:

for(i=0; i<10; i++) {
    -do this;
    -do it different;
    -do it again better;
    +do this;
    +do it different;
    +do it again better;
}

Someone coming along wanting to use blame to figure out what developer to talk to about doing it different can't, because the log is full of formatting fixes.

Then someone gets the bright idea to change all tabs to spaces, and then a diff shows the entire file as having been changed.

Best to avoid the issue with spaces instead of tabs. This avoids issues caused by someone hitting spacebar four times instead of the tab key.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy