Horde3D

Next-Generation Graphics Engine
It is currently 05.01.2025, 00:22

All times are UTC + 1 hour




Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Coding style
PostPosted: 27.09.2008, 16:18 
Offline

Joined: 15.06.2008, 11:21
Posts: 166
Location: Germany
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Coding style
PostPosted: 27.09.2008, 17:39 
Offline

Joined: 18.05.2008, 17:47
Posts: 96
I propose to drop tabs and use spaces instead :)


Top
 Profile  
Reply with quote  
 Post subject: Re: Coding style
PostPosted: 27.09.2008, 18:26 
Offline

Joined: 15.06.2008, 11:21
Posts: 166
Location: Germany
"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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Coding style
PostPosted: 29.09.2008, 01:30 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
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 );


Top
 Profile  
Reply with quote  
 Post subject: Re: Coding style
PostPosted: 29.09.2008, 07:48 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
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).


Top
 Profile  
Reply with quote  
 Post subject: Re: Coding style
PostPosted: 29.09.2008, 08:35 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Coding style
PostPosted: 29.09.2008, 08:54 
Offline

Joined: 18.05.2008, 17:47
Posts: 96
no tabify works fine
also
http://astyle.sourceforge.net/astyle.html
http://uncrustify.sourceforge.net/


Top
 Profile  
Reply with quote  
 Post subject: Re: Coding style
PostPosted: 29.09.2008, 10:56 
Offline

Joined: 21.08.2008, 11:44
Posts: 354
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)


Top
 Profile  
Reply with quote  
 Post subject: Re: Coding style
PostPosted: 29.09.2008, 11:26 
Offline

Joined: 15.06.2008, 11:21
Posts: 166
Location: Germany
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Coding style
PostPosted: 29.09.2008, 12:17 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
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?


Top
 Profile  
Reply with quote  
 Post subject: Re: Coding style
PostPosted: 29.09.2008, 12:34 
Offline

Joined: 15.06.2008, 11:21
Posts: 166
Location: Germany
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Coding style
PostPosted: 29.09.2008, 12:42 
Offline

Joined: 18.05.2008, 17:47
Posts: 96
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Coding style
PostPosted: 29.09.2008, 13:25 
Offline

Joined: 22.11.2007, 17:05
Posts: 707
Location: Boston, MA
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.

_________________
Tristam MacDonald - [swiftcoding]


Last edited by swiftcoder on 29.09.2008, 18:33, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Coding style
PostPosted: 29.09.2008, 18:07 
Offline

Joined: 21.08.2008, 11:44
Posts: 354
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Coding style
PostPosted: 29.09.2008, 21:06 
Offline

Joined: 15.06.2008, 11:21
Posts: 166
Location: Germany
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.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 25 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group