Am I immoral for using a variable name that differs from its type only by case?

前端 未结 10 1138
旧时难觅i
旧时难觅i 2021-02-11 11:58

For instance, take this piece of code:

var person = new Person();

or for you Pythonistas:

person = Person()

I

10条回答
  •  我在风中等你
    2021-02-11 12:26

    The reason it is considered bad is if you need to have 2 Person's in the future, you can then end up with code that looks like.

    Person person = new Person();

    Person person2 = new Person();

    That would then be bordering on "Bad". However, in that case you should then refactor your orginal person in order to distinguish between the two.

    As for your example, the variable name "person" is a perfectly descriptive name for the object "Person". Therefore there is nothing wrong with it whatsoever.

提交回复
热议问题