Soft Tabs vs. Hard Tabs

0 Comments

Published: 1:09pm September 28th, 2011
Updated: 1:36pm September 28th, 2011

There's an ongoing debate amongst developers as to which is better: soft or hard tabs. Why does this matter? In a collaborative work environment everyone needs to use the same kind and size of tabs to avoid messy differences between different peoples' code. Many argue that soft tabs are the best solution. Here's my argument on why hard tabs are better...

Why Soft Tabs?

Soft tabs, or tabs made up of space characters, are often argued as better to use when collaborating with others because a space is a space is a space. From one OS or coding editor to another, spaces are always the same size. If you use a tab size of 4 spaces, each tab will always appear the same for everyone in any text editor (depending on font, of course).

However, it means that everyone has to agree to use the same size of tabs. If we don't agree on the same tab size, we can end up with a mess like this when we start mixing our code together:

Sure, you can set a coding standard and require everyone use the same tab size and everyone can set their tab size accordingly in their text editor, but that's a bit of a hassle. And what if I work on different projects for different organizations that each like to use different tab sizes for their coding standards?

Why Hard Tabs are Better

A tab is a tab is a tab, regardless of software default settings are or a given coders' preferred tab size. If everyone uses hard tabs, indentation will be consistent throughout the code and everyone can use their preferred tab size.

For example, here's several lines of code using hard tabs with a tab size of 2:

Here is the same code with the tab size changed to 4:

There's no way to end up with mixed indentation within one code file. Each line is always indented by the same number of tabs all the time.

If you have a strong argument for why soft tabs are better, I'll be glad to hear your comments.

ShareThis

Leave a Comment