July 13, 2014 Re: DStyle: Braces on same line | ||||
---|---|---|---|---|
| ||||
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. |
July 13, 2014 Re: DStyle: Braces on same line | ||||
---|---|---|---|---|
| ||||
Posted in reply to Danyal Zia | 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.
|
July 13, 2014 Re: DStyle: Braces on same line | ||||
---|---|---|---|---|
| ||||
Posted in reply to Joseph Rushton Wakeling | 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:
>> 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.
Andrei has stated several times he prefers Phobos-style brackets but uses egyptian ones in slides / books because of spacing constraints.
|
July 13, 2014 Re: DStyle: Braces on same line | ||||
---|---|---|---|---|
| ||||
Posted in reply to Danyal Zia | 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
|
July 13, 2014 Re: DStyle: Braces on same line | ||||
---|---|---|---|---|
| ||||
Posted in reply to Joseph Rushton Wakeling | 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. |
July 13, 2014 Re: DStyle: Braces on same line | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | 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. > >> E.g. in this case, "Egyptian"-style braces definitely make your code >> more compact, > > I.e. you see where everything is. 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. >> but separate-line opening braces definitely make it easier >> to see 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. > > 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! |
July 13, 2014 Re: DStyle: Braces on same line | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | 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. |
July 13, 2014 Re: DStyle: Braces on same line | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brian Rogoff | On 07/13/2014 07:51 PM, Brian Rogoff wrote: > 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. >> >>> E.g. in this case, "Egyptian"-style braces definitely make your code >>> more compact, >> >> I.e. you see where everything is. > > Yes, the same argument for books and slides is also applicable to all > other media. Exactly. > 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). >>> but separate-line opening braces definitely make it easier >>> to see 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. >> >> 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! 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. |
July 13, 2014 Re: DStyle: Braces on same line | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brian Rogoff | 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.
|
July 14, 2014 Re: DStyle: Braces on same line | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gary Willoughby | 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.html
Unrelated to my original question. I already read that before asking.
|
Copyright © 1999-2021 by the D Language Foundation