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

前端 未结 8 992
醉梦人生
醉梦人生 2021-02-11 11:43

For instance, take this piece of code:

var person = new Person();

or for you Pythonistas:

person = Person()

I

8条回答
  •  清酒与你
    2021-02-11 12:11

    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.

提交回复
热议问题