Is there a list of keywords and rules used in naming?
(for variables, classes, methods etc)
I think I’m not the only one that thinks a bit when it comes to some names.
Some actions may have standard names (get, set, load) and it’s easy to find a name but some are a bit difficult to name.
Example 1: actions
$this->setName('George') // will set a property of the class $this->getName() // will get a property of the class
OK, all good. Now, I’d like to insert a record.
$this->addName('george') // or, should I use? $this->insertName('george') // when to use add, insert, create, make // is there a set of rules?
Example 2: properties and variables
Some user has an active
flag of type int
.
$userObject->active // or $userObject->isActive
Problem to solve:
I have a method that will return a list of articles that have keys as status. This is in the class articles. So, the output will look like this:
'active' => last article that was approved 'pending' => last pending article, that needs approval 'rejected' => last rejected article
How would you name this method?
I think we should create a standard, as we have PSR2 for writing code, a standard for naming.
Thoughts?