naming convention of temp local variables

后端 未结 11 1194
我在风中等你
我在风中等你 2021-01-23 05:40

What is the standard way to name a temp variable in the local function? let me give you an illustration of what I am doing. I get a pointer to a structure, so I want store one o

11条回答
  •  忘掉有多难
    2021-01-23 06:01

    For your information: Code Complete has a chapter decicated to variable naming.

    In your example one problem is that the member variable in Foo is not very descriptive to start with, which makes it hard to find a useful name for the placeholder local variable.

    For example, I would do something like this:

    struct Foo
    {
      double mValue; // I don't use underscores here
                     // however, you can do as you please.
                     // Also 'mValue' is just for the sake of example,
                     // you should find a more descriptive name :D
    
    };
    
    
    void function (Foo* f)
    {
       double oldValue = f->mValue;
    
           /***Other stuff***/
    
       f->mValue = oldValue;
    }
    

提交回复
热议问题