How to give variables short and clear names

Published Apr 16, 2017
How to give variables short and clear names

One of the most ingenious work of Google was to do the code review strictly. Every line of code is required to pass two checks before publishing it.
1. Make sure the code works well.(By Team)
2. Make sure the readability of the code.(By Others)

The readability of the code is absolutely important not only to the development but also for coorporation. You know, the big projects need several people to work on. In this article, we will talk about the most important thing to gurantee a readable code: the **variable name**. 

To name a variable, sometimes, is a tricky problem. We need to make it clear that people will know what this variable is doing in the first sight, and at the same time, to keep it simple and short. We need to know the important features of a good name. 

Choose a good name

Basically, we have two goals:
-Simple: We should know what this variable is related to
-Clear:  We should know what this variable is not related to

As long as a name reaches the two goals, the other chars are redundant. The following passage will show you some useful rules in naming. 

1. No DataType
String nameString;
DockableModelessWindow dockableModelessWindow;
  String name;
  DockableModelessWindow window;
2. Delete the word that is not representative
Discover and read more posts from Mars Gao
get started