Jump to page: 1 2 3
Thread overview
DStyle: Braces on same line
Jul 12, 2014
Danyal Zia
Jul 12, 2014
Timon Gehr
Jul 12, 2014
anonymous
Jul 12, 2014
Danyal Zia
Jul 12, 2014
Dicebot
Jul 13, 2014
dysmondad
Jul 13, 2014
Danyal Zia
Jul 13, 2014
Dicebot
Jul 13, 2014
H. S. Teoh
Jul 13, 2014
Gary Willoughby
Jul 14, 2014
Danyal Zia
Jul 13, 2014
Timon Gehr
Jul 13, 2014
Brian Rogoff
Jul 13, 2014
Timon Gehr
Jul 14, 2014
Dicebot
Jul 13, 2014
bearophile
July 12, 2014
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
July 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

July 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?

no

> Or 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.
July 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.
July 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.
July 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?
>
> Thanks

Pick 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.
July 13, 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.
July 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 ;)
July 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 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.

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)
July 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?
>
> Thanks

Here is the 'official' style that is followed by most people including me.

http://dlang.org/dstyle.html
« First   ‹ Prev
1 2 3