需要帮助命名一个代表值及其线性变化的类

时间:2009-06-27 09:55:50

标签: naming-conventions naming

在进行一些重构时,我发现我经常使用一对或浮点数来表示初始值以及该值随时间线性变化的程度。我想创建一个结构来保存两个字段,但我找不到正确的名称。

看起来应该是这样的:

struct XXX
{
    float Value;
    float Slope; // or Delta? or Variation? 
}

任何建议都将不胜感激。

7 个答案:

答案 0 :(得分:1)

我想我更喜欢这种命名:

struct ValueDeltaDuplet
{
    float Value;
    float Delta;    
}

答案 1 :(得分:1)

初始值+恒定斜率:这不是一个仿射函数吗?

答案 2 :(得分:1)

感觉像是“缩放”给我......

struct ValueScale
{
    float Value;
    float Slope;
}

或者

struct ScalableValue
{
    float Value;
    float Slope;
}

答案 3 :(得分:1)

就像Arithmetic progression(或算术序列)

struct sequence_num_t {
    float value;
    float delta;
};

struct SequencePoint
{
   float Value;
   float Delta;
};

答案 4 :(得分:1)

由于你有一个初始值,以及一个表示'某事'如何演变的值,你可以使用“线性函数”之类的东西。

我还会添加必要的成员函数:

struct LinearFunction {
    float constant;
    float slope;
    float increment( float delta ) const { return constant + delta*slope; }
    void add( const LinearFunction& other ) { constant += other.constant; slope += other.slope; }
    LinearFunction invert() const { 
        LinearFunction inv = { -constant/slope, 1./slope; };
        return inv;
    }
};

或者我是否渴望在这里?

答案 5 :(得分:0)

struct ValueSlopePair
{
    float Value;
    float Slope;    
}

答案 6 :(得分:-1)

struct FloatPair
{
    float Value;
    float Slope;    
}