[Bikeshed] getter/readonly mixin util with private/protected backing

Justin Johansson no at spam.com
Thu Nov 12 01:37:27 PST 2009


Lutger Wrote:

> Nick Sabalausky wrote:
> 
> > In my SemiTwist D Tools project (
> > http://www.dsource.org/projects/semitwist ), I have a util mixin to DRY-ly
> > create a publically-readonly property with backing storage (actually, I've
> > had it for awhile, but I've been toying with it again recently).
> > 
> > 1. It can optionally give the backing storage any access level you want,
> > but what I'm wondering is, what do you think would be a better default:
> > private or protected?
> 
> Private for sure. 
>  
> > 2. As a secondary question, do you think 'getter', 'readonly' or something
> > else would be the best name for it?
> 
> getter is the clearest imho.
>  
> > 3. There's an alternate version that creates a getter that, instead of
> > returning the backing storage, works like this: On the first call, a
> > user-supplied function is called that generates the value. This value is
> > automatically cached and returned. Subsequent calls return the cached
> > value until the private (or protected) 'cached' flag is cleared. What
> > would be a good name for this util? 'getterLazy', 'getterCached',
> > 'readonlyLazy', 'readonlyCached', etc..., or just simply overload the
> > regular 'getter'/'readonly'/etc...?
> 
> What about passing both this and access level as a parameter to the 
> template? 
> 
> Something like this perhaps:
> 
> mixin ( getter!("myFunc", "myInitializer", PROTECTED | LAZY) );
> 
>  
> > 4. Do you think this util would be a useless waste, or potentially handy?
> > 
> > My main interest is Q #1, but I'm curious about opinions on the others
> > too.
> > 
> 
> Might be handy depending on the kind of things you are going to write.

Nick,

On the surface Lutger's answers seem pretty reasonable but that's without knowing
more about the finer details of your project.

However, having looked at the project link I think you are more likely to get better
informed, and more, replies if you told us a bit more about the problem(s) the SemiTwist
Tools project is trying to solve.  I'm interested in being helpful (and hope this reply is)
but can you expand the project detail a little to solicit a wider audience?

Regards Justin




More information about the Digitalmars-d mailing list