Functions⚙️ are needed so as not to repeat the same code📟 in many places in the program algorithm. In modern programs, functions are the main "building blocks".
DRY (rus. Do not repeat yourself) is a software development principle aimed at reducing the repetition of information of various kinds, especially in systems with many layers of abstraction. Functions are exactly the type of data that serves this design principle.
Function⚙️ is action! Therefore, the function name is usually a verb. It should be simple, precise, and describe the action of the function, so that the programmer reading the code📟 has a good understanding of what the function does.
As a rule, verb prefixes are used, indicating the general nature of the action, followed by a clarification. Typically, development teams have conventions about the meaning of these prefixes.
For example, functions⚙️ starting with `` show '' usually show something.
Functions⚙️ starting with ...
Examples of such names:
Thanks to prefixes, at the first glance at the name of a function, it becomes clear what its code is doing and what value it can return🔄.
In any case, you and your team need to understand exactly what a prefix means and what a function⚙️ can and cannot do with it.
Ultra-short function names⚙️
Function names⚙️ that are used very often are sometimes made extra short.
For example, the jQuery framework has a function⚙️ named
$. In the Lodash library, the main function⚙️ is represented by the underscore name \ _
These are exceptions. Basically, function names should be reasonably short and descriptive 🖊️.
Thanks goes to these wonderful people (emoji key):
🐛 🎨 🖋
🖋 🐛 🎨