Hi. Recently wondered how to call variables and functions. I understand that this is probably very subjective, but I want to hear your opinions. We are not talking about notation. It is also clear that the variable name should accurately reflect its contents. I want to know about the sequence of words, time, length, names, etc. for Example, what would you name the "total time user store" (in functions of the time counters of preserving users), total_time, time_total, save_time_users, etc.? The first word should most reflect the contents of the variable (time_total) or better to call as we speak (total_time)? Does it make sense to call the variable parts of speech, i.e. palgaerinevustele? get_groups_user or get_user_groups?
I think the meaning of the question clear. I want to write uniform and understandable code. Share your vision, can be examples.
The most important rule - that in this context, it was immediately clear what the variable means. The closer to English, the better (the order of words to retain). There are only a few basic rules:
- the main word in the title is a noun or an adjective
- Boolean can be prefixed with is_... (but not isnot_...)
- articles do not use
No need to duplicate the meaning of which is clear from the context. If we have, say, a method parse_html(), there is html_nodes you can simply write nodes.
zion answered on August 19th 19 at 23:33
If you work in a team is to sit down and write the list of words comprise names, as well as a list of pairs such as Add/Remove, Open/Close, Program/Clear, Create/Destroy to some is to add meaning.
For example, the Init method produces the initialization of the content of the object, in fact an analogue designer, and it can't be nothing else except the first reference to this object, and let the Reset puts the object in the same initial state but from any state.
Size is the size in bytes, words or something else what they have.
Len or Length the length in elementno