How to name variables

前端 未结 24 1272
抹茶落季
抹茶落季 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条回答
  •  萌比男神i
    2020-12-01 01:30

    I like to prefix my variables with what they're going to be: str = String, int = Integer, bool = Boolean, etc.

    Using a single letter is quick and easy in Loops: For i = 0 to 4...Loop

    Variables are made to be a short but descriptive substitute for what you're using. If the variable is too short, you might not understand what it's for. If it's too long, you'll be typing forever for a variable that represents 5.

    Foo & Bar are used for example code to show how the code works. You can use just about any different nonsensical characters to use instead. I usually just use i, x, & y.

    My personal opinion of foo bar vs. fu bar is that it's too obvious and no one likes 2-character variables, 3 is much better!

提交回复
热议问题