Horde3D
http://www.horde3d.org/forums/

Coding style
http://www.horde3d.org/forums/viewtopic.php?f=1&t=514
Page 1 of 2

Author:  phoenix64 [ 27.09.2008, 16:18 ]
Post subject:  Coding style

One thing about coding style that imho should be changed:

Currently, identation is done with tabs, which is great.
Also, when lines become too long, they are splitted up, and the second line is idented using tabs. This mostly is good as well.

But what really sucks is that this is done with tabs, which means that it looks ok with tabs set to 4 spaces, but looks incredibly ugly with everything else. This is not what tabs are made for!

I'd prefer one of the following styles:

1. Identation with tabs, formatting with spaces:
Code:
[tab]function(arg1, arg2, arg3, arg4,
[tab]         arg5);


2. Identation with tabs, formatting with exactly one tab (does not vertically align arguments):
Code:
[tab]function(arg1, arg2, arg3, arg4,
[tab][tab]arg5);


I'd actually propose to use the former from now on.

Author:  kal [ 27.09.2008, 17:39 ]
Post subject:  Re: Coding style

I propose to drop tabs and use spaces instead :)

Author:  phoenix64 [ 27.09.2008, 18:26 ]
Post subject:  Re: Coding style

"I propose to drop tabs and use spaces instead :)" - yeah, that would be even worse :p

EDIT: The same also applies to comments after variables which aren't cleanly aligned as they should be. Tabs for identing and spaces for formatting is just the most flexible version.

Author:  DarkAngel [ 29.09.2008, 01:30 ]
Post subject:  Re: Coding style

phoenix64 wrote:
1. Identation with tabs, formatting with spaces:
Code:
[tab]function(arg1, arg2, arg3, arg4,
[tab]         arg5);
This is the style I try to stick to personally, so it's my choice.
Just use the tabs to get indented to the same level, and then if you want to do pretty alignment of different lines, use spaces:
Code:
[tab]for( int i=0;
[tab]     i != 10; ++i );

Author:  marciano [ 29.09.2008, 07:48 ]
Post subject:  Re: Coding style

Phoenix, that sounds quite reasonable. Both styles, 1 and 2 are used in Horde depending on the situation for best readability but not yet following the tab/space rules.

I wonder what would be the best way to fix this. Manually is probably a bit tedious. Does someone know some tools supporting that? Probably it would not be so difficult to write one (or even a small VS plugin).

Author:  Volker [ 29.09.2008, 08:35 ]
Post subject:  Re: Coding style

There are two options in Visual Studio, you can convert all tabs to spaces (or vice versa) using the "Edit" -> "Advanced" -> "Tabify/Untabify Selected Lines" and you can change the default settings under "Tools" -> "Text Editor" -> "C/C++" -> "Tabs".
But that means you only have spaces left and no tabs at all. There may be also a problem with whitespaces in constant strings when using the Tabify command. I didn't check this.

Author:  kal [ 29.09.2008, 08:54 ]
Post subject:  Re: Coding style

no tabify works fine
also
http://astyle.sourceforge.net/astyle.html
http://uncrustify.sourceforge.net/

Author:  Siavash [ 29.09.2008, 10:56 ]
Post subject:  Re: Coding style

I have not any problems with coding style because I'm using Code::Blocks 8.02 and it's equipped with AStyle source code formatter plugin and everything is done with just one click !

I don't think that there is any reasons to suffer yourself for coding style 8)

Author:  phoenix64 [ 29.09.2008, 11:26 ]
Post subject:  Re: Coding style

One more comment on this thing: Plz don't just run a script over the whole codebase! I just branched the community repo and would be left with tons of conflicts. because virtually everything changes. Just use the new style from now on. And lets write an official style document.

EDIT: C::B sucks. By default is even uses Spaces instead of Tabs and without any user action involved converts empty lines which makes diffs really unreadable.

Author:  Volker [ 29.09.2008, 12:17 ]
Post subject:  Re: Coding style

At least in Tortoise you can ignore whitespace changes. But I agree, that we shouldn't change it for the whole code base. BTW.: Why not just defining tabsize to 4. Then there shouldn't be any problems at all, should it?

Author:  phoenix64 [ 29.09.2008, 12:34 ]
Post subject:  Re: Coding style

There aren't, but it's inflexible. I prefer my tabs to be less than 4 spaces (2 atm) as it saves space while not having any disadvantage. Others prefer 8 spaces for better readability.

The style I proposed is easy to get used to really.

Author:  kal [ 29.09.2008, 12:42 ]
Post subject:  Re: Coding style

phoenix64 wrote:
EDIT: C::B sucks. By default is even uses Spaces instead of Tabs and without any user action involved converts empty lines which makes diffs really unreadable.

I find it offensive :)
1) Tabs vs spaces... It is not a war. It is just the programmer's choice.
2) Those are options and can be changed. You should always check the default configuration. Some of those should be off by default though.

Author:  swiftcoder [ 29.09.2008, 13:25 ]
Post subject:  Re: Coding style

phoenix64 wrote:
I'd prefer one of the following styles:
What about just letting long lines wrap? Any text-editor worth its salt supports soft-wrapping of long lines, with custom indentation of the wrapped portion, and it avoids all the space/tab problems with wrapped lines altogether...

For the record, I use tabs exclusively, 2 spaces to a tab, with line-wrapping enabled.

Author:  Siavash [ 29.09.2008, 18:07 ]
Post subject:  Re: Coding style

phoenix64 wrote:
EDIT: C::B sucks. By default is even uses Spaces instead of Tabs and without any user action involved converts empty lines which makes diffs really unreadable.

I'm agree with kal and don't forget that Code::Blocks is just an IDE and AStyle plugin performs that job !

As Volker said the best solution is defining tabsize to 4 and it's common in most of projects.

Author:  phoenix64 [ 29.09.2008, 21:06 ]
Post subject:  Re: Coding style

Using spaces for identation has one big problem, and that is that different projects use different tab widths. With tabs, that's no problem, I can work on a project where people prefer 4 spaces at the same time as on one where people use 2 spaces, without having to change the editor settings every time I switch between the source files.

btw, make that "C::B sucks." a "C::Bs default settings suck". And from the people who used C::B and who I've worked with, none of them stripped the changes in empty lines away from the commits.

@ Letting lines wrap: I don't think this is a good solution as imho it is harder to read than aligned function arguments. I could live with it though.

Page 1 of 2 All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/