Is naming variables after their type a bad practice?

前端 未结 11 710
孤独总比滥情好
孤独总比滥情好 2021-02-02 16:00

I\'m programming C++ using the underscore naming style (as opposed to camel case) which is also used by the STL and boost. However, since both types and variables/functions are

11条回答
  •  隐瞒了意图╮
    2021-02-02 16:36

    Short and semi-wrong answer: If you have enough variables that you're working with in one place that you need non-cryptic variable names, maybe you have too many variables.

    Though I actually disagree with that, to some extent. I think it has a grain of truth, but only that.

    Some short variable names in C++ are just traditional and people know what they mean because they've been programming in C/C++ for awhile. Using i for an index variable is an example.

    I think variable names should be named for their purpose. What's the position the position of? What's the manager managing? Why does this particular instance of the audio subsystem need to exist?

    The trailing _ notation is used to distinguish member variable names. It can be very helpful when someone starts mentioning x out of nowhere to see x_ and know that it's coming from the class, and isn't declared in an enclosing scope or the global scope.

提交回复
热议问题