[mlpack-svn] [MLPACK] #118: Use consistent accessors and mutators (was: Decide on whether to use setters and getters, or publicly accessible variables)

MLPACK Trac trac at coffeetalk-1.cc.gatech.edu
Wed Oct 26 20:12:15 EDT 2011


#118: Use consistent accessors and mutators
------------------------------------------+---------------------------------
  Reporter:  rcurtin                      |        Owner:            
      Type:  wishlist                     |       Status:  new       
  Priority:  major                        |    Milestone:  MLPACK 1.0
 Component:  MLPACK                       |   Resolution:            
  Keywords:  mlpack getter setter public  |     Blocking:  120       
Blocked By:                               |  
------------------------------------------+---------------------------------

Old description:

> I am not sure of exactly how I want to approach this one, because the
> benefits are minimal.  Essentially, the difference is this:
>
> {{{
> class SomeClass {
>  private:
>   T someObject;
>
>  public:
>   T& someObject() { return someObject; }
>   const T& someObject() const { return someObject; }
> };
> }}}
>
> and
>
> {{{
> class SomeClass {
>  public:
>   T someObject;
> };
> }}}
>
> It is not likely that this will get us much in terms of speed because the
> compiler is likely to inline the getters and setters (accessors and
> mutators, for you more grammatically inclined).
>
> What we do get with getters and setters is that fuzzy feeling we get from
> following the OOP principles we learned years ago and perhaps users will
> be expecting getters and setters, but what we get without them is a lot
> less seemingly redundant code.  I should note that Armadillo uses
> publicly accessible variables (but read-only, through a trick I don't
> want to use for MLPACK).
>
> I'm looking for opinions here.  Once we have consensus we can go about
> modifying the code to fit the majority decision.  I think I lean towards
> publicly accessible variables.

New description:

 Originally, this ticket dealt with what convention we should use -- public
 members, or setters/getters (accessors/mutators, or whatever name you
 like).  We chose to use accessors and mutators, but with specific naming
 conventions, listed below.

 Variable names should be declared in camelcase, starting with a lowercase
 letter:

 {{{
 int leafSize;
 int dim;
 int newDim;
 }}}

 The names of the accessors and mutators for these variables should have
 the following format:

 {{{
 int leafSize;

 const int LeafSize() const;
 void LeafSize(const int leafSize);

 arma::mat someMatrix;

 const arma::mat& SomeMatrix() const;
 void SomeMatrix(const arma::mat& SomeMatrix);
 }}}

 This ticket now refers to transitioning every object in MLPACK to this
 format.

--

Comment (by rcurtin):

 Updated the description with the solution we have settled on.

-- 
Ticket URL: <http://trac.research.cc.gatech.edu/fastlab/ticket/118#comment:7>
MLPACK <www.fast-lab.org>
MLPACK is an intuitive, fast, and scalable C++ machine learning library developed by the FASTLAB at Georgia Tech under Dr. Alex Gray.


More information about the mlpack-svn mailing list