Minus: I am aware of what OOP is and constantly use it in development. Or because of what you are there minus with disregard for a similar approach? No matter how surprising it may be for you, projects can also be written using simple functions, instead of stuffing everything into various classes. There are many situations where it is more convenient to write a function than to fence a whole class to solve a small problem.
There is one interesting approach in the development of projects, which I recently began to like. The point is simple: when you write functions, put each of them in a separate file. I now mean the functions that are used in many places of your project, thus forming a certain "library" of methods.
Few people do this in the modern world. What are the profits from this approach? But what.
Many of you most likely repeatedly sent each other links to different pieces of code on Github, like this . Today this link points exactly to a method called booleanConditional
. But what this link will indicate after half a year - we will look at that after half a year :) Well, I would venture to suggest that in half a year there will be a jumble of some completely different code unrelated to booleanConditional
.
If your function lies in its own file, then no offsets will happen over time. Even after a long time after the processing of the project, your link will most likely not lose its relevance and will indicate the same function, and it will indicate its current actual content.
Now you have a whole file for your function, in which you can only write about it! All that will be written in this file - refers only to this function. Describe the structure of the import and use of the necessary libraries for its work? You are welcome. To write a big comment that tells in detail how your function should behave? Why not? Write below examples of use, start a discussion with colleagues on how to finalize it? Leave in the comments the last version of this function, if necessary, to return to it back? Yes, please, what problems: take and write as much as you like.
Having a separate file for each function greatly expands the space for creativity. At the same time, everything will look very comfortable and logical. When we describe a large number of functions in a single large bold file, we cannot afford such liberties.
We all know that modern version control systems allow you to view the change history of any project file. And now think about how convenient it can be to have a life history of each of its functions. This also becomes possible simply due to the fact that we have allocated each of its functions to a separate file.
In our current project, everything is broken down as follows: there is a project core and its modules. The kernel has a folder of functions, in which there are five more folders. It looks like this:
Each project module has its own functions, broken down in much the same way.
Now it became several times easier to find the necessary function of the project, while you can use almost any code editor: the main thing is that he knows how to search by file name in the project. Dividing the functions into groups according to their areas of destination also helps to increase the project order. And simply, when everything is decomposed in this way, it becomes much easier to analyze the existing created project methods.
In theory, if we are talking about a PHP project, then on production, for good, we need to collect all the functions into one file and load it with one instead of a heap of files. We'll have to write some code to solve this performance problem (if it really suddenly becomes a problem), but this is not a question for you, is it true, my friend is a habravcan?
I don’t see any problems in the JavaScript world. There, all adequate people have long been compiling the source code with various ready-made tools into one file.
I don't know about other programming languages.
These are the pies. In my opinion, it’s much more pleasant to work with a project. And what opinion on this topic do you have?
Source: https://habr.com/ru/post/311748/
All Articles