Naming procedure conventions – Where to place adjective in a verb followed by an object convention

namingnaming-standardsprogramming practices

I am reading on Coding Complete book the following statement:

To name a procedure, use a strong verb followed by an object A
procedure with functional cohesion usually performs an operation on an
object. The name should reflect what the procedure does, and an
operation on an object implies a verb-plusobject name.
PrintDocument(), CalcMonthlyRevenues(), CheckOrderlnfo(), and
RepaginateDocument() are samples of good procedure names.

In my code I apply this principle but some routines have an adjective in front the noun example:

Currently I am using

  _getFirstView()
  _getLastView()
  _getActiveView()
  _getActiveMasterView()

I am wondering if this naming could be improved for example using the following variant (in some how how found them more visually organized)

  _getViewFirst()
  _getViewLast()
  _getViewActive()
  _getViewMasterActive()
...

What is a good practice which makes sense in this scenario?

Best Answer

No, you shouldn't change the order of words away from their natural order in natural language.

The point of the guidelines you are citing is to ensure that method names are readable and informative. No amount of gain in informativeness that you could achieve by making method names consistent with each other can outweigh the loss of readability from such reordering. getFirstView() is perfectly fine (and getViewFirst() is actually misleading, since it implies that it's important to call this before some other method).

Related Topic