Monday April 24, 2006 A while ago I argued that you should completely avoid Tab characters in your Java source files. Use spaces for indentation. I won't repeat those arguments here. But even those arguing in favor of tab-indented source files agree that mixing spaces and tabs is evil.
The problem is that sometimes you're not aware that you're working on source with mixed tabs and spaces. This can happen easily if you edit the source files with an editor that has the wrong (as far as you're concerned) handling of Tabs.
To help avoid this you can use a simple NetBeans module I just committed into CVS, under contrib/fixtabs. You can grab the NBM file here and install via Tools | Update Center. I'll submit it to nbextras.org soon so you can get it there later.
Here's what the module looks like in action. If you for example open the JDK JTable class and look at the constructor, you'll see something like this (click for full size):
Ewwww!
When you encounter files like this, you can go to the edit menu and select the action to convert the tabs to spaces. You can also turn off Tab highlighting here.
(Update 4/28/06: I changed this such that the "checkbox" toggle is now in the View menu, along with other view states you can enable and disable, and I moved the Convert action to the Source menu along with other source transformation actions.)
The module is similar to one of my favorite modules (which I guess I haven't described yet) - the "stripwhitespace" module. That module highlights trailing whitespace in the current source file, and lets you remove these. Not only is the fixtabs module similar - it's heavily based on the same source code.
Let me know if you encounter any bugs.
(2006-04-24 17:24:44.0) Permalink Comments [10]
Posted by Jeremiah Johnson on April 24, 2006 at 06:34 PM PDT #
By "mixed tabs and spaces" I was referring to indenting some lines with spaces, other lines with tabs. This is what the JTable screenshot shows. I think most people agree this is a bad thing.
I definitely don't think people who choose to indent using Tabs should be "consistent" and use Tabs instead of spaces to separate tokens within a line.
Posted by Tor Norbye on April 24, 2006 at 07:10 PM PDT #
Posted by Shashi on April 24, 2006 at 09:59 PM PDT #
There is a bug though, and I hope it is not in your module as well. I occasionally run into the problem that I get an NPE when I start NetBeans and no editor file is open, at that occurance I get an NPE in the StripWhiteSpace module.
Iwan
Posted by Iwan on April 24, 2006 at 11:23 PM PDT #
There is a bug though, and I hope it is not in your module as well. I occasionally run into the problem that I get an NPE when I start NetBeans and no editor file is open, at that occurance I get an NPE in the StripWhiteSpace module.
Iwan
Posted by Iwan on April 24, 2006 at 11:24 PM PDT #
Posted by Trond Norbye on April 25, 2006 at 01:20 AM PDT #
Posted by jeremiah johnson on April 25, 2006 at 02:31 AM PDT #
I use emacs/eclipse and have a shortcut to a batch file which strips whitespace.
People who love their sourceCode have common ways of getting things done! :-)
BR,
~A
Posted by anjan bacchu on April 25, 2006 at 07:17 AM PDT #
Posted by kunhua on April 26, 2006 at 07:15 AM PDT #
Posted by 213.140.56.4 on April 27, 2006 at 03:04 PM PDT #