Having tab characters in the source code is not a very good coding practice. Static file analyzers like checkstyle can be configured to catch the tab characters as either warnings or errors but that configuration is beyond the scope of this article.
I will however talk why tab characters are bad:
- Tab characters need to be configured with the tab width and different users might choose to have different tab width (some may choose 3 characters, some 5), and thus the code violates the standard coding practice, especially when the code is shared and edited by multiple users.
- The other problem as mentioned in the Apache Jakarta coding standards is that in a ]distributed development environment, when the commit messages get sent to a mailing list, they are almost impossible to read if you use tabs.
By default, when you use your IDEs like IBM Rational Application Developer or Eclipse, the text editors are configured to insert tabs by default. So how do you tell the IDEs to use spaces instead of tabs? Follow the following steps.
Configure your default Text Editors:
Window->Preferences->Editors->Text Editors->Insert spaces for tabs
If you are using Eclipse 3.6
Window->Preferences->General->Editors->Text Editors->Insert spaces for tabs
You might also want to configure your Java Code Style Formatter
Window->Preferences->Java->Code Style->Formatter->Edit->Indentation = "Spaces Only"
Originally posted 2012-05-05 12:10:39.