How to name variables

前端 未结 24 1336
抹茶落季
抹茶落季 2020-12-01 00:37
  • What rules do you use to name your variables?
  • Where are single letter vars allowed?
  • How much info do you put in the name?
  • How about for exam
24条回答
  •  难免孤独
    2020-12-01 01:22

    One rule I always follow is this: if a variable encodes a value that is in some particular units, then those units have to be part of the variable name. Example:

    int postalCodeDistanceMiles;
    decimal reactorCoreTemperatureKelvin;
    decimal altitudeMsl;
    int userExperienceWongBakerPainScale
    

    I will NOT be responsible for crashing any Mars landers (or the equivalent failure in my boring CRUD business applications).

提交回复
热议问题