How to name variables

前端 未结 24 1335
抹茶落季
抹茶落季 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:20

    In DSLs and other fluent interfaces often variable- and method-name taken together form a lexical entity. For example, I personally like the (admittedly heretic) naming pattern where the verb is put into the variable name rather than the method name. @see 6th Rule of Variable Naming

    Also, I like the spartan use of $ as variable name for the main variable of a piece of code. For example, a class that pretty prints a tree structure can use $ for the StringBuffer inst var. @see This is Verbose!

    Otherwise I refer to the Programmer's Phrasebook by Einar Hoest. @see http://www.nr.no/~einarwh/phrasebook/

提交回复
热议问题