Skip to main content

Functions

@serverSerrverlesskiy

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".

Don’t repeat yourself#

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.

Select function name#

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.

Choice

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 ...

"get .." - return a value,
"calc .." - something is being calculated,
"create .." - create something,
"check .." - check something and return a boolean value, etc.

Examples of such names:

showMessage (..) // shows the message
getAge (..) // returns age (in some value)
calcSum (..) // calculates the sum and returns the result
createForm (..) // creates a form (and usually returns it)
checkPermission (..) // checks access by returning true / false

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 🖊️.

Payment#

Now you are on a stripped-down version of the site, after subscribing to Patreon, you will get full access to the training course, as well as access to our server's private channels in Discord.

Download our mobile application or get tested in our JavaScript telegram bot, and also subscribe to our news.

Become a Patron!

Sumerian school

Contributors ✨#

Thanks goes to these wonderful people (emoji key):


Dmitriy K.

📖

Dmitriy Vasilev

💵

Resoner2005

🐛 🎨 🖋

Navernoss

🖋 🐛 🎨

Become a Patron!