How to name variables

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

    • I only use single character variables for loop control or very short functions.
    for(int i = 0; i< endPoint; i++) {...}
    
    int max( int a, int b) {
        if (a > b)
           return a;
        return b;
    }
    
    • The amount of information depends on the scope of the variable, the more places it could be used, the more information I want to have the name to keep track of its purpose.
    • When I write example code, I try to use variable names as I would in real code (although functions might get useless names like foo or bar).
    • See Etymology of "Foo"

提交回复
热议问题