Both logical and structural to name the variables?

Good afternoon, colleagues.
The whole issue applies not only to PHP, but still...
Tell me, more experienced colleagues, as you call variables? On what principle or algorithm?
In a draft script in the 200y line I is $homepage_product_name trying to access $product_name_home etc.
What specifically I refer to a variable, the more variations in the head with the growth in the number of lines in the document...

Can someone share their naming scheme? Preferably with a description...
Thank you!
March 20th 20 at 11:25
5 answers
March 20th 20 at 11:27
In English, nouns in the beginning turn into adjectives, then a noun to which they relate.
Compare: "stone wall" (stone wall) and "wall of stone" (stone from the wall).

That is the first thing you need to define the main noun, that is WHAT is meant. If this name, the variable name must end with _name (or Name depending on the style).

Further, if not to find fault with the rules, the sequence of adjectives is better to do so: the more important the closer to the noun.
Step one: product_name
Step two: homepage_product_name (it should be obvious that no home_page)

Further, nothing superfluous should not be, and should accurately reflect the essence. For example, the setting indicates that the notification can be sent only if the application is inactive.
Not correct: notify_if_inactive (in General, not clear, not logical)
Right: is_notify_if_inactive_only
The is_ prefix in this case is an agreement in our team, indicate that Boolean variable, you can also use b_ for example, for the same purpose. Or, say, if it is constant or changes very rarely, you can write with caps or add a prefix c_

Do next is start subtlety and improvement. The basic principles outlined above is a clear build order and conformity to fact.
March 20th 20 at 11:29
Tell me, more experienced colleagues how you name variables?

As close as possible to natural language. And it is also desirable taking into account the recommendations to the naming standards adopted in a particular PL, $homepage_product_name == > $nameOfProductOnHomepage, although why there is hompage and than differs from not on hompage of mystery.
Well, I took the example out of my head right now, so that you understand the question, so Hompage abstract here. You can estimate that this product is just "featured", and recommended is displayed on the main. Let it be so.

When the length of the name variable ($nameOfProductOnHomepage) I get stuck in them much faster.... - izabella47 commented on March 20th 20 at 11:32
@Mercedes34, if you are in the controller home page, in this context, there is only product name, no other names of the product, maybe there are no other pages

That is, here the item name is the name of the variable $name
And here druuge, but also the name $name

That is an example-the name of the person:
the Institute is the name of the student
in obshejitie is the name of the tenant
just-the citizen

Like it or not, in a particular context name is the name - Brady_Hess commented on March 20th 20 at 11:35
@Mercedes34you and their will be confused, it's just I have little idea really long naming in a structured project with objects as the basis of development. As written above @Wallace.Cassin - the very structural decomposition of the object will not unnecessarily lengthen the naming. In MVC you have all the breaks on the controller + action + objects inside the code will be like:

