[Rosettacode] D code line length limit

H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu May 8 09:59:22 PDT 2014


On Thu, May 08, 2014 at 03:13:48PM +0000, Dicebot via Digitalmars-d-learn wrote:
> On Thursday, 8 May 2014 at 14:34:27 UTC, H. S. Teoh via Digitalmars-d-learn
> wrote:
> >FWIW, for very long function signatures I write it this way:
> >
> >	const(T)[] myVeryLongFunction(T)(const(T)[] arr,
> >	                                 int        x,
> >	                                 int        y,
> >	                                 int        z,
> >	                                 ExtraArgs  extraArgs)
> >		pure @safe nothrow
> >		if (is(T : int) &&
> >		    someOtherLongCriteria!T &&
> >		    yetMoreVeryLongCriteria!T)
> >	{
> >		...
> >	}
> 
> I like this one with only exception that I prefer to keep parameter
> list to fill the line and always match brackets:
> 
> const(T)[] myVeryLongFunction(T)(const(T)[] arr,
>     int x, int y, int z, ExtraArgs  extraArgs
> )
>     pure @safe nothrow
>     if (is(T : int) &&
>         someOtherLongCriteria!T &&
>         yetMoreVeryLongCriteria!T
>     )
> {
> }
> 
> for quick overview of parameters DDOC fits better IMHO

I find the hanging )'s rather jarring. But, it's subjective after all,
right? :)

One thing I haven't quite figured out, is what to do when there are many
of both compile-time and runtime-parameters. None of my usual formatting
techniques seem to produce a nice result; it always looks ambiguous:

	Result myFunc(alias veryLongCompileTimeArgument,
	              alias anotherVeryLongCompileTimeArgument,
	              int   compileTimeIntegerArgument)
	             (int          runtimeArg1,
	              const(int)[] runtimeArg2,
	              int          moreRuntimeArgs)
		pure @safe nothrow
	...

This is the best I can do, but I'm not very happy with it. One
alternative is:

	Result myFunc(
		alias veryLongCompileTimeArgument,
		alias anotherVeryLongCompileTimeArgument,
		int   compileTimeIntegerArgument
	)(
		int          runtimeArg1,
		const(int)[] runtimeArg2,
		int          moreRuntimeArgs
	)
		pure @safe nothrow
	in { ... }
	out(result) { ... }
	body
	{
	}

This doesn't look that great either. :-/


T

-- 
The fact that anyone still uses AOL shows that even the presence of options doesn't stop some people from picking the pessimal one. - Mike Ellis


More information about the Digitalmars-d-learn mailing list