If the only change a function does to the class is to update a cache then I would suggest leaving the function as const but marking the cache member variables with the mutable keyword so they can be modified in a const function. Otherwise access problems can arise if you're trying to write const-correct code elsewhere.

More detail here: http://www.parashift.com/c++-faq/mutable-data-members.html

Tim

On 21 May 2013, at 10:28 am, Memo Akten wrote:

> In libs/openFrameworks/graphics/ofPolyline.h:
> 
> > @@ -124,22 +127,70 @@ class ofPolyline {
> >  
> >  	vector<ofPoint> & getVertices();
> >  
> > -	float getPerimeter() const;
> > +	float getPerimeter();
> getPerimeter checks and updates the cache if necessary. If cache is dirty, and getPerimeter has to go through calculating the length for each segment, I think it makes sense to save those lengths in case anyone else needs them. Memo Akten +44 7958 783 832 www.memo.tv (http://www.memo.tv) www.twitter.com/memotv (http://www.twitter.com/memotv) The Mega Super Awesome Visuals Company www.msavisuals.com (http://www.msavisuals.com) Marshmallow Laser Feast www.marshmallowlaserfeast.com (http://www.marshmallowlaserfeast.com)
> …
> —
> Reply to this email directly or view it on GitHub.
>