How to name variables

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

    I learned not to ever use single-letter variable names back in my VB3 days. The problem is that if you want to search everywhere that a variable is used, it's kinda hard to search on a single letter!

    The newer versions of Visual Studio have intelligent variable searching functions that avoid this problem, but old habits and all that. Anyway, I prefer to err on the side of ridiculous.

    for (int firstStageRocketEngineIndex = 0; firstStageRocketEngineIndex < firstStageRocketEngines.Length; firstStageRocketEngineIndex++)
    {
      firstStageRocketEngines[firstStageRocketEngineIndex].Ignite();
      Thread.Sleep(100);  // Don't start them all at once. That would be bad.
    }
    

提交回复
热议问题