Answer the question
In order to leave comments, you need to log in
How do programmers store frequently used pieces of code so that they don't have to remember each time?
How do programmers store small heterogeneous pieces of code, examples of how instructions are used, patterns of a certain language / framework, concepts, frequently used code, boilerplate, so that each time you don’t remember how to do it when you need it again?
And so that you can conveniently copy / paste them, search for them, add, occasionally change.
Answer the question
In order to leave comments, you need to log in
Programmers do not forget this to store it somewhere. You can forget the names of functions, of which there are 100500 in various APIs. But the syntax and language standards are like an alphabet. Do you often forget the alphabet? Can you reproduce it now: "a", "b", "c" ...? And if another language: "a", "b", "c"... ? Likewise, (real) programmers remember these things as the foundations of the foundations.
Frequently used code is arranged as functions, and there is no need for copying / rewriting. Many of these simple functions are included in the standard library, and the names of such functions do not change much from language to language. Therefore, even if the language does not have one of these functions, then it is created with a known name in advance, which programmers remember well. And if the function is specific to the project, then there are not many such functions, and they are also easy to remember (for the duration of the project).
Frequently used code, with a sufficiently deep study, is remembered at an intuitive level.
Boilerplate - mechanical memory, snippets, and templates.
Well, Google with stackoverflow :)
If within the framework of one project, then you can just copy-paste.
Well, you can also move the repeating code into a separate module and use it
In the backend, almost everything that is often used is added to some kind of module, a console command generator or a dump of helpers (such as the Utils class) in the project, so there is no need to store it separately. Occasionally, you can save some reference implementation of a large task in a github or gist
a separate folder with files containing pieces of code. Permanently open in Atom, you can quickly take and copy-paste
I asked this question a very, very long time ago, I was looking for a program so that snippets could be inserted into any IDE without being tied to the code editor itself, but alas, I did not find a suitable software, maybe after so many years someone found one.
So far, I've only got around with snippets in the IDE, and if the code needs a lot of explanation, I kept the code in obsidian (markdown markup)
When I was coding in VB6 at school, I saved significant pieces of code that can be reused in modules and stored them in folders that were more or less structured.
Now I store the snippets on my github. From the consideration that it lies in the cloud.
If you often use something, then it makes sense to allocate it to the library.
Well, or write a code generator. For example in IDEA.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question