Parameter vs. Member variables

前端 未结 9 825
别跟我提以往
别跟我提以往 2021-01-01 11:15

I\'ve recently been working with someone else\'s code and I realized that this individual has a very different philosophy regarding private variables and method parameters t

9条回答
  •  离开以前
    2021-01-01 11:54

    I claim that it isn't a style issue but rather a readability/maintainability issue. One variable should have one use, and one use only. “Recycling” variables for different purposes just because they happen to require the same type doesn't make any sense.

    From your description it sounds as if the other person's code you worked on does exactly this, since all other uses are basically covered by your list. Put simply, it uses private member variables to act as temporaries depending on situation. Am I right to assume this? If so, the code is horrible.

    The smaller the lexical scope and lifetime of any given variable, the less possiblity of erroneous use and the better for resource disposal.

提交回复
热议问题