Name At the Right Level of Abstraction [VA8]

Name At the Right Level of Abstraction [VA8]

Tip VA8

You generally want to name in the problem domain as much as possible. However, code for any non-trivial program will have multiple levels of abstraction. Ensure your names are at the right level of abstraction for the code you are working in.

For example, the file_handle name below seems like it’s at an inappropriate level of abstraction based on the data type for the variable (a higher-level “file” object):

File file_handle("path/to/file");

The name should just be file in this case:

File file("path/to/file");

 

Now, within the File class, you might need to go down a level of abstraction and thus have to deal with actual “file handles.” In such a case, a name with “handle” would be appropriate to provide distinction between the different levels of abstraction:

File::File(const std::string& filepath) { Path = filepath; OperatingSystemHandle = OperatingSystem_OpenFile(Path); }
Find the experts Ad.png