digitalmars.D.learn - [Rosettacode] D code line length limit
- bearophile (13/13) May 07 2014 So far in Rosettacode D entries I've kept a line length limit of
- Meta (13/26) May 07 2014 Maybe D programmers need to adopt a new convention for
- Jonathan M Davis via Digitalmars-d-learn (13/23) May 07 2014 My eyes... Oh, how that hurts readibily. Obviously, folks are free to fo...
- Meta (19/20) May 07 2014 While I agree that
- Meta (4/25) May 07 2014 That `extern(C) public static immutable pure nothrow @safe`
- Jonathan M Davis via Digitalmars-d-learn (7/22) May 08 2014 Actually, I find the second version perfectly readable, and I think that...
- bearophile (8/10) May 08 2014 But please put the const/immutable of methods on the right:
- Jonathan M Davis via Digitalmars-d-learn (22/30) May 08 2014 On Thu, 08 May 2014 07:29:08 +0000
- bearophile (4/10) May 08 2014 This is a job for a Lint. like DScanner :-)
- Jonathan M Davis via Digitalmars-d-learn (9/17) May 08 2014 On Thu, 08 May 2014 09:30:38 +0000
- bearophile (4/6) May 08 2014 I opened a request on this, and it was closed down :-)
- Jonathan M Davis via Digitalmars-d-learn (10/14) May 08 2014 On Thu, 08 May 2014 10:27:17 +0000
- H. S. Teoh via Digitalmars-d-learn (24/49) May 08 2014 FWIW, for very long function signatures I write it this way:
- bearophile (4/17) May 08 2014 You also need the pre&post-conditions :-)
- H. S. Teoh via Digitalmars-d-learn (31/49) May 08 2014 [...]
- Dicebot (15/28) May 08 2014 I like this one with only exception that I prefer to keep
- H. S. Teoh via Digitalmars-d-learn (35/67) May 08 2014 I find the hanging )'s rather jarring. But, it's subjective after all,
- Jonathan M Davis via Digitalmars-d-learn (9/32) May 08 2014 On Thu, 8 May 2014 07:32:52 -0700
- H. S. Teoh via Digitalmars-d-learn (9/16) May 07 2014 I have a 1600x1200 monitor, and I still prefer a maximum of 80 chars per
- Nick Sabalausky (5/18) May 07 2014 72-73 chars would indeed be a pain. In my own code I like to use a soft
- bearophile (5/7) May 07 2014 This is not regular code, it's an online wiki. The situation is a
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (4/5) May 07 2014 I've never worked at a place where the limit was not 80. So, from my
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
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, bearophileMaybe 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
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
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
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: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 =)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
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: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 DavisMy 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 ;-)
May 08 2014
Jonathan M Davis:ultimately, this sort of thing pretty much always ends up being highly subjective.But please put the const/immutable of methods on the right: struct Foo { void bar1() const {} // Good const void bar2() {} // Bad } Bye, bearophile
May 08 2014
On Thu, 08 May 2014 07:29:08 +0000 bearophile via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:Jonathan M Davis:Well, that's one case where there's actually an objective reason to put it on the right due to one of the flaws in the language - that it's the one place that const inconsistently does not apply to the type immediately to its right (though it's consistent with how attributes are applied to the function itself - just not consistent with variables). It's also because of this that I favor putting most attributes on the right (though that's subjective, unlike with const). I only put attributes on the left if they're on the left in C++ or Java (e.g. static, public, or final). Everything else goes on the right. Unfortunately, making this consistent by doing something like enforcing that all function attributes go on the right would then be inconsistent with other languages with regards to the attributes that they have which go on the left, so I don't know how we could have gotten it completely right. No matter which way you go, it's inconsistent in one way or another. If it were up to me, I'd probably enforce that all attributes which could be ambiguous go on the right but that all others could go on either side, but Walter has never liked that idea. So, we're stuck with arguing that everyone should put them on the right by convention in order to avoid the ambiguity. - Jonathan M Davisultimately, this sort of thing pretty much always ends up being highly subjective.But please put the const/immutable of methods on the right: struct Foo { void bar1() const {} // Good const void bar2() {} // Bad }
May 08 2014
Jonathan M Davis:Unfortunately, making this consistent by doing something like enforcing that all function attributes go on the right would then be inconsistent with other languages with regards to the attributes that they have which go on the left,This is a job for a Lint. like DScanner :-) Bye, bearophile
May 08 2014
On Thu, 08 May 2014 09:30:38 +0000 bearophile via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:Jonathan M Davis:Sure, that could point out that putting const or the left is bug-prone and warn you that you should change it, but while it's not really possible to have a fully consistent design with regards to function attributes, I still think that allowing const on the left is simply a bad design decision. A linter is then just a way to help you work around that bad design decision. - Jonathan M DavisUnfortunately, making this consistent by doing something like enforcing that all function attributes go on the right would then be inconsistent with other languages with regards to the attributes that they have which go on the left,This is a job for a Lint. like DScanner :-)
May 08 2014
Jonathan M Davis:I still think that allowing const on the left is simply a bad design decision.I opened a request on this, and it was closed down :-) Bye, bearophile
May 08 2014
On Thu, 08 May 2014 10:27:17 +0000 bearophile via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:Jonathan M Davis:I know. Walter doesn't agree that it was a bad decision. He thinks that being consistent with the other function attributes and letting them all be on both sides of the function is more important, but given the fact that that's highly error-prone for const and immutable, I definitely think that it was a bad decision. Unfortunately, we're stuck with it, because Walter doesn't agree, and I don't expect that anyone is going to be able to convince him. - Jonathan M DavisI still think that allowing const on the left is simply a bad design decision.I opened a request on this, and it was closed down :-)
May 08 2014
On Thu, May 08, 2014 at 01:59:58AM -0700, Jonathan M Davis via Digitalmars-d-learn wrote:On Thu, 08 May 2014 07:29:08 +0000 bearophile via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> 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) { ... }Jonathan M Davis:ultimately, this sort of thing pretty much always ends up being highly subjective.Due to this flaw, I've stopped writing "const T" completely -- now I only ever write "const(T)". Besides, there is also the ambiguity between const(T)[] and const(T[]), so I regard writing const without parens (const T[]) as a bad practice in D.But please put the const/immutable of methods on the right: struct Foo { void bar1() const {} // Good const void bar2() {} // Bad }Well, that's one case where there's actually an objective reason to put it on the right due to one of the flaws in the language - that it's the one place that const inconsistently does not apply to the type immediately to its right (though it's consistent with how attributes are applied to the function itself - just not consistent with variables).It's also because of this that I favor putting most attributes on the right (though that's subjective, unlike with const). I only put attributes on the left if they're on the left in C++ or Java (e.g. static, public, or final). Everything else goes on the right.[...] Ditto. I think this is the closest we can come to consistency given the current language. T -- My program has no bugs! Only undocumented features...
May 08 2014
H. S. Teoh: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) { ... }You also need the pre&post-conditions :-) Bye, bearophile
May 08 2014
On Thu, May 08, 2014 at 02:50:54PM +0000, bearophile via Digitalmars-d-learn wrote:H. S. Teoh:[...] I actually had them in my first draft. :) 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) in { assert(x >= 0 && x < 5); assert(y >= 0 && y < 5); assert(z >= 0 && z < 5); } out(result) { assert(result[0] >= 0 && result[0] < 5); assert(result[1] >= 1 && result[1] < 6); assert(result[2] >= 2 && result[2] < 7); } body { ... } There. :) T -- You are only young once, but you can stay immature indefinitely. -- azephrahelFWIW, 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) { ... }You also need the pre&post-conditions :-)
May 08 2014
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
May 08 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: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 EllisFWIW, 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
May 08 2014
On Thu, 8 May 2014 07:32:52 -0700 "H. S. Teoh via Digitalmars-d-learn" <digitalmars-d-learn puremagic.com> wrote:On Thu, May 08, 2014 at 01:59:58AM -0700, Jonathan M Davis via Digitalmars-d-learn wrote:That's that I do with the params, but I'd still put the attributes to the right of the last param rather than on their own line. I don't think that I'd _ever_ put attributes on their own line. But as always, it's all quite subjective, and everyone seems to prefer something at least slightly different. - Jonathan M DavisOn Thu, 08 May 2014 07:29:08 +0000 bearophile via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> 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) { ... }Jonathan M Davis:ultimately, this sort of thing pretty much always ends up being highly subjective.
May 08 2014
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
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, bearophile72-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
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
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