Why does the PSR2 standard require us to use 4 (four) spaces instead of tab?

Asked

Viewed 319 times

5

According to one of the items specified by the standard PSR2 (to which most PHP libraries), we have:

  • Codes MUST use 4 spaces for indentation, not tabs.

I know the pattern exists, but I’d like to know if there’s any special reason.

What’s wrong with using tabs in PHP code?

Overall (even if it’s not PHP), using tabs instead of spaces can be a problem?

  • 2

    The question can be improved, downvoter?

  • Already OS survey of the year past it became clear which is the preference of the staff :D \t tabs tabs tabs tabs

  • It is by preference, there is a page with the votes of the staff responsible for the specification. Some voted "tab" and most "spaces". As far as I know, the "tab" represents the space occupied by a column. In some IDE’s you can set the column width, so the space occupied by the tab will also be changed. With spaces this does not occur, that is, the space is the same of a character.

  • @Filipemoraes I don’t know if it’s just preference. I’ve seen git give inexplicable conflicts on tab.

  • See here the result of the vote, in the section "A.3. Survey Results" or "A.1. Survey Data": https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md

  • 2

    Let’s use \x09 :D

  • Those who did not understand the reference : http://187.7.106.14/Marcelo/org_comp/tableASCII.pdf, Hexadecimal \x09 = Horizontal Tab HT

Show 2 more comments

1 answer

3


Had a vote and decided they would be spaces. Quoting the specification:

Using only Spaces, and not Mixing Spaces with tabs, helps to avoid problems with diffs, patches, history, and Annotations. The use of Spaces also makes it easy to Insert fine-grained sub-indentation for inter-line Alignment.`

Translation/summary: the default is spaces and following the pattern makes life easier, the use of spaces also allows slightly greater control over sub-identation levels.

More than that is just Flame War.

  • What is Flame War (I’ve heard the term, but forgot)?

  • @Wallacemaxters something intended to provoke and instigate a discussion among proponents of opposing ideas. (Ex.: java x c# which is better)

  • 2

    People posting subjective arguments in an infinite, non-productive discussion that never gets anywhere because the initial question does not have an objective answer.

  • See here the result of the vote, in the section "A.3. Survey Results" or "A.1. Survey Data": https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md

  • So, to make it worse, just need to make Flame War between tabs and spaces, and still say that one spends "Menas" memory that the other.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.