digitalmars.D.learn - DStyle: Braces on same line
- Danyal Zia (11/11) Jul 12 2014 Hi,
- Timon Gehr (6/19) Jul 12 2014 I think Phobos is often painful to read exactly because trivial
- anonymous (6/17) Jul 12 2014 yes (I read that "if" as "as long as")
- Danyal Zia (4/7) Jul 12 2014 Agreed about variables and functions. However I personally prefer
- Dicebot (4/6) Jul 12 2014 Depends entirely on whenever you want to match style of standard
- dysmondad (7/18) Jul 12 2014 Pick one and stick with it. There are countless holy wars out
- Joseph Rushton Wakeling via Digitalmars-d-learn (7/14) Jul 13 2014 As long as your coding style is self-consistent, then it really doesn't ...
- Danyal Zia (3/8) Jul 13 2014 I'm going with Andrei's style of preference on his talks ;)
- Joseph Rushton Wakeling via Digitalmars-d-learn (7/8) Jul 13 2014 Andrei can no doubt speak for himself about his preferences, but I'd be ...
- Dicebot (5/14) Jul 13 2014 Andrei has stated several times he prefers Phobos-style brackets
- H. S. Teoh via Digitalmars-d-learn (17/36) Jul 13 2014 I had my own style before, but after I started contributing to Phobos, I
- Gary Willoughby (4/15) Jul 13 2014 Here is the 'official' style that is followed by most people
- Danyal Zia (3/6) Jul 14 2014 Unrelated to my original question. I already read that before
- Joseph Rushton Wakeling via Digitalmars-d-learn (8/18) Jul 13 2014 Two consequences of adapting myself to Phobos style were that I realized...
- Timon Gehr (6/14) Jul 13 2014 Wrong. There are things which are simply bad ideas.
- Brian Rogoff (17/29) Jul 13 2014 Yes, the same argument for books and slides is also applicable to
- Timon Gehr (9/40) Jul 13 2014 Yup, but they also do horrible things like using '+' to denote
- Joseph Rushton Wakeling via Digitalmars-d-learn (12/14) Jul 13 2014 Not really. In a book or a slide you have an unavoidable constraint on ...
- Joseph Rushton Wakeling via Digitalmars-d-learn (14/18) Jul 13 2014 I think that we can take it as read that I meant, "Any reasonable stylis...
- Dicebot (2/7) Jul 14 2014 It is perfectly valid and much more important :P
- bearophile (6/9) Jul 13 2014 Rosettacode D examples always use the Egyptian style. For my code
Hi, I noticed that in Andrei's talks and his book, he used braces on the same line of delcaration, however Phobos and other D libraries I know use braces on their own line. Now I'm in a position where I need to take decision on coding style of my library and I get accustomed to use braces on same line but I'm worried if that would make my library less readable to other D users. Should I worry about it? Or is that's just a debatable style that won't really matter if it's persistent throughout library? Thanks
Jul 12 2014
On 07/12/2014 09:01 PM, Danyal Zia wrote:Hi, I noticed that in Andrei's talks and his book, he used braces on the same line of delcaration,That's because they do not waste that much space that way.however Phobos and other D libraries I know use braces on their own line. Now I'm in a position where I need to take decision on coding style of my library and I get accustomed to use braces on same line but I'm worried if that would make my library less readable to other D users. ...I think Phobos is often painful to read exactly because trivial functionality tends to span multiple pages.Should I worry about it?IMO No.Or is that's just a debatable style that won't really matter if it's persistent throughout library?Yes.Thanks
Jul 12 2014
On Saturday, 12 July 2014 at 19:01:56 UTC, Danyal Zia wrote:Hi, I noticed that in Andrei's talks and his book, he used braces on the same line of delcaration, however Phobos and other D libraries I know use braces on their own line. Now I'm in a position where I need to take decision on coding style of my library and I get accustomed to use braces on same line but I'm worried if that would make my library less readable to other D users. Should I worry about it?noOr is that's just a debatable style that won't really matter if it's persistent throughout library?yes (I read that "if" as "as long as") There is another stylistic choice which I do find confusing: capitalized identifiers for non-types, e.g. variables and functions. Please don't do that.
Jul 12 2014
On Saturday, 12 July 2014 at 19:35:11 UTC, anonymous wrote:There is another stylistic choice which I do find confusing: capitalized identifiers for non-types, e.g. variables and functions. Please don't do that.Agreed about variables and functions. However I personally prefer to use PascalCased identifiers in enum unlike what is preached in Dstyle page.
Jul 12 2014
On Saturday, 12 July 2014 at 19:01:56 UTC, Danyal Zia wrote:Should I worry about it? Or is that's just a debatable style that won't really matter if it's persistent throughout library?Depends entirely on whenever you want to match style of standard library - no one will blame you for having own preferences. It is only required for Phobos pull requests.
Jul 12 2014
On Saturday, 12 July 2014 at 19:01:56 UTC, Danyal Zia wrote:Hi, I noticed that in Andrei's talks and his book, he used braces on the same line of delcaration, however Phobos and other D libraries I know use braces on their own line. Now I'm in a position where I need to take decision on coding style of my library and I get accustomed to use braces on same line but I'm worried if that would make my library less readable to other D users. Should I worry about it? Or is that's just a debatable style that won't really matter if it's persistent throughout library? ThanksPick one and stick with it. There are countless holy wars out there about this sort of thing and it is really a personal choice. Generally it's a good idea to follow the style of extant code if you are working on large project and I do feel that coding teams should pick a style all the code from that group should use the same style.
Jul 12 2014
On 12/07/14 21:01, Danyal Zia via Digitalmars-d-learn wrote:I noticed that in Andrei's talks and his book, he used braces on the same line of delcaration, however Phobos and other D libraries I know use braces on their own line. Now I'm in a position where I need to take decision on coding style of my library and I get accustomed to use braces on same line but I'm worried if that would make my library less readable to other D users. Should I worry about it? Or is that's just a debatable style that won't really matter if it's persistent throughout library?As long as your coding style is self-consistent, then it really doesn't matter a lot. In particular this choice of bracing style is a very minor issue that people are well used to having to deal with. However, I do think there's value in deliberately matching the code style of the standard library, as it extends the volume of public D code with a common style. So unless you have a strong personal preference, I'd go with that.
Jul 13 2014
On Sunday, 13 July 2014 at 10:18:23 UTC, Joseph Rushton Wakeling via Digitalmars-d-learn wrote:However, I do think there's value in deliberately matching the code style of the standard library, as it extends the volume of public D code with a common style. So unless you have a strong personal preference, I'd go with that.I'm going with Andrei's style of preference on his talks ;)
Jul 13 2014
On 13/07/14 14:23, Danyal Zia via Digitalmars-d-learn wrote:I'm going with Andrei's style of preference on his talks ;)Andrei can no doubt speak for himself about his preferences, but I'd be wary of assuming that the style he uses in his talks necessarily reflects his actual stylistic preference. As has been pointed out by others, same-line opening brace is a common style for slides and books because it saves vertical space; people will use it there even if in their actual code they prefer something different.
Jul 13 2014
On Sunday, 13 July 2014 at 16:47:00 UTC, Joseph Rushton Wakeling via Digitalmars-d-learn wrote:On 13/07/14 14:23, Danyal Zia via Digitalmars-d-learn wrote:Andrei has stated several times he prefers Phobos-style brackets but uses egyptian ones in slides / books because of spacing constraints.I'm going with Andrei's style of preference on his talks ;)Andrei can no doubt speak for himself about his preferences, but I'd be wary of assuming that the style he uses in his talks necessarily reflects his actual stylistic preference. As has been pointed out by others, same-line opening brace is a common style for slides and books because it saves vertical space; people will use it there even if in their actual code they prefer something different.
Jul 13 2014
On Sun, Jul 13, 2014 at 11:32:23AM +0200, Joseph Rushton Wakeling via Digitalmars-d-learn wrote:On 12/07/14 21:01, Danyal Zia via Digitalmars-d-learn wrote:I had my own style before, but after I started contributing to Phobos, I found it a pain to keep switching back and forth between styles (and to convert styles before submitting PR's), so eventually I decided to just adopt Phobos style for all my D code, including my personal projects. That way I never have to worry again about which project is in what style, but everything is consistently the same style. It also helps that my previous supervisor at my work also used a similar style, which was different from my own, so I already had to adapt my style to his in the past. That was what convinced me that other inferior styles than my own had any merit at all. ;-) At the end of the day, though, as long as your style is consistent within a project, it's Good Enough(tm). There are far weightier issues of semantics to worry about than fretting over syntax. T -- Verbing weirds language. -- Calvin (& Hobbes)I noticed that in Andrei's talks and his book, he used braces on the same line of delcaration, however Phobos and other D libraries I know use braces on their own line. Now I'm in a position where I need to take decision on coding style of my library and I get accustomed to use braces on same line but I'm worried if that would make my library less readable to other D users. Should I worry about it? Or is that's just a debatable style that won't really matter if it's persistent throughout library?As long as your coding style is self-consistent, then it really doesn't matter a lot. In particular this choice of bracing style is a very minor issue that people are well used to having to deal with. However, I do think there's value in deliberately matching the code style of the standard library, as it extends the volume of public D code with a common style. So unless you have a strong personal preference, I'd go with that.
Jul 13 2014
On Saturday, 12 July 2014 at 19:01:56 UTC, Danyal Zia wrote:Hi, I noticed that in Andrei's talks and his book, he used braces on the same line of delcaration, however Phobos and other D libraries I know use braces on their own line. Now I'm in a position where I need to take decision on coding style of my library and I get accustomed to use braces on same line but I'm worried if that would make my library less readable to other D users. Should I worry about it? Or is that's just a debatable style that won't really matter if it's persistent throughout library? ThanksHere is the 'official' style that is followed by most people including me. http://dlang.org/dstyle.html
Jul 13 2014
On Sunday, 13 July 2014 at 16:10:31 UTC, Gary Willoughby wrote:Here is the 'official' style that is followed by most people including me. http://dlang.org/dstyle.htmlUnrelated to my original question. I already read that before asking.
Jul 14 2014
On 13/07/14 16:52, H. S. Teoh via Digitalmars-d-learn wrote:I had my own style before, but after I started contributing to Phobos, I found it a pain to keep switching back and forth between styles (and to convert styles before submitting PR's), so eventually I decided to just adopt Phobos style for all my D code, including my personal projects. That way I never have to worry again about which project is in what style, but everything is consistently the same style.Same here. :-)It also helps that my previous supervisor at my work also used a similar style, which was different from my own, so I already had to adapt my style to his in the past. That was what convinced me that other inferior styles than my own had any merit at all. ;-)Two consequences of adapting myself to Phobos style were that I realized (i)how little most of these things really matter, and (ii) pretty much any stylistic choice carries both benefits and drawbacks. E.g. in this case, "Egyptian"-style braces definitely make your code more compact, but separate-line opening braces definitely make it easier to see where scopes begin and end.
Jul 13 2014
On 07/13/2014 06:45 PM, Joseph Rushton Wakeling via Digitalmars-d-learn wrote:Two consequences of adapting myself to Phobos style were that I realized (i)how little most of these things really matter, and (ii) pretty much any stylistic choice carries both benefits and drawbacks. ...Wrong. There are things which are simply bad ideas.E.g. in this case, "Egyptian"-style braces definitely make your code more compact,I.e. you see where everything is.but separate-line opening braces definitely make it easier to see where scopes begin and end.This is the only argument I have heard in favour of doing this, but it is not actually valid. This critique might apply to Lisp style.
Jul 13 2014
On Sunday, 13 July 2014 at 17:24:40 UTC, Timon Gehr wrote:On 07/13/2014 06:45 PM, Joseph Rushton Wakeling via Digitalmars-d-learn wrote: Wrong. There are things which are simply bad ideas.Yes, the same argument for books and slides is also applicable to all other media. This style has also caught on amongst the other curly braced languages that I use, so that most of the code I read (and write) has adopted it (C/C++/Java/Javascript code, that is). The Phobos style is incredibly wasteful IMO, but that's what D has adopted, so if you intend to contribute to Phobos, you had better get used to it. The Rust community appears to have made the right choice with Egyptian for everything.E.g. in this case, "Egyptian"-style braces definitely make your code more compact,I.e. you see where everything is.All of this is subjective, of course, but I definitely don't find that the Phobos style provides this advantage.but separate-line opening braces definitely make it easier to see where scopes begin and end.This is the only argument I have heard in favour of doing this, but it is not actually valid. This critique might apply to Lisp style.Not sure I follow you here. Most of the Lisp I've read is indented like Python, the idea being that you learn not to not see all of the parens and rely on tools like paredit to do the trivial balancing. I'd hate to read Lisp with separate lines for parens that open scopes. I'm sure that's not what you mean!
Jul 13 2014
On 07/13/2014 07:51 PM, Brian Rogoff wrote:On Sunday, 13 July 2014 at 17:24:40 UTC, Timon Gehr wrote:Exactly.On 07/13/2014 06:45 PM, Joseph Rushton Wakeling via Digitalmars-d-learn wrote: Wrong. There are things which are simply bad ideas.Yes, the same argument for books and slides is also applicable to all other media.E.g. in this case, "Egyptian"-style braces definitely make your code more compact,I.e. you see where everything is.This style has also caught on amongst the other curly braced languages that I use, so that most of the code I read (and write) has adopted it (C/C++/Java/Javascript code, that is). The Phobos style is incredibly wasteful IMO, but that's what D has adopted, so if you intend to contribute to Phobos, you had better get used to it. The Rust community appears to have made the right choice with Egyptian for everything. ...Yup, but they also do horrible things like using '+' to denote intersection (multiple trait bounds).I was suggesting that if someone does this: http://en.wikipedia.org/wiki/Indent_style#Lisp_style Then I would have an easier time seeing where a person is coming from who claims that it makes it in some way harder to see at a glance where scopes begin and end.All of this is subjective, of course, but I definitely don't find that the Phobos style provides this advantage.but separate-line opening braces definitely make it easier to see where scopes begin and end.This is the only argument I have heard in favour of doing this, but it is not actually valid. This critique might apply to Lisp style.Not sure I follow you here. Most of the Lisp I've read is indented like Python, the idea being that you learn not to not see all of the parens and rely on tools like paredit to do the trivial balancing. I'd hate to read Lisp with separate lines for parens that open scopes. I'm sure that's not what you mean!
Jul 13 2014
On 13/07/14 19:51, Brian Rogoff via Digitalmars-d-learn wrote:Yes, the same argument for books and slides is also applicable to all other media.Not really. In a book or a slide you have an unavoidable constraint on how much vertical space you can take up. On a screen, you are unavoidably going to have to scroll up or down at some point; it's just a question of how often. Scrolling media (not just code) allow you to make a tradeoff between less vertically compact styles that better highlight different semantic blocks, versus more compact styles that packs more data into one screen's worth of lines, while usually making it less easy to highlight the semantics of what's being displayed. You may lean towards favouring compact code over other factors, but at the end of the day this is a preference based on your personal priorities, not a hard and fast rule.
Jul 13 2014
On 13/07/14 19:24, Timon Gehr via Digitalmars-d-learn wrote:Wrong. There are things which are simply bad ideas.I think that we can take it as read that I meant, "Any reasonable stylistic choice." Of course, YMMV about what counts as "reasonable", but most of the things that people fuss over are fairly minimal differences in practice.I.e. you see where everything is.Compactness can also be a disadvantage. Some people have a preference for a hyper-compact style where there are minimal blank lines in the code; I accept their goal as valid, and I think there are cases where it can surely help, but it's not one that I personally find very helpful. In fact, one reason that I've come to appreciate standard D style is the way in which separate opening braces actually help to space out the code into more obvious "paragraphs".This is the only argument I have heard in favour of doing this, but it is not actually valid. This critique might apply to Lisp style.Well, I personally find that separate-line opening braces do make it easier to line up the opening and ending of scopes. If it doesn't do anything for you, that's a shame; but it doesn't make the argument invalid.
Jul 13 2014
On Sunday, 13 July 2014 at 17:24:40 UTC, Timon Gehr wrote:It is perfectly valid and much more important :Pbut separate-line opening braces definitely make it easier to see where scopes begin and end.This is the only argument I have heard in favour of doing this, but it is not actually valid. This critique might apply to Lisp style.
Jul 14 2014
Danyal Zia:I noticed that in Andrei's talks and his book, he used braces on the same line of delcaration, however Phobos and other D libraries I know use braces on their own line.Rosettacode D examples always use the Egyptian style. For my code I use the same style, but Phobos contributions (and future ddmd) should put opening braces on their own line. Bye, bearophile
Jul 13 2014