Thread overview
style
May 22, 2006
sclytrack
May 22, 2006
Daniel Keep
May 22, 2006
Lars Ivar Igesund
May 22, 2006
Daniel Keep
May 22, 2006
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

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:

# class Window
# {
#     private char[] _caption;
#
#     char[] caption()           { return _caption; }
#     void caption(char[] value) { _caption = value; }
# }

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

#     char[] caption(char[] value)
#     {
#         return _caption = value;
#     }

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
Daniel Keep wrote:

> 
> A question of my own: does anyone define the return type of the 'setter', and then return the value like this:
> 
> #     char[] caption(char[] value)
> #     {
> #         return _caption = value;
> #     }
> 
> 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

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:
>>
>> #     char[] caption(char[] value)
>> #     {
>> #         return _caption = value;
>> #     }
>>
>> 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
<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!