Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 150243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:15:34+00:00 2026-05-11T09:15:34+00:00

I recently wrote a class that renders B-spline curves. These curves are defined by

  • 0

I recently wrote a class that renders B-spline curves. These curves are defined by a number of control points. Originally, I had intended to use eight control points, so I added a constant to the class, like so:

class Curve {    public:       static const int CONTROL_POINT_COUNT = 8; }; 

Now I want to extend this class to allow an arbitrary amount of control points. So I want to change this to:

class Curve {    public:       int getControlPointCount() {return _controlPointCount;} }; 

The question is whether it isn’t better to store constants in methods to begin with, to facilitate adaptability. In other words, isn’t it better to have started thus:

class Curve {    public:       int getControlPointCount() {return 8;} }; 

The advantage of this is that I could have just changed one symbol in the method in question, instead of moving around constants etc.

Is this a good practice or a bad one?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T09:15:35+00:00Added an answer on May 11, 2026 at 9:15 am

    Typically I favour maintaining as few couplings manually as possible.

    The number of control points in the curve is, well, the number of control points in the curve. It’s not an independent variable that can be set at will.

    So I usually would expose a const standard container reference:

    class Curve {        private:         std::vector<Point>& _controlPoints;      public:               Curve ( const std::vector<Point>& controlPoints) : _controlPoints(controlPoints)         {         }          const std::vector<Point>& getControlPoints ()         {             return _controlPoints;         } }; 

    And if you want to know how many control points, then use curve.getControlPoints().size(). I’d suspect that in most of the use cases you’d want the points as well as the count anyway, and by exposing a standard container you can use the standard library’s iterator idioms and built-in algorithms, rather getting the count and calling a function like getControlPointWithIndex in a loop.

    If there really is nothing else in the curve class, I might even go as far as:

    typedef std::vector<Point> Curve; 

    (often a curve won’t render itself, as a renderer class can have details about the rendering pipeline, leaving a curve as purely the geometric artifact)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I recently wrote a java class that extends exception and used an instance
I recently wrote a program that used a simple producer/consumer pattern. It initially had
I recently wrote a DLL in C# (.Net 2.0) which contains a class that
I recently wrote a class library that includes some objects that model certain types
I recently wrote a class for an assignment in which I had to store
I recently wrote a theme function to add a class to my primary links
I recently wrote code that didnt work as i would expect, it was: message
I recently wrote some data access methods (plain old Java) that use immutable objects
Recently I had faced compiling errors in a c++ code I wrote so I've
I recently wrote a Vector 3 class, and I submitted my normalize() function for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.