style

Daniel Keep daniel.keep.lists at gmail.com
Mon May 22 02:36:16 PDT 2006



sclytrack at 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/



More information about the Digitalmars-d mailing list