www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - style

reply sclytrack pi.be writes:
I was wondering about the style to be used in D, especially related to private
and protected members.

Java has get and set methods.

class Window {
private:
char [] caption;
public:
char [] getCaption() {}
}

Is above good D-style?


Below you already need 2 or 3 names. Which names should they be?

class Window
{
private:

//What name should this be, of course one can choose because its private.
//Borland goes with FCaption;

char [] mcaption;    
public:
char [] caption() {}
void caption(char[] pcaption)
{
mcaption = pcaption;
}
}

So give me the best D-style names. :-)
May 22 2006
next sibling parent reply Daniel Keep <daniel.keep.lists gmail.com> writes:
sclytrack pi.be wrote:
 I was wondering about the style to be used in D, especially related to private
 and protected members.
 
 Java has get and set methods.
 
 class Window {
 private:
 char [] caption;
 public:
 char [] getCaption() {}
 }
 
 Is above good D-style?
 
Yuck. By the way, that's just my *personal* opinion :)
 
 Below you already need 2 or 3 names. Which names should they be?
 
 class Window
 {
 private:
 
 //What name should this be, of course one can choose because its private.
 //Borland goes with FCaption;
 
 char [] mcaption;    
 public:
 char [] caption() {}
 void caption(char[] pcaption)
 {
 mcaption = pcaption;
 }
 }
 
 So give me the best D-style names. :-)
 
 
Personally, I use this: A question of my own: does anyone define the return type of the 'setter', and then return the value like this: I'm under the impression this is good because it allows you to chain assignment statements; but does anyone actually do this? -- Daniel -- v1sw5+8Yhw5ln4+5pr6OFma8u6+7Lw4Tm6+7l6+7D a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
May 22 2006
parent reply Lars Ivar Igesund <larsivar igesund.net> writes:
Daniel Keep wrote:

 
 A question of my own: does anyone define the return type of the
 'setter', and then return the value like this:
 




 
 I'm under the impression this is good because it allows you to chain
 assignment statements; but does anyone actually do this?
 
 -- Daniel
 
I believe Mango do this quite extensively. -- Lars Ivar Igesund blog at http://larsivi.net DSource & #D: larsivi
May 22 2006
parent Daniel Keep <daniel.keep.lists gmail.com> writes:
Lars Ivar Igesund wrote:
 Daniel Keep wrote:
 
 A question of my own: does anyone define the return type of the
 'setter', and then return the value like this:






 I'm under the impression this is good because it allows you to chain
 assignment statements; but does anyone actually do this?

 -- Daniel
I believe Mango do this quite extensively.
WELL. That settles it, then :) -- Daniel -- v1sw5+8Yhw5ln4+5pr6OFma8u6+7Lw4Tm6+7l6+7D a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
May 22 2006
prev sibling parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
<sclytrack pi.be> wrote in message news:e4s007$2ejs$1 digitaldaemon.com...
 I was wondering about the style to be used in D, especially related to 
 private
 and protected members.

 Java has get and set methods.

 class Window {
 private:
 char [] caption;
 public:
 char [] getCaption() {}
 }

 Is above good D-style?
I make it a _personal crusade_ to do away with the words "get" and "set" in method names. I always just use the name of the property I'm setting or getting; that way, it can be used as a D property as well. obj.caption = "hi"; // set writefln(obj.caption); // get
 class Window
 {
 private:

 //What name should this be, of course one can choose because its private.
 //Borland goes with FCaption;

 char [] mcaption;
I use "mCaption." In fact, I've made it such a habit to prefix all member variables with "m," that if I read other peoples' code where they don't have any kind of distinguishing characteristic for member variables, it's _very_ difficult for me to read!
May 22 2006