class IndexController extends Controller {
...
public function indexAction(){
 $product = new Product();
$product->initById(55);
 echo $product->name; // although it is certainly not doing
}
...
}
- millie_Romague commented on March 20th 20 at 11:38
March 20th 20 at 11:31
I try to do at the same principle - $modulfunktionen
Can you give an example with a description? - izabella47 commented on March 20th 20 at 11:34
@Mercedes34, $shop_basket_product or $blog_article_title.
In General, correctly wrote above, it's time to move on the PLO - mazie.Homeni commented on March 20th 20 at 11:37
@Clark.Funk, the transition to PLO will not help the person. He asked how to learn to name variables and properties. OOP for it will not do it.
Normal code to write and call normal methods/variables and procedure. - amira.Rolfs commented on March 20th 20 at 11:40
@margaret.Wunsc,
the transition to PLO will not help the person.
incorrect statement, as I wrote - the code split into logical sub-blocks and objects greatly simplifies the naming of entities, if the procedural style is the same $homepage_product_name XS what it is and where, in the PLO will be in IndexController::indexAction() and have the form $product->name that clearly relates it to the main page and the product name, and more briefly and completely logical. - millie_Romague commented on March 20th 20 at 11:43
@Norma.OHara, it's not from OOP. it depends on the developer.
Can and controller to create a CategoryController and it will categories news, categories, articles and products categories in the store. - amira.Rolfs commented on March 20th 20 at 11:46
@margaret.Wunsc, Who argues, Mr.**to nokogiri on any architecture, but in OOP, the logical structure initially, if the developer is not an idiot not able to separate the soft from the warm, no architecture will not save, but I don't think categorical statements "transition to PLO will not help a person" is justified, first of all you don't know the man personally to judge his level of intelligence, right? And secondly - I see no contradiction - even in the above example, where everything is piled up in a heap, the structural organization allows to reduce naming entities and build logic(though twisted and curve), it's basically the same code more structurally separate and entity logically referred to as concisely and without redundancy. - millie_Romague commented on March 20th 20 at 11:49
@Norma.OHara, there just need to come up with the names of the properties. The author of the question of "how to invent". The same question he would have with any architecture.
Never easier in the PLO to come up with names.
When you make a claim, remember that the question asks not a programmer. - amira.Rolfs commented on March 20th 20 at 11:52
@margaret.Wunsc,
When you make a claim, remember that the question asks not a programmer.
From such a conclusion?
Tell me, more experienced colleagues how you name variables?
The man is clearly positioning himself as a programmer, the fact that he is inexperienced is another matter, but the issue is not the case.
there just need to come up with the names of the properties.
Yes, but think of the names of the properties is a completely different task than to come up with names of hundreds of variables from spaghetti code, as there is no structural nesting, and properties are typically referred to as nativee, name will be in the product and the user and other entities, with different "names".
Compare: $homepage_product_name and $product->name called indexcontroller::indexexp, then it does not write $name->product, there is a clear sequence. - millie_Romague commented on March 20th 20 at 11:55
@Norma.OHara,
$product_name
$product->name
Don't see the difference. Why do You compare obviously crazy code with that code, which the author no?
The author has code that is not easy to read. You say that the transition to OOP will solve all his problems with it.
A clear sequence is not in the PLO, it is in my head should be.
You can write it as:
$product->product_name - amira.Rolfs commented on March 20th 20 at 11:58
@margaret.Wunsc,

$product_name
$product->name
Don't see the difference.
...
A clear sequence is not in the PLO, it is in my head should be.
Just don't be considered idiots, when a person in the noodles trying to bring some structure to the naming, it points to the lack of structure, not lack of brains. - millie_Romague commented on March 20th 20 at 12:01
@Norma.OHara, I do not believe all idiots. Without the PLO there's no shortage of structure. You thought of it themselves. Structuring your code, its convenience and beauty no relation to the PLO has not.
You have clung to it as if OOP is a panacea for all "disease" in programming. - amira.Rolfs commented on March 20th 20 at 12:04
@margaret.Wunsc,
Structuring your code, its convenience and beauty no relation to the PLO has not.

In General, the main role of the PLO - structuring of the code, initially, even at the expense of performance.

You have clung to it as if OOP is a panacea for all "disease" in programming.
No, of course, a silver bullet does not exist, but to know and do in OOP the programmer should be normal. - millie_Romague commented on March 20th 20 at 12:07
@margaret.Wunsc, MVC has not been canceled. - Else.Mohr32 commented on March 20th 20 at 12:10
March 20th 20 at 11:33
https://m.habr.com/ru/post/437122/
Articles like this one - dozens.
homepage_product_name

Not quite understand the meaning. on other pages of this same product a different name?
March 20th 20 at 11:35
Names do what you want, the main thing that was clear. How to use long names, so use a decent IDE with autocompletion(plus the MVC pattern). In General, to fence your garden does not need the documentation to read about the standards PSR-0, PSR-1, PSR-4

Find more questions by tags PHPProgrammingOOPWeb Development