Thread overview | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
May 07, 2014 [Rosettacode] D code line length limit | ||||
---|---|---|---|---|
| ||||
So far in Rosettacode D entries I've kept a line length limit of 72 or 73 chars. But now a little larger monitors are common, D UFCS chains are common, and we also have longer function signatures with "pure nothrow @safe @nogc" (that usually I put on a new line), so keeping that line length limit is becoming a little pain. So probably I'll increase the maximum line length. Rosettacode rules forbids too much long lines, and while in my code I use a limit of about 90-100 in my code, this is too much for online wiki pages. So I'll do some tests, and I think for Rosettacode D entries I'll increase the limit to about 80 chars. Bye, bearophile |
May 07, 2014 Re: [Rosettacode] D code line length limit | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On Wednesday, 7 May 2014 at 13:25:55 UTC, bearophile wrote:
> So far in Rosettacode D entries I've kept a line length limit of 72 or 73 chars.
>
> But now a little larger monitors are common, D UFCS chains are common, and we also have longer function signatures with "pure nothrow @safe @nogc" (that usually I put on a new line), so keeping that line length limit is becoming a little pain.
>
> So probably I'll increase the maximum line length. Rosettacode rules forbids too much long lines, and while in my code I use a limit of about 90-100 in my code, this is too much for online wiki pages. So I'll do some tests, and I think for Rosettacode D entries I'll increase the limit to about 80 chars.
>
> Bye,
> bearophile
Maybe D programmers need to adopt a new convention for annotations in the long term. Instead of:
void doSomething(int n) pure @safe @nogc nothrow
{
}
We should write:
pure @safe @nogc nothrow
void doSomething(int n)
{
}
The only problem being that this conflicts with the convention for UDAs...
|
May 07, 2014 Re: [Rosettacode] D code line length limit | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | On Wed, 07 May 2014 13:39:55 +0000 Meta via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com> wrote: > Maybe D programmers need to adopt a new convention for annotations in the long term. Instead of: > > void doSomething(int n) pure @safe @nogc nothrow > { > } > > We should write: > > pure @safe @nogc nothrow > void doSomething(int n) > { > } My eyes... Oh, how that hurts readibily. Obviously, folks are free to format their code how they like, but I very much hope that that style never becomes prevalent. About the only place in a signature that I like to break it up across lines is with the parameters, and I generally will let the signature line get to the limit before I will break it up (which in the case of Phobos, would be 120 characters, since it has a hard limit of 120, and a soft limit of 80 - and functions are one place where I will definitely go passed the soft limit). Regardless, formatting code is one are that's always going to be highly subjective. - Jonathan M Davis |
May 07, 2014 Re: [Rosettacode] D code line length limit | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On Wed, May 07, 2014 at 01:25:52PM +0000, bearophile via Digitalmars-d-learn wrote: > So far in Rosettacode D entries I've kept a line length limit of 72 or 73 chars. > > But now a little larger monitors are common, D UFCS chains are common, and we also have longer function signatures with "pure nothrow @safe @nogc" (that usually I put on a new line), so keeping that line length limit is becoming a little pain. I have a 1600x1200 monitor, and I still prefer a maximum of 80 chars per line. Lines that are too long are hard to read at a glance, regardless of how narrow/short the monitor is. But, how you choose to format your code is really up to you. ;-) T -- Elegant or ugly code as well as fine or rude sentences have something in common: they don't depend on the language. -- Luca De Vitis |
May 07, 2014 Re: [Rosettacode] D code line length limit | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On 5/7/2014 9:25 AM, bearophile wrote:
> So far in Rosettacode D entries I've kept a line length limit of 72 or
> 73 chars.
>
> But now a little larger monitors are common, D UFCS chains are common,
> and we also have longer function signatures with "pure nothrow @safe
> @nogc" (that usually I put on a new line), so keeping that line length
> limit is becoming a little pain.
>
> So probably I'll increase the maximum line length. Rosettacode rules
> forbids too much long lines, and while in my code I use a limit of about
> 90-100 in my code, this is too much for online wiki pages. So I'll do
> some tests, and I think for Rosettacode D entries I'll increase the
> limit to about 80 chars.
>
> Bye,
> bearophile
72-73 chars would indeed be a pain. In my own code I like to use a soft limit of 80, FWIW.
I do find I need to break up lines in D more than I would in other languages, especially function signatures.
|
May 07, 2014 Re: [Rosettacode] D code line length limit | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On 05/07/2014 06:25 AM, bearophile wrote: > limit to about 80 chars. I've never worked at a place where the limit was not 80. So, from my point of view it is still the industry standard and I like it. :) Ali |
May 07, 2014 Re: [Rosettacode] D code line length limit | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | Nick Sabalausky:
> 72-73 chars would indeed be a pain. In my own code I like to use a soft limit of 80, FWIW.
This is not regular code, it's an online wiki. The situation is a little different. But I think 80 is now acceptable.
Bye,
bearophile
|
May 07, 2014 Re: [Rosettacode] D code line length limit | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On Wednesday, 7 May 2014 at 14:40:37 UTC, Jonathan M Davis via Digitalmars-d-learn wrote:
> My eyes... Oh, how that hurts readibily.
While I agree that
pure @safe @nogc nothrow
void doSomething(int n)
{
}
is quite ugly, it is really not much worse than
void doSomething(int n) pure @safe @nogc nothrow
{
}
I would argue that the latter hurts readability more, as parsing meaning from long lines is difficult for humans. Also, we can always go deeper ;-)
extern(C) public static immutable pure nothrow @safe void doSomething(int n)
{
}
I won't get into the `if` template guards, as those are cheating.
|
May 07, 2014 Re: [Rosettacode] D code line length limit | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | On Wednesday, 7 May 2014 at 18:51:59 UTC, Meta wrote:
> On Wednesday, 7 May 2014 at 14:40:37 UTC, Jonathan M Davis via Digitalmars-d-learn wrote:
>> My eyes... Oh, how that hurts readibily.
>
> While I agree that
>
> pure @safe @nogc nothrow
> void doSomething(int n)
> {
> }
>
> is quite ugly, it is really not much worse than
>
> void doSomething(int n) pure @safe @nogc nothrow
> {
> }
>
> I would argue that the latter hurts readability more, as parsing meaning from long lines is difficult for humans. Also, we can always go deeper ;-)
>
> extern(C) public static immutable pure nothrow @safe void doSomething(int n)
> {
> }
>
> I won't get into the `if` template guards, as those are cheating.
That `extern(C) public static immutable pure nothrow @safe` should be on the same line as the function declaration. The web interface is ruining my point =)
|
May 08, 2014 Re: [Rosettacode] D code line length limit | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | On Wed, 07 May 2014 18:51:58 +0000 Meta via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com> wrote: > On Wednesday, 7 May 2014 at 14:40:37 UTC, Jonathan M Davis via Digitalmars-d-learn wrote: > > My eyes... Oh, how that hurts readibily. > > While I agree that > > pure @safe @nogc nothrow > void doSomething(int n) > { > } > > is quite ugly, it is really not much worse than > > void doSomething(int n) pure @safe @nogc nothrow > { > } > > I would argue that the latter hurts readability more, as parsing meaning from long lines is difficult for humans. Also, we can always go deeper ;-) Actually, I find the second version perfectly readable, and I think that it is by far the best way for that function signature to be written, whereas I find the first one to be much, much harder to read. But ultimately, this sort of thing pretty much always ends up being highly subjective. - Jonathan M Davis |
Copyright © 1999-2021 by the D Language Foundation