Code Style

Alexander Panek a.panek at brainsware.org
Fri Jun 15 13:15:03 PDT 2007


Robert Fraser wrote:
> Hi all,
> [...]
> Also, a more general question... would you ever consider actually USING a code formatter/have used one in the past?

Personally, I don't use code formatters as they tend to have only one 
set of formatting properties, which makes it a bit of a pain in the ass 
at times. The fact that Vim does not provide any (on-the-fly) code 
formatting might also be an influence..

Anyways, my formatting of code requires rather much space(s) and thus 
might not be appreciated by anyone. Though, if you'd like to take a peak 
on it, here are some files with hopefully interesting formatting :)

http://trac.brainsware.org/libodf/browser/branches/d/odf/OpenDocument.d
http://trac.brainsware.org/libodf/browser/branches/d/odf/Content.d

Basically, everything that is not contextually connected is placed in a 
new paragraph, which means:

<code>
set;
of;
instructionsContextA;
                         // teh space.
set;
of;
instructionsContextB;
</code>

A function is always written as follows:

<code>
Type functionName (T) ( T1 a, T2 b ) {
	/// code...
}

// or

Type functionName ( T1, T2 ) ( T1 a, T2 b ) {
	/// code...
}
</code>

Classes are similar to that:

<code>
class Foo (T) { // or "( T1, T2 )" as above
	Type     alignedMembers;
         TypeType alignedMemberFoos;
	T        buh;
}
</code>

..etc. Hope that helps.

Kind regards,
Alex



More information about the Digitalmars-d mailing list