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

前端 未结 10 1346
旧时难觅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条回答
  •  萌比男神i
    2021-02-11 12:31

    What is the reasoning of those telling you this is bad? I do this all the time. It is the simplest, expressive way to name a single variable of a type. If you needed two Person objects then you could prefix person with meaningful adjectives like

    fastPerson
    slowPerson
    

    otherwise just

    person
    

    is fine with me.

提交回复
热议问题