K
K
kovert992019-02-23 11:49:27
Programming
kovert99, 2019-02-23 11:49:27

How to make variable (field) names more readable?

Hello, during development, you constantly have to create variables and fields, in the names of which you have to indicate inheritance.
For example, there is an object - contact_book ;
it has child objects - contacts
(contact_book => contacts).
That is, something like this (in the under score style) comes out: contact_book_contacts
Or like this (in the camel case style): contactBookContacts
Such names are very difficult to read, especially if you specify any additional adjectives and inheritance. For example: contact_book_deleted_contact (content book => deleted contact) or contact_book_deleted_contact_first_field(contact book => deleted contact => first field).
It occurred to me that we could combine lower case and camel case, like: contactBook_deletedContact_firstField ,
or in BEM-like style: contact_book__deleted_contact__first_field .
But all this is already some kind of perversion.
Actually the questions themselves:
How do you implement this in your code or database?
Are there any suitable naming methodologies?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
Zanak, 2019-06-21
@kovert99

If the question is still relevant: do not do what you described in the water part of the question. Including object relationships in their naming is a bad idea, because refactoring the class hierarchy can lead, with this approach to naming, to changing the names and contents of methods that are not directly affected by this refactoring. This is especially true in the case of scripting languages, where modules can be loaded at runtime, and the library is not imported every time the application is launched. It's good if you carefully cover your code with tests, but even they may not save you.
For naming tables, it is better to use English nouns in the singular. For convenience, you can connect multiple words using the '_' character. For example: user, user_profile, user_acl, for storing the user's account, his profile and rights, respectively. If you're extending someone else's project, it's acceptable to use a prefix to visually control which tables you added and which ones originally existed: for example, my_user_additional_info. This approach is fairly self-documenting your project and makes it easier for your potential colleagues to maintain it.
With the naming of classes and variables, the approach is similar. camelCase or snake_case or even PascalCase is a matter of taste, by and large. Yes, many, if not all, languages ​​have their own code formatting style, but it's up to you to follow it or not. I will limit myself to advice: stick to the chosen style of text design, at least until the end of the project.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question