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

前端 未结 10 1149
旧时难觅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:35

    Jason - I'm not sure who has told you that this is bad. A number of authors use this as a standard way of expressing an Instance (lower case) of a Class (capitalized).

    I use this quite often as I find that the lower-cased variable actually communicates to me not only that this is an instance but also the name of the class.

    Unless someone has a solid argument to the contrary, I'll certainly continue doing this.

提交回复
热议问题