[phobos] Column limits again
David Simcha
dsimcha at gmail.com
Sun Apr 10 11:15:21 PDT 2011
On 4/10/2011 2:08 PM, Jacob Carlborg wrote:
> To start with, if you're using an object orient language like D is,
> and using classes in your code you basically always loose four
> columns. Next, if you're writing platform specific code with static
> if's you're loosing another four columns. If you're also going to
> annotate all you're functions/methods to take full advantage of D's
> type system you quickly get quite long function decelerations.
> @property, @safe, nothrow, const/immutable (possibly several times),
> template constraints and others.
>
> Have a look at the std.net.isemail module I'm writing:
> https://github.com/jacob-carlborg/phobos/blob/isemail/std/net/isemail.d
>
> I'm the first one to say that this function is way too long but I*m
> finding it hard to split it up. But lets focus on the column width
> instead. This function deals a lot with email status codes which is
> declared as an enum. Everywhere the function is referring to an email
> status code it needs to be prefixed with the name of the
> enum, EmailStatusCode. Since I'm also having quite long names for the
> enum members, to make them more descriptive, it's quite hard to keep
> statements within the 80 column limit, even 120 columns. Look at the
> unit tests.
>
One thing I find helps specifically for function declarations is to put
every parameter on its own line, like the following:
SomeLongType someFunction(
ParameterType1 parameter1,
ParameterType2 parameter2,
SomeEnumType flag1,
SomeOtherEnumType flag2
) const pure nothrow {
// Function body.
}
This is much more readable for long functions with more than 2-3
parameters and long, verbose names than putting the entire function
declaration on one line.
More information about the phobos
mailing list