Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the TAB character bad in source code? [closed]

Tags:

I'm pretty familiar I guess with both Zend and PEAR PHP coding standards, and from my previous two employers no TAB characters were allowed in the code base, claiming it might be misinterpreted by the build script or something (something like that, I honestly can't remember the exact reason). We all set up our IDE's to explode TABs to 4 spaces.

I'm very used to this, but now my newest employer insists on using TABs and not spaces for indentation. I suppose I shouldn't really care since I can just tell PHP Storm to just use the TAB char when i hit the Tab key, but, I do. I want spaces and I'd like a valid argument for why spaces are better than TABs.

So, personal preferences aside, my question is, is there a legitimate reason to avoid using TABs in our code base?

Keep in mind this coding standard applies to PHP and JavaScript.

like image 535
Maverick Avatar asked Feb 10 '12 17:02

Maverick


People also ask

Which is better tab or spaces?

Tabs Debate. Pro-spaces programmers argue that using the space bar makes the layout more flexible. However, pro-tabs users rebut saying tabs makes code more readable and aesthetically pleasing.

Should I use tabs in code?

The analysis performed by the team at Stack Overflow found that programmers who use spaces instead of tabs are making more money. David Robinson, the data scientist who performed this study found that programmers using space over tabs made an average of 9 percent more each year than their tab using counterparts.

What does tab character do?

A tab character defines the space between two document elements. For example, you can separate numbers from list items, or columns of text, by using tabs. You can then set tab stops that define the location and alignment of the tabbed text.

What is a tab in coding?

“Tabs,” reads the counter argument. “ They're a character specifically meant for indentation. They allow developers with different preferences in indentation size to change how the code looks without changing the code” So there!


2 Answers

Tabs are better

  • Clearer to reader what level each piece of code is on; spaces can be ambiguous, espcially when it's unclear whether you're using 2-space tabs or 4-space tabs
  • Conceptually makes more sense. When you indent, you expect a tab and not spaces. The document should represent what you did on your keyboard, and not in-document settings.
  • Tabs can't be confused with spaces in extended lines of code. Especially when word warp is enabled, there could be a space in a wrapped series of words. This could obviously confuse the readers. It would slow down paired programming.
  • Tabs are a special character. When viewing of special characters is enabled on your IDE, levels can be more easily identified.

Note to all coders: you can easily switch between tabs and spaces using any of JetBrains' editors (ex. PHPStorm, RubyIDE, ReSharper, IntelliJIDEA, etc.) by simply pressing CTRL + ALT + L on Windows, Mac, or Linux.

like image 186
user1429980 Avatar answered Oct 19 '22 21:10

user1429980


is there a legitimate reason to avoid using TABs in our code base?

I have consulted at many a company and not once have I run into a codebase that didn't have some sort of mixture of tabs and spaces among various source files and not once has it been a problem.

Preferred? Sure.

Legitimate, as in accordance with established rules, principles, or standards? No.

Edit

All I really want to know is if there's nothing wrong with TABs, why would both Zend and PEAR specifically say they are not allowed?

Because it's their preference. A convention they wish to be followed to keep uniformity (along with things like naming and brace style). Nothing more.

like image 39
webbiedave Avatar answered Oct 19 '22 20:10

webbiedave