digitalmars.D.learn - Class Order Style
- Jolly James (5/31) Feb 20 2017 ... and so on. are there any recommendations?
- ketmar (4/12) Feb 20 2017 just add ddoc documentation to 'em, and then it doesn't matter in which
- Jolly James (3/29) Feb 20 2017 ah okay, thx
- Lenny Lowood (2/31) Feb 21 2017 Me as a beginner would like to know this, too ...
- Jonathan M Davis via Digitalmars-d-learn (20/66) Feb 21 2017 It's completely a stylistic preference. There are a number of different ...
- Jolly James (3/11) Feb 22 2017 thank you!
- Seb (5/36) Feb 21 2017 Two pointers towards two popular style guides, which could also
- Jacob Carlborg (34/65) Feb 24 2017 In my opinion:
How to sort the members of a class? like:1. properties then 2. private 3. methods 4. ctors... and so on. are there any recommendations? And what is better?class A { private: int a; int b; public: int c; int d; }orclass A { private { int a; int b; } public { int c; int d; } }
Feb 20 2017
Jolly James wrote:How to sort the members of a class? like:just add ddoc documentation to 'em, and then it doesn't matter in which order they are declared: people will generate documentation to find out how to use your code. ;-)1. properties then 2. private 3. methods 4. ctors... and so on. are there any recommendations? And what is better?
Feb 20 2017
On Monday, 20 February 2017 at 13:50:26 UTC, ketmar wrote:just add ddoc documentation to 'em, and then it doesn't matter in which order they are declared: people will generate documentation to find out how to use your code. ;-)ah okay, thx But what about this?class A { private: int a; int b; public: int c; int d; }orclass A { private { int a; int b; } public { int c; int d; } }
Feb 20 2017
On Monday, 20 February 2017 at 18:02:20 UTC, Jolly James wrote:On Monday, 20 February 2017 at 13:50:26 UTC, ketmar wrote:Me as a beginner would like to know this, too ...just add ddoc documentation to 'em, and then it doesn't matter in which order they are declared: people will generate documentation to find out how to use your code. ;-)ah okay, thx But what about this?class A { private: int a; int b; public: int c; int d; }orclass A { private { int a; int b; } public { int c; int d; } }
Feb 21 2017
On Tuesday, February 21, 2017 22:41:40 Lenny Lowood via Digitalmars-d-learn wrote:On Monday, 20 February 2017 at 18:02:20 UTC, Jolly James wrote:It's completely a stylistic preference. There are a number of different ways to order your member variables and functions, and there are several different ways to apply attributes to them. As far as public and private go, I think that most folks either use the labels like private: public: or they put them directly on the members like private int a; I suspect that the folks who programmed a lot in C++ tend to do the former, since that's the way you have to do it in C++, and I'd guess that the folks that's how you have to do it in those languages. There is no right or wrong way. Personally, I use the labels like in C++ and put the public stuff first in a class or struct and the private stuff last (and I think that that's what Phobos mostly does), but you'll find plenty of folks who do it differently. - Jonathan M DavisOn Monday, 20 February 2017 at 13:50:26 UTC, ketmar wrote:Me as a beginner would like to know this, too ...just add ddoc documentation to 'em, and then it doesn't matter in which order they are declared: people will generate documentation to find out how to use your code. ;-)ah okay, thx But what about this?class A { private: int a; int b; public: int c; int d; }orclass A { private { int a; int b; } public { int c; int d; } }
Feb 21 2017
On Tuesday, 21 February 2017 at 23:06:23 UTC, Jonathan M Davis wrote:On Tuesday, February 21, 2017 22:41:40 Lenny Lowood via Digitalmars-d-learn wrote:thank you![...]It's completely a stylistic preference. There are a number of different ways to order your member variables and functions, and there are several different ways to apply attributes to them. [...]
Feb 22 2017
On Monday, 20 February 2017 at 13:47:07 UTC, Jolly James wrote:How to sort the members of a class? like:Two pointers towards two popular style guides, which could also help to answer future questions: http://dlang.org/dstyle.html https://vibed.org/style-guide1. properties then 2. private 3. methods 4. ctors... and so on. are there any recommendations? And what is better?class A { private: int a; int b; public: int c; int d; }orclass A { private { int a; int b; } public { int c; int d; } }
Feb 21 2017
On 2017-02-20 14:47, Jolly James wrote:How to sort the members of a class? like:In my opinion: 1. Manifest constants (enum) 2. Static variables 3. Instance variables 4. Constructors 5. Properties 6. Methods1. properties then 2. private 3. methods 4. ctors... and so on. are there any recommendations?And what is better?I usually go with "private int a;" if there are four or less fields (static or instance). Otherwise I use the block style (with curly braces). For the methods I use the Java style with the protection attribute attached for each method. Sometimes I put a bunch of internal methods at the end, then I use the label (C++) style. class Foo { enum a = 1; enum b = 2; static int c = 3; static int d = 4; private int e_; private int f_; this(int e, int f) {} static void g(); static void h(); int e() { return e_; } int f() { return f_; } void i(); void j(); private: void k(); void l(); } -- /Jacob Carlborgclass A { private: int a; int b; public: int c; int d; }orclass A { private { int a; int b; } public { int c; int d; } }
Feb 24 2017