Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

confusion on coding standards

 
Yan Zhou
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am still confused by Sun's coding standards when it says that a Tab must be 8 spaces. I wonder what is wrong with a Tab being 4 space?

If I have tab being 4 spaces, the first identation takes one tab, the second takes two tabs, and the third identation takes 3 tabs, etc. When it comes to wrapped lines, the second line takes two tabs (i.e., 8 spaces). I do not see how this style is wrong.

If a Tab is 8 space, the third indentation will start at 16th column (two tabs), while the first starts at 4th and the second starts at 8th columns (one tab), respectively. That does not look right to me.

What am I missing here?

Thanks.
Yan
 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I got out of the Java Coding Style Guide:

Indentation

Line indentation is always 4 spaces, for all indentation levels. The construction of the indentation may include tabs as well as spaces in order to reduce the file size; however, you may not change the hard tab settings to accomplish this. Hard tabs must be set every 8 spaces
Note:If this rule was not followed, tabs could not be used because they would lack a well-defined meaning

IMHO, this is to ensure that code is displayed uniformly on different machines. There needs to be a standard number of spaces to set tab to so that everyone can view code. Sun chose 8 spaces so that one tab = two indents. If you need to indent three levels, use a combination of tabs and spaces (/t _ _ _ _)
[ September 24, 2004: Message edited by: Paul Bourdeaux ]
 
Yan Zhou
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If an IDE converts Tab into space, I can set Tab to 4 space and it should be fine because the line indentation will always be four spaces, and instead of typing 4 spaces, I can just hit Tab instead.

Now if the IDE does not convert Tab into space, now comes the question of one Tab is set to 8 space. On the first line indentation, I will type 4 spaces; on the second, I can use a Tab (because typing 8 spaces is boring), and the thrid line, I can use a Tab and then type 4 more spaces (because typing 12 spaces is even more boring). Is this how I suppose to understand the Tab issue in coding convention?

Why did not Sun decide to set Tab into 4 spaces? This is what I still do not understand: why setting Tab to 8 spaces is better than 4 spaces. I think the opposite is ture. With one Tab set to 4 spaces, we can just use Tabs instead of typing spaces. And if all viewers set Tab to 4 spaces, the code appear uniformly wherever it is loaded.

Thanks.
Yan
 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If an IDE converts Tab into space, I can set Tab to 4 space and it should be fine because the line indentation will always be four spaces, and instead of typing 4 spaces, I can just hit Tab instead.
Yep. In fact, I do the same thing. You just need to make sure that tabs are indeed converted instead of hard coded.

I agree that setting tab to four spaces would have been more user friendly. I'm not sure what Sun's reason was for making it eight.
 
mike acre
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yan,

I could not agree with you more, it seems madness.
There must be an underlying reason, but I know not it.

For what it's worth I read the JCS doc to make sure I adhered to it. I found I more or less did already with the exception of what you mention and no space inserted for keyword & parenthesis.

I decided to ignore the tab requiremnt and have tabs set to 4 spaces and I have left them as tabs. Bad me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